blob: 8ce58d715aef9cce3a5d2334f88515ae0d58caf2 [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 Rostedtfcb3f162011-06-13 10:40:58 -0400192my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500193
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400194# do not force reboots on config problems
195my $no_reboot = 1;
196
Steven Rostedt759a3cc2012-05-01 08:20:12 -0400197# reboot on success
198my $reboot_success = 0;
199
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500200my %option_map = (
201 "MACHINE" => \$machine,
202 "SSH_USER" => \$ssh_user,
203 "TMP_DIR" => \$tmpdir,
204 "OUTPUT_DIR" => \$outputdir,
205 "BUILD_DIR" => \$builddir,
206 "TEST_TYPE" => \$test_type,
Steven Rostedt921ed4c2012-07-19 15:18:27 -0400207 "PRE_KTEST" => \$pre_ktest,
208 "POST_KTEST" => \$post_ktest,
209 "PRE_TEST" => \$pre_test,
210 "POST_TEST" => \$post_test,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500211 "BUILD_TYPE" => \$build_type,
212 "BUILD_OPTIONS" => \$build_options,
213 "PRE_BUILD" => \$pre_build,
214 "POST_BUILD" => \$post_build,
215 "PRE_BUILD_DIE" => \$pre_build_die,
216 "POST_BUILD_DIE" => \$post_build_die,
217 "POWER_CYCLE" => \$power_cycle,
218 "REBOOT" => \$reboot,
219 "BUILD_NOCLEAN" => \$noclean,
220 "MIN_CONFIG" => \$minconfig,
221 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
222 "START_MIN_CONFIG" => \$start_minconfig,
Steven Rostedtccc513b2012-05-21 17:13:40 -0400223 "MIN_CONFIG_TYPE" => \$minconfig_type,
Steven Rostedt43de3312012-05-21 23:35:12 -0400224 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500225 "IGNORE_CONFIG" => \$ignore_config,
226 "TEST" => \$run_test,
227 "ADD_CONFIG" => \$addconfig,
228 "REBOOT_TYPE" => \$reboot_type,
229 "GRUB_MENU" => \$grub_menu,
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400230 "PRE_INSTALL" => \$pre_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500231 "POST_INSTALL" => \$post_install,
232 "NO_INSTALL" => \$no_install,
233 "REBOOT_SCRIPT" => \$reboot_script,
234 "REBOOT_ON_ERROR" => \$reboot_on_error,
235 "SWITCH_TO_GOOD" => \$switch_to_good,
236 "SWITCH_TO_TEST" => \$switch_to_test,
237 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
Steven Rostedt648a1822012-03-21 11:18:27 -0400238 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500239 "DIE_ON_FAILURE" => \$die_on_failure,
240 "POWER_OFF" => \$power_off,
241 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
242 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
243 "SLEEP_TIME" => \$sleep_time,
244 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
245 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
246 "IGNORE_WARNINGS" => \$ignore_warnings,
Steven Rostedtbe405f92012-01-04 21:51:59 -0500247 "IGNORE_ERRORS" => \$ignore_errors,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500248 "BISECT_MANUAL" => \$bisect_manual,
249 "BISECT_SKIP" => \$bisect_skip,
250 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
251 "BISECT_RET_GOOD" => \$bisect_ret_good,
252 "BISECT_RET_BAD" => \$bisect_ret_bad,
253 "BISECT_RET_SKIP" => \$bisect_ret_skip,
254 "BISECT_RET_ABORT" => \$bisect_ret_abort,
255 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
256 "STORE_FAILURES" => \$store_failures,
257 "STORE_SUCCESSES" => \$store_successes,
258 "TEST_NAME" => \$test_name,
259 "TIMEOUT" => \$timeout,
260 "BOOTED_TIMEOUT" => \$booted_timeout,
261 "CONSOLE" => \$console,
262 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
263 "SUCCESS_LINE" => \$success_line,
264 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
265 "STOP_AFTER_SUCCESS" => \$stop_after_success,
266 "STOP_AFTER_FAILURE" => \$stop_after_failure,
267 "STOP_TEST_AFTER" => \$stop_test_after,
268 "BUILD_TARGET" => \$build_target,
269 "SSH_EXEC" => \$ssh_exec,
270 "SCP_TO_TARGET" => \$scp_to_target,
Steven Rostedt02ad2612012-03-21 08:21:24 -0400271 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500272 "CHECKOUT" => \$checkout,
273 "TARGET_IMAGE" => \$target_image,
274 "LOCALVERSION" => \$localversion,
275
276 "BISECT_GOOD" => \$bisect_good,
277 "BISECT_BAD" => \$bisect_bad,
278 "BISECT_TYPE" => \$bisect_type,
279 "BISECT_START" => \$bisect_start,
280 "BISECT_REPLAY" => \$bisect_replay,
281 "BISECT_FILES" => \$bisect_files,
282 "BISECT_REVERSE" => \$bisect_reverse,
283 "BISECT_CHECK" => \$bisect_check,
284
285 "CONFIG_BISECT" => \$config_bisect,
286 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
Steven Rostedtb0918612012-07-19 15:26:00 -0400287 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500288
289 "PATCHCHECK_TYPE" => \$patchcheck_type,
290 "PATCHCHECK_START" => \$patchcheck_start,
291 "PATCHCHECK_END" => \$patchcheck_end,
292);
293
294# Options may be used by other options, record them.
295my %used_options;
296
Steven Rostedt7bf51072011-10-22 09:07:03 -0400297# default variables that can be used
298chomp ($variable{"PWD"} = `pwd`);
299
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500300$config_help{"MACHINE"} = << "EOF"
301 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500302 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500303EOF
304 ;
305$config_help{"SSH_USER"} = << "EOF"
306 The box is expected to have ssh on normal bootup, provide the user
307 (most likely root, since you need privileged operations)
308EOF
309 ;
310$config_help{"BUILD_DIR"} = << "EOF"
311 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500312 You can use \${PWD} that will be the path where ktest.pl is run, or use
313 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500314EOF
315 ;
316$config_help{"OUTPUT_DIR"} = << "EOF"
317 The directory that the objects will be built (full path).
318 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500319 You can use \${PWD} that will be the path where ktest.pl is run, or use
320 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500321EOF
322 ;
323$config_help{"BUILD_TARGET"} = << "EOF"
324 The location of the compiled file to copy to the target.
325 (relative to OUTPUT_DIR)
326EOF
327 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500328$config_help{"BUILD_OPTIONS"} = << "EOF"
329 Options to add to \"make\" when building.
330 i.e. -j20
331EOF
332 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500333$config_help{"TARGET_IMAGE"} = << "EOF"
334 The place to put your image on the test machine.
335EOF
336 ;
337$config_help{"POWER_CYCLE"} = << "EOF"
338 A script or command to reboot the box.
339
340 Here is a digital loggers power switch example
341 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
342
343 Here is an example to reboot a virtual box on the current host
344 with the name "Guest".
345 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
346EOF
347 ;
348$config_help{"CONSOLE"} = << "EOF"
349 The script or command that reads the console
350
351 If you use ttywatch server, something like the following would work.
352CONSOLE = nc -d localhost 3001
353
354 For a virtual machine with guest name "Guest".
355CONSOLE = virsh console Guest
356EOF
357 ;
358$config_help{"LOCALVERSION"} = << "EOF"
359 Required version ending to differentiate the test
360 from other linux builds on the system.
361EOF
362 ;
363$config_help{"REBOOT_TYPE"} = << "EOF"
364 Way to reboot the box to the test kernel.
365 Only valid options so far are "grub" and "script".
366
367 If you specify grub, it will assume grub version 1
368 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
369 and select that target to reboot to the kernel. If this is not
370 your setup, then specify "script" and have a command or script
371 specified in REBOOT_SCRIPT to boot to the target.
372
373 The entry in /boot/grub/menu.lst must be entered in manually.
374 The test will not modify that file.
375EOF
376 ;
377$config_help{"GRUB_MENU"} = << "EOF"
378 The grub title name for the test kernel to boot
379 (Only mandatory if REBOOT_TYPE = grub)
380
381 Note, ktest.pl will not update the grub menu.lst, you need to
382 manually add an option for the test. ktest.pl will search
383 the grub menu.lst for this option to find what kernel to
384 reboot into.
385
386 For example, if in the /boot/grub/menu.lst the test kernel title has:
387 title Test Kernel
388 kernel vmlinuz-test
389 GRUB_MENU = Test Kernel
390EOF
391 ;
392$config_help{"REBOOT_SCRIPT"} = << "EOF"
393 A script to reboot the target into the test kernel
394 (Only mandatory if REBOOT_TYPE = script)
395EOF
396 ;
397
Steven Rostedtdad98752011-11-22 20:48:57 -0500398sub read_prompt {
399 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400400
401 my $ans;
402
403 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500404 if ($cancel) {
405 print "$prompt [y/n/C] ";
406 } else {
407 print "$prompt [Y/n] ";
408 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400409 $ans = <STDIN>;
410 chomp $ans;
411 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500412 if ($cancel) {
413 $ans = "c";
414 } else {
415 $ans = "y";
416 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400417 }
418 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500419 if ($cancel) {
420 last if ($ans =~ /^c$/i);
421 print "Please answer either 'y', 'n' or 'c'.\n";
422 } else {
423 print "Please answer either 'y' or 'n'.\n";
424 }
425 }
426 if ($ans =~ /^c/i) {
427 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400428 }
429 if ($ans !~ /^y$/i) {
430 return 0;
431 }
432 return 1;
433}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500434
Steven Rostedtdad98752011-11-22 20:48:57 -0500435sub read_yn {
436 my ($prompt) = @_;
437
438 return read_prompt 0, $prompt;
439}
440
441sub read_ync {
442 my ($prompt) = @_;
443
444 return read_prompt 1, $prompt;
445}
446
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500447sub get_ktest_config {
448 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400449 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500450
451 return if (defined($opt{$config}));
452
453 if (defined($config_help{$config})) {
454 print "\n";
455 print $config_help{$config};
456 }
457
458 for (;;) {
459 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500460 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500461 print "\[$default{$config}\] ";
462 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400463 $ans = <STDIN>;
464 $ans =~ s/^\s*(.*\S)\s*$/$1/;
465 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500466 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400467 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500468 } else {
469 print "Your answer can not be blank\n";
470 next;
471 }
472 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500473 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500474 last;
475 }
476}
477
478sub get_ktest_configs {
479 get_ktest_config("MACHINE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500480 get_ktest_config("BUILD_DIR");
481 get_ktest_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500482
Steven Rostedtdbd37832011-11-23 16:00:48 -0500483 if ($newconfig) {
484 get_ktest_config("BUILD_OPTIONS");
485 }
486
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500487 # options required for other than just building a kernel
488 if (!$buildonly) {
Steven Rostedt165708b2011-11-26 20:56:52 -0500489 get_ktest_config("POWER_CYCLE");
490 get_ktest_config("CONSOLE");
491 }
492
493 # options required for install and more
494 if ($buildonly != 1) {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500495 get_ktest_config("SSH_USER");
496 get_ktest_config("BUILD_TARGET");
497 get_ktest_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500498 }
499
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500500 get_ktest_config("LOCALVERSION");
501
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500502 return if ($buildonly);
503
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500504 my $rtype = $opt{"REBOOT_TYPE"};
505
506 if (!defined($rtype)) {
507 if (!defined($opt{"GRUB_MENU"})) {
508 get_ktest_config("REBOOT_TYPE");
509 $rtype = $entered_configs{"REBOOT_TYPE"};
510 } else {
511 $rtype = "grub";
512 }
513 }
514
515 if ($rtype eq "grub") {
516 get_ktest_config("GRUB_MENU");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500517 }
518}
519
Steven Rostedt77d942c2011-05-20 13:36:58 -0400520sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400521 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400522 my $retval = "";
523
524 # We want to check for '\', and it is just easier
525 # to check the previous characet of '$' and not need
526 # to worry if '$' is the first character. By adding
527 # a space to $value, we can just check [^\\]\$ and
528 # it will still work.
529 $value = " $value";
530
531 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
532 my $begin = $1;
533 my $var = $2;
534 my $end = $3;
535 # append beginning of value to retval
536 $retval = "$retval$begin";
537 if (defined($variable{$var})) {
538 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400539 } elsif (defined($remove_undef) && $remove_undef) {
540 # for if statements, any variable that is not defined,
541 # we simple convert to 0
542 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400543 } else {
544 # put back the origin piece.
545 $retval = "$retval\$\{$var\}";
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500546 # This could be an option that is used later, save
547 # it so we don't warn if this option is not one of
548 # ktests options.
549 $used_options{$var} = 1;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400550 }
551 $value = $end;
552 }
553 $retval = "$retval$value";
554
555 # remove the space added in the beginning
556 $retval =~ s/ //;
557
558 return "$retval"
559}
560
Steven Rostedta57419b2010-11-02 15:13:54 -0400561sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400562 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400563
Steven Rostedtcad96662011-12-22 11:32:52 -0500564 my $prvalue = process_variables($rvalue);
565
566 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500567 # Note if a test is something other than build, then we
568 # will need other manditory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500569 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500570 $buildonly = 0;
571 } else {
572 # install still limits some manditory options.
573 $buildonly = 2;
574 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500575 }
576
Steven Rostedta57419b2010-11-02 15:13:54 -0400577 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400578 if (!$override || defined(${$overrides}{$lvalue})) {
579 my $extra = "";
580 if ($override) {
581 $extra = "In the same override section!\n";
582 }
583 die "$name: $.: Option $lvalue defined more than once!\n$extra";
584 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500585 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400586 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500587 if ($rvalue =~ /^\s*$/) {
588 delete $opt{$lvalue};
589 } else {
Steven Rostedtcad96662011-12-22 11:32:52 -0500590 $opt{$lvalue} = $prvalue;
Steven Rostedt21a96792010-11-08 16:45:50 -0500591 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400592}
593
Steven Rostedt77d942c2011-05-20 13:36:58 -0400594sub set_variable {
595 my ($lvalue, $rvalue) = @_;
596
597 if ($rvalue =~ /^\s*$/) {
598 delete $variable{$lvalue};
599 } else {
600 $rvalue = process_variables($rvalue);
601 $variable{$lvalue} = $rvalue;
602 }
603}
604
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400605sub process_compare {
606 my ($lval, $cmp, $rval) = @_;
607
608 # remove whitespace
609
610 $lval =~ s/^\s*//;
611 $lval =~ s/\s*$//;
612
613 $rval =~ s/^\s*//;
614 $rval =~ s/\s*$//;
615
616 if ($cmp eq "==") {
617 return $lval eq $rval;
618 } elsif ($cmp eq "!=") {
619 return $lval ne $rval;
620 }
621
622 my $statement = "$lval $cmp $rval";
623 my $ret = eval $statement;
624
625 # $@ stores error of eval
626 if ($@) {
627 return -1;
628 }
629
630 return $ret;
631}
632
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400633sub value_defined {
634 my ($val) = @_;
635
636 return defined($variable{$2}) ||
637 defined($opt{$2});
638}
639
Steven Rostedt8d735212011-10-17 11:36:44 -0400640my $d = 0;
641sub process_expression {
642 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400643
Steven Rostedt8d735212011-10-17 11:36:44 -0400644 my $c = $d++;
645
646 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
647 my $express = $1;
648
649 if (process_expression($name, $express)) {
650 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
651 } else {
652 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
653 }
654 }
655
656 $d--;
657 my $OR = "\\|\\|";
658 my $AND = "\\&\\&";
659
660 while ($val =~ s/^(.*?)($OR|$AND)//) {
661 my $express = $1;
662 my $op = $2;
663
664 if (process_expression($name, $express)) {
665 if ($op eq "||") {
666 return 1;
667 }
668 } else {
669 if ($op eq "&&") {
670 return 0;
671 }
672 }
673 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400674
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400675 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
676 my $ret = process_compare($1, $2, $3);
677 if ($ret < 0) {
678 die "$name: $.: Unable to process comparison\n";
679 }
680 return $ret;
681 }
682
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400683 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
684 if (defined $1) {
685 return !value_defined($2);
686 } else {
687 return value_defined($2);
688 }
689 }
690
Steven Rostedt45d73a52011-09-30 19:44:53 -0400691 if ($val =~ /^\s*0\s*$/) {
692 return 0;
693 } elsif ($val =~ /^\s*\d+\s*$/) {
694 return 1;
695 }
696
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400697 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400698}
699
700sub process_if {
701 my ($name, $value) = @_;
702
703 # Convert variables and replace undefined ones with 0
704 my $val = process_variables($value, 1);
705 my $ret = process_expression $name, $val;
706
707 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400708}
709
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400710sub __read_config {
711 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400712
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400713 my $in;
714 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400715
Steven Rostedta57419b2010-11-02 15:13:54 -0400716 my $name = $config;
717 $name =~ s,.*/(.*),$1,;
718
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400719 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400720 my $default = 1;
721 my $repeat = 1;
722 my $num_tests_set = 0;
723 my $skip = 0;
724 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400725 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400726 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400727 my $if = 0;
728 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400729 my $override = 0;
730
731 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400732
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400733 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400734
735 # ignore blank lines and comments
736 next if (/^\s*$/ || /\s*\#/);
737
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400738 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400739
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400740 my $type = $1;
741 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400742 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400743
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400744 my $old_test_num;
745 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400746 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400747
748 if ($type eq "TEST_START") {
749
750 if ($num_tests_set) {
751 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
752 }
753
754 $old_test_num = $test_num;
755 $old_repeat = $repeat;
756
757 $test_num += $repeat;
758 $default = 0;
759 $repeat = 1;
760 } else {
761 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400762 }
763
Steven Rostedta9f84422011-10-17 11:06:29 -0400764 # If SKIP is anywhere in the line, the command will be skipped
765 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400766 $skip = 1;
767 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400768 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400769 $skip = 0;
770 }
771
Steven Rostedta9f84422011-10-17 11:06:29 -0400772 if ($rest =~ s/\sELSE\b//) {
773 if (!$if) {
774 die "$name: $.: ELSE found with out matching IF section\n$_";
775 }
776 $if = 0;
777
778 if ($if_set) {
779 $skip = 1;
780 } else {
781 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400782 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400783 }
784
Steven Rostedta9f84422011-10-17 11:06:29 -0400785 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400786 if (process_if($name, $1)) {
787 $if_set = 1;
788 } else {
789 $skip = 1;
790 }
791 $if = 1;
792 } else {
793 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400794 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400795 }
796
Steven Rostedta9f84422011-10-17 11:06:29 -0400797 if (!$skip) {
798 if ($type eq "TEST_START") {
799 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
800 $repeat = $1;
801 $repeat_tests{"$test_num"} = $repeat;
802 }
803 } elsif ($rest =~ s/\sOVERRIDE\b//) {
804 # DEFAULT only
805 $override = 1;
806 # Clear previous overrides
807 %overrides = ();
808 }
809 }
810
811 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400812 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400813 }
814
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400815 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400816 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400817 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400818 }
819
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400820 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400821 if (!$if) {
822 die "$name: $.: ELSE found with out matching IF section\n$_";
823 }
824 $rest = $1;
825 if ($if_set) {
826 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400827 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400828 } else {
829 $skip = 0;
830
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400831 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400832 # May be a ELSE IF section.
833 if (!process_if($name, $1)) {
834 $skip = 1;
835 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400836 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400837 } else {
838 $if = 0;
839 }
840 }
841
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400842 if ($rest !~ /^\s*$/) {
843 die "$name: $.: Gargbage found after DEFAULTS\n$_";
844 }
845
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400846 } elsif (/^\s*INCLUDE\s+(\S+)/) {
847
848 next if ($skip);
849
850 if (!$default) {
851 die "$name: $.: INCLUDE can only be done in default sections\n$_";
852 }
853
854 my $file = process_variables($1);
855
856 if ($file !~ m,^/,) {
857 # check the path of the config file first
858 if ($config =~ m,(.*)/,) {
859 if (-f "$1/$file") {
860 $file = "$1/$file";
861 }
862 }
863 }
864
865 if ( ! -r $file ) {
866 die "$name: $.: Can't read file $file\n$_";
867 }
868
869 if (__read_config($file, \$test_num)) {
870 $test_case = 1;
871 }
872
Steven Rostedta57419b2010-11-02 15:13:54 -0400873 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
874
875 next if ($skip);
876
Steven Rostedt2545eb62010-11-02 15:01:32 -0400877 my $lvalue = $1;
878 my $rvalue = $2;
879
Steven Rostedta57419b2010-11-02 15:13:54 -0400880 if (!$default &&
881 ($lvalue eq "NUM_TESTS" ||
882 $lvalue eq "LOG_FILE" ||
883 $lvalue eq "CLEAR_LOG")) {
884 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400885 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400886
887 if ($lvalue eq "NUM_TESTS") {
888 if ($test_num) {
889 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
890 }
891 if (!$default) {
892 die "$name: $.: NUM_TESTS must be set in default section\n";
893 }
894 $num_tests_set = 1;
895 }
896
897 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400898 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400899 } else {
900 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400901 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400902
903 if ($repeat > 1) {
904 $repeats{$val} = $repeat;
905 }
906 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400907 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
908 next if ($skip);
909
910 my $lvalue = $1;
911 my $rvalue = $2;
912
913 # process config variables.
914 # Config variables are only active while reading the
915 # config and can be defined anywhere. They also ignore
916 # TEST_START and DEFAULTS, but are skipped if they are in
917 # on of these sections that have SKIP defined.
918 # The save variable can be
919 # defined multiple times and the new one simply overrides
920 # the prevous one.
921 set_variable($lvalue, $rvalue);
922
Steven Rostedta57419b2010-11-02 15:13:54 -0400923 } else {
924 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400925 }
926 }
927
Steven Rostedta57419b2010-11-02 15:13:54 -0400928 if ($test_num) {
929 $test_num += $repeat - 1;
930 $opt{"NUM_TESTS"} = $test_num;
931 }
932
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400933 close($in);
934
935 $$current_test_num = $test_num;
936
937 return $test_case;
938}
939
Steven Rostedtc4261d02011-11-23 13:41:18 -0500940sub get_test_case {
941 print "What test case would you like to run?\n";
942 print " (build, install or boot)\n";
943 print " Other tests are available but require editing the config file\n";
944 my $ans = <STDIN>;
945 chomp $ans;
946 $default{"TEST_TYPE"} = $ans;
947}
948
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400949sub read_config {
950 my ($config) = @_;
951
952 my $test_case;
953 my $test_num = 0;
954
955 $test_case = __read_config $config, \$test_num;
956
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500957 # make sure we have all mandatory configs
958 get_ktest_configs;
959
Steven Rostedt0df213c2011-06-14 20:51:37 -0400960 # was a test specified?
961 if (!$test_case) {
962 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -0500963 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400964 }
965
Steven Rostedta75fece2010-11-02 14:58:27 -0400966 # set any defaults
967
968 foreach my $default (keys %default) {
969 if (!defined($opt{$default})) {
970 $opt{$default} = $default{$default};
971 }
972 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500973
974 if ($opt{"IGNORE_UNUSED"} == 1) {
975 return;
976 }
977
978 my %not_used;
979
980 # check if there are any stragglers (typos?)
981 foreach my $option (keys %opt) {
982 my $op = $option;
983 # remove per test labels.
984 $op =~ s/\[.*\]//;
985 if (!exists($option_map{$op}) &&
986 !exists($default{$op}) &&
987 !exists($used_options{$op})) {
988 $not_used{$op} = 1;
989 }
990 }
991
992 if (%not_used) {
993 my $s = "s are";
994 $s = " is" if (keys %not_used == 1);
995 print "The following option$s not used; could be a typo:\n";
996 foreach my $option (keys %not_used) {
997 print "$option\n";
998 }
999 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1000 if (!read_yn "Do you want to continue?") {
1001 exit -1;
1002 }
1003 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001004}
1005
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001006sub __eval_option {
1007 my ($option, $i) = @_;
1008
1009 # Add space to evaluate the character before $
1010 $option = " $option";
1011 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301012 my $repeated = 0;
1013 my $parent = 0;
1014
1015 foreach my $test (keys %repeat_tests) {
1016 if ($i >= $test &&
1017 $i < $test + $repeat_tests{$test}) {
1018
1019 $repeated = 1;
1020 $parent = $test;
1021 last;
1022 }
1023 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001024
1025 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1026 my $start = $1;
1027 my $var = $2;
1028 my $end = $3;
1029
1030 # Append beginning of line
1031 $retval = "$retval$start";
1032
1033 # If the iteration option OPT[$i] exists, then use that.
1034 # otherwise see if the default OPT (without [$i]) exists.
1035
1036 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301037 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001038
1039 if (defined($opt{$o})) {
1040 $o = $opt{$o};
1041 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301042 } elsif ($repeated && defined($opt{$parento})) {
1043 $o = $opt{$parento};
1044 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001045 } elsif (defined($opt{$var})) {
1046 $o = $opt{$var};
1047 $retval = "$retval$o";
1048 } else {
1049 $retval = "$retval\$\{$var\}";
1050 }
1051
1052 $option = $end;
1053 }
1054
1055 $retval = "$retval$option";
1056
1057 $retval =~ s/^ //;
1058
1059 return $retval;
1060}
1061
1062sub eval_option {
1063 my ($option, $i) = @_;
1064
1065 my $prev = "";
1066
1067 # Since an option can evaluate to another option,
1068 # keep iterating until we do not evaluate any more
1069 # options.
1070 my $r = 0;
1071 while ($prev ne $option) {
1072 # Check for recursive evaluations.
1073 # 100 deep should be more than enough.
1074 if ($r++ > 100) {
1075 die "Over 100 evaluations accurred with $option\n" .
1076 "Check for recursive variables\n";
1077 }
1078 $prev = $option;
1079 $option = __eval_option($option, $i);
1080 }
1081
1082 return $option;
1083}
1084
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001085sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001086 if (defined($opt{"LOG_FILE"})) {
1087 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1088 print OUT @_;
1089 close(OUT);
1090 }
1091}
1092
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001093sub logit {
1094 if (defined($opt{"LOG_FILE"})) {
1095 _logit @_;
1096 } else {
1097 print @_;
1098 }
1099}
1100
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001101sub doprint {
1102 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001103 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001104}
1105
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001106sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001107sub start_monitor;
1108sub end_monitor;
1109sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001110
1111sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001112 my ($time) = @_;
1113
Steven Rostedt2b803362011-09-30 18:00:23 -04001114 if (defined($time)) {
1115 start_monitor;
1116 # flush out current monitor
1117 # May contain the reboot success line
1118 wait_for_monitor 1;
1119 }
1120
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001121 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001122 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001123 if (defined($powercycle_after_reboot)) {
1124 sleep $powercycle_after_reboot;
1125 run_command "$power_cycle";
1126 }
1127 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001128 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001129 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001130 }
Andrew Jones2728be42011-08-12 15:32:05 +02001131
1132 if (defined($time)) {
Steven Rostedt2b803362011-09-30 18:00:23 -04001133 wait_for_monitor($time, $reboot_success_line);
Andrew Jones2728be42011-08-12 15:32:05 +02001134 end_monitor;
1135 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001136}
1137
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001138sub reboot_to_good {
1139 my ($time) = @_;
1140
1141 if (defined($switch_to_good)) {
1142 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001143 }
1144
1145 reboot $time;
1146}
1147
Steven Rostedt576f6272010-11-02 14:58:38 -04001148sub do_not_reboot {
1149 my $i = $iteration;
1150
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001151 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001152 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1153 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1154}
1155
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001156sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001157 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001158
Steven Rostedt576f6272010-11-02 14:58:38 -04001159 my $i = $iteration;
1160
1161 if ($reboot_on_error && !do_not_reboot) {
1162
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001163 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001164 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001165
Steven Rostedta75fece2010-11-02 14:58:27 -04001166 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001167 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001168 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001169 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001170
Steven Rostedtf80802c2011-03-07 13:18:47 -05001171 if (defined($opt{"LOG_FILE"})) {
1172 print " See $opt{LOG_FILE} for more info.\n";
1173 }
1174
Steven Rostedt576f6272010-11-02 14:58:38 -04001175 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001176}
1177
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001178sub open_console {
1179 my ($fp) = @_;
1180
1181 my $flags;
1182
Steven Rostedta75fece2010-11-02 14:58:27 -04001183 my $pid = open($fp, "$console|") or
1184 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001185
1186 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001187 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001188 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001189 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001190
1191 return $pid;
1192}
1193
1194sub close_console {
1195 my ($fp, $pid) = @_;
1196
1197 doprint "kill child process $pid\n";
1198 kill 2, $pid;
1199
1200 print "closing!\n";
1201 close($fp);
1202}
1203
1204sub start_monitor {
1205 if ($monitor_cnt++) {
1206 return;
1207 }
1208 $monitor_fp = \*MONFD;
1209 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001210
1211 return;
1212
1213 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001214}
1215
1216sub end_monitor {
1217 if (--$monitor_cnt) {
1218 return;
1219 }
1220 close_console($monitor_fp, $monitor_pid);
1221}
1222
1223sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001224 my ($time, $stop) = @_;
1225 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001226 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001227 my $booted = 0;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001228
Steven Rostedta75fece2010-11-02 14:58:27 -04001229 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001230
1231 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001232 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001233 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001234 last if (!defined($line));
1235 print "$line";
1236 $full_line .= $line;
1237
1238 if (defined($stop) && $full_line =~ /$stop/) {
1239 doprint "wait for monitor detected $stop\n";
1240 $booted = 1;
1241 }
1242
1243 if ($line =~ /\n/) {
1244 $full_line = "";
1245 }
1246 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001247 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001248}
1249
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301250sub save_logs {
1251 my ($result, $basedir) = @_;
1252 my @t = localtime;
1253 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1254 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1255
1256 my $type = $build_type;
1257 if ($type =~ /useconfig/) {
1258 $type = "useconfig";
1259 }
1260
1261 my $dir = "$machine-$test_type-$type-$result-$date";
1262
1263 $dir = "$basedir/$dir";
1264
1265 if (!-d $dir) {
1266 mkpath($dir) or
1267 die "can't create $dir";
1268 }
1269
1270 my %files = (
1271 "config" => $output_config,
1272 "buildlog" => $buildlog,
1273 "dmesg" => $dmesg,
1274 "testlog" => $testlog,
1275 );
1276
1277 while (my ($name, $source) = each(%files)) {
1278 if (-f "$source") {
1279 cp "$source", "$dir/$name" or
1280 die "failed to copy $source";
1281 }
1282 }
1283
1284 doprint "*** Saved info to $dir ***\n";
1285}
1286
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001287sub fail {
1288
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001289 if (defined($post_test)) {
1290 run_command $post_test;
1291 }
1292
Steven Rostedta75fece2010-11-02 14:58:27 -04001293 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001294 dodie @_;
1295 }
1296
Steven Rostedta75fece2010-11-02 14:58:27 -04001297 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001298
Steven Rostedt576f6272010-11-02 14:58:38 -04001299 my $i = $iteration;
1300
Steven Rostedta75fece2010-11-02 14:58:27 -04001301 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001302 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001303 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001304 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001305 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001306
Steven Rostedt9064af52011-06-13 10:38:48 -04001307 my $name = "";
1308
1309 if (defined($test_name)) {
1310 $name = " ($test_name)";
1311 }
1312
Steven Rostedt576f6272010-11-02 14:58:38 -04001313 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1314 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001315 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001316 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1317 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001318
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301319 if (defined($store_failures)) {
1320 save_logs "fail", $store_failures;
1321 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001322
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001323 return 1;
1324}
1325
Steven Rostedt2545eb62010-11-02 15:01:32 -04001326sub run_command {
1327 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001328 my $dolog = 0;
1329 my $dord = 0;
1330 my $pid;
1331
Steven Rostedte48c5292010-11-02 14:35:37 -04001332 $command =~ s/\$SSH_USER/$ssh_user/g;
1333 $command =~ s/\$MACHINE/$machine/g;
1334
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001335 doprint("$command ... ");
1336
1337 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001338 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001339
1340 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001341 open(LOG, ">>$opt{LOG_FILE}") or
1342 dodie "failed to write to log";
1343 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001344 }
1345
1346 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001347 open (RD, ">$redirect") or
1348 dodie "failed to write to redirect $redirect";
1349 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001350 }
1351
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001352 while (<CMD>) {
1353 print LOG if ($dolog);
1354 print RD if ($dord);
1355 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001356
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001357 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001358 my $failed = $?;
1359
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001360 close(CMD);
1361 close(LOG) if ($dolog);
1362 close(RD) if ($dord);
1363
Steven Rostedt2545eb62010-11-02 15:01:32 -04001364 if ($failed) {
1365 doprint "FAILED!\n";
1366 } else {
1367 doprint "SUCCESS\n";
1368 }
1369
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001370 return !$failed;
1371}
1372
Steven Rostedte48c5292010-11-02 14:35:37 -04001373sub run_ssh {
1374 my ($cmd) = @_;
1375 my $cp_exec = $ssh_exec;
1376
1377 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1378 return run_command "$cp_exec";
1379}
1380
1381sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001382 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001383
1384 $cp_scp =~ s/\$SRC_FILE/$src/g;
1385 $cp_scp =~ s/\$DST_FILE/$dst/g;
1386
1387 return run_command "$cp_scp";
1388}
1389
Steven Rostedt02ad2612012-03-21 08:21:24 -04001390sub run_scp_install {
1391 my ($src, $dst) = @_;
1392
1393 my $cp_scp = $scp_to_target_install;
1394
1395 return run_scp($src, $dst, $cp_scp);
1396}
1397
1398sub run_scp_mod {
1399 my ($src, $dst) = @_;
1400
1401 my $cp_scp = $scp_to_target;
1402
1403 return run_scp($src, $dst, $cp_scp);
1404}
1405
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001406sub get_grub_index {
1407
Steven Rostedta75fece2010-11-02 14:58:27 -04001408 if ($reboot_type ne "grub") {
1409 return;
1410 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001411 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001412
1413 doprint "Find grub menu ... ";
1414 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001415
1416 my $ssh_grub = $ssh_exec;
1417 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1418
1419 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001420 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001421
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001422 my $found = 0;
1423
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001424 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001425 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001426 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001427 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001428 last;
1429 } elsif (/^\s*title\s/) {
1430 $grub_number++;
1431 }
1432 }
1433 close(IN);
1434
Steven Rostedta75fece2010-11-02 14:58:27 -04001435 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001436 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001437 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001438}
1439
Steven Rostedt2545eb62010-11-02 15:01:32 -04001440sub wait_for_input
1441{
1442 my ($fp, $time) = @_;
1443 my $rin;
1444 my $ready;
1445 my $line;
1446 my $ch;
1447
1448 if (!defined($time)) {
1449 $time = $timeout;
1450 }
1451
1452 $rin = '';
1453 vec($rin, fileno($fp), 1) = 1;
1454 $ready = select($rin, undef, undef, $time);
1455
1456 $line = "";
1457
1458 # try to read one char at a time
1459 while (sysread $fp, $ch, 1) {
1460 $line .= $ch;
1461 last if ($ch eq "\n");
1462 }
1463
1464 if (!length($line)) {
1465 return undef;
1466 }
1467
1468 return $line;
1469}
1470
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001471sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001472 if (defined($switch_to_test)) {
1473 run_command $switch_to_test;
1474 }
1475
Steven Rostedta75fece2010-11-02 14:58:27 -04001476 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001477 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001478 } elsif (defined $reboot_script) {
1479 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001480 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001481 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001482}
1483
Steven Rostedta57419b2010-11-02 15:13:54 -04001484sub get_sha1 {
1485 my ($commit) = @_;
1486
1487 doprint "git rev-list --max-count=1 $commit ... ";
1488 my $sha1 = `git rev-list --max-count=1 $commit`;
1489 my $ret = $?;
1490
1491 logit $sha1;
1492
1493 if ($ret) {
1494 doprint "FAILED\n";
1495 dodie "Failed to get git $commit";
1496 }
1497
1498 print "SUCCESS\n";
1499
1500 chomp $sha1;
1501
1502 return $sha1;
1503}
1504
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001505sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001506 my $booted = 0;
1507 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001508 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001509 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001510 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001511
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001512 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001513
1514 my $line;
1515 my $full_line = "";
1516
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001517 open(DMESG, "> $dmesg") or
1518 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001519
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001520 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001521
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001522 my $success_start;
1523 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001524 my $monitor_start = time;
1525 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001526 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001527
Steven Rostedt2d01b262011-03-08 09:47:54 -05001528 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001529
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001530 if ($bug && defined($stop_after_failure) &&
1531 $stop_after_failure >= 0) {
1532 my $time = $stop_after_failure - (time - $failure_start);
1533 $line = wait_for_input($monitor_fp, $time);
1534 if (!defined($line)) {
1535 doprint "bug timed out after $booted_timeout seconds\n";
1536 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1537 last;
1538 }
1539 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001540 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001541 if (!defined($line)) {
1542 my $s = $booted_timeout == 1 ? "" : "s";
1543 doprint "Successful boot found: break after $booted_timeout second$s\n";
1544 last;
1545 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001546 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001547 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001548 if (!defined($line)) {
1549 my $s = $timeout == 1 ? "" : "s";
1550 doprint "Timed out after $timeout second$s\n";
1551 last;
1552 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001553 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001554
Steven Rostedt2545eb62010-11-02 15:01:32 -04001555 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001556 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001557
1558 # we are not guaranteed to get a full line
1559 $full_line .= $line;
1560
Steven Rostedta75fece2010-11-02 14:58:27 -04001561 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001562 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001563 $success_start = time;
1564 }
1565
1566 if ($booted && defined($stop_after_success) &&
1567 $stop_after_success >= 0) {
1568 my $now = time;
1569 if ($now - $success_start >= $stop_after_success) {
1570 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1571 last;
1572 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001573 }
1574
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001575 if ($full_line =~ /\[ backtrace testing \]/) {
1576 $skip_call_trace = 1;
1577 }
1578
Steven Rostedt2545eb62010-11-02 15:01:32 -04001579 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001580 if (!$bug && !$skip_call_trace) {
1581 if ($ignore_errors) {
1582 $bug_ignored = 1;
1583 } else {
1584 $bug = 1;
1585 $failure_start = time;
1586 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001587 }
1588 }
1589
1590 if ($bug && defined($stop_after_failure) &&
1591 $stop_after_failure >= 0) {
1592 my $now = time;
1593 if ($now - $failure_start >= $stop_after_failure) {
1594 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1595 last;
1596 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001597 }
1598
1599 if ($full_line =~ /\[ end of backtrace testing \]/) {
1600 $skip_call_trace = 0;
1601 }
1602
1603 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001604 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001605 $bug = 1;
1606 }
1607
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001608 # Detect triple faults by testing the banner
1609 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1610 if ($1 eq $version) {
1611 $version_found = 1;
1612 } elsif ($version_found && $detect_triplefault) {
1613 # We already booted into the kernel we are testing,
1614 # but now we booted into another kernel?
1615 # Consider this a triple fault.
1616 doprint "Aleady booted in Linux kernel $version, but now\n";
1617 doprint "we booted into Linux kernel $1.\n";
1618 doprint "Assuming that this is a triple fault.\n";
1619 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1620 last;
1621 }
1622 }
1623
Steven Rostedt2545eb62010-11-02 15:01:32 -04001624 if ($line =~ /\n/) {
1625 $full_line = "";
1626 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001627
1628 if ($stop_test_after > 0 && !$booted && !$bug) {
1629 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001630 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001631 $done = 1;
1632 }
1633 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001634 }
1635
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001636 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001637
Steven Rostedt2545eb62010-11-02 15:01:32 -04001638 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001639 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001640 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001641 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001642
Steven Rostedta75fece2010-11-02 14:58:27 -04001643 if (!$booted) {
1644 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001645 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001646 }
1647
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001648 if ($bug_ignored) {
1649 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1650 }
1651
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001652 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001653}
1654
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001655sub eval_kernel_version {
1656 my ($option) = @_;
1657
1658 $option =~ s/\$KERNEL_VERSION/$version/g;
1659
1660 return $option;
1661}
1662
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001663sub do_post_install {
1664
1665 return if (!defined($post_install));
1666
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001667 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001668 run_command "$cp_post_install" or
1669 dodie "Failed to run post install";
1670}
1671
Steven Rostedt2545eb62010-11-02 15:01:32 -04001672sub install {
1673
Steven Rostedte0a87422011-09-30 17:50:48 -04001674 return if ($no_install);
1675
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001676 if (defined($pre_install)) {
1677 my $cp_pre_install = eval_kernel_version $pre_install;
1678 run_command "$cp_pre_install" or
1679 dodie "Failed to run pre install";
1680 }
1681
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001682 my $cp_target = eval_kernel_version $target_image;
1683
Steven Rostedt02ad2612012-03-21 08:21:24 -04001684 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001685 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001686
1687 my $install_mods = 0;
1688
1689 # should we process modules?
1690 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001691 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001692 while (<IN>) {
1693 if (/CONFIG_MODULES(=y)?/) {
1694 $install_mods = 1 if (defined($1));
1695 last;
1696 }
1697 }
1698 close(IN);
1699
1700 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001701 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001702 doprint "No modules needed\n";
1703 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001704 }
1705
Steven Rostedt627977d2012-03-21 08:16:15 -04001706 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001707 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001708
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001709 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001710 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001711
Steven Rostedte48c5292010-11-02 14:35:37 -04001712 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001713 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001714
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001715 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001716 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001717 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001718
Steven Rostedt02ad2612012-03-21 08:21:24 -04001719 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001720 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001721
Steven Rostedta75fece2010-11-02 14:58:27 -04001722 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001723
Steven Rostedte7b13442011-06-14 20:44:36 -04001724 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001725 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001726
Steven Rostedte48c5292010-11-02 14:35:37 -04001727 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001728
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001729 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001730}
1731
Steven Rostedtddf607e2011-06-14 20:49:13 -04001732sub get_version {
1733 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04001734 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001735 doprint "$make kernelrelease ... ";
1736 $version = `$make kernelrelease | tail -1`;
1737 chomp($version);
1738 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04001739 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04001740}
1741
1742sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001743 # Make sure the stable kernel has finished booting
1744 start_monitor;
1745 wait_for_monitor 5;
1746 end_monitor;
1747
Steven Rostedtddf607e2011-06-14 20:49:13 -04001748 get_grub_index;
1749 get_version;
1750 install;
1751
1752 start_monitor;
1753 return monitor;
1754}
1755
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001756sub check_buildlog {
1757 my ($patch) = @_;
1758
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001759 my @files = `git show $patch | diffstat -l`;
1760
1761 open(IN, "git show $patch |") or
1762 dodie "failed to show $patch";
1763 while (<IN>) {
1764 if (m,^--- a/(.*),) {
1765 chomp $1;
1766 $files[$#files] = $1;
1767 }
1768 }
1769 close(IN);
1770
1771 open(IN, $buildlog) or dodie "Can't open $buildlog";
1772 while (<IN>) {
1773 if (/^\s*(.*?):.*(warning|error)/) {
1774 my $err = $1;
1775 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001776 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001777 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001778 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001779 }
1780 }
1781 }
1782 }
1783 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001784
1785 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001786}
1787
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001788sub apply_min_config {
1789 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001790
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001791 # Read the config file and remove anything that
1792 # is in the force_config hash (from minconfig and others)
1793 # then add the force config back.
1794
1795 doprint "Applying minimum configurations into $output_config.new\n";
1796
1797 open (OUT, ">$outconfig") or
1798 dodie "Can't create $outconfig";
1799
1800 if (-f $output_config) {
1801 open (IN, $output_config) or
1802 dodie "Failed to open $output_config";
1803 while (<IN>) {
1804 if (/^(# )?(CONFIG_[^\s=]*)/) {
1805 next if (defined($force_config{$2}));
1806 }
1807 print OUT;
1808 }
1809 close IN;
1810 }
1811 foreach my $config (keys %force_config) {
1812 print OUT "$force_config{$config}\n";
1813 }
1814 close OUT;
1815
1816 run_command "mv $outconfig $output_config";
1817}
1818
1819sub make_oldconfig {
1820
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001821 my @force_list = keys %force_config;
1822
1823 if ($#force_list >= 0) {
1824 apply_min_config;
1825 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001826
1827 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001828 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1829 # try a yes '' | oldconfig
1830 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001831 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001832 dodie "failed make config oldconfig";
1833 }
1834}
1835
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001836# read a config file and use this to force new configs.
1837sub load_force_config {
1838 my ($config) = @_;
1839
1840 open(IN, $config) or
1841 dodie "failed to read $config";
1842 while (<IN>) {
1843 chomp;
1844 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1845 $force_config{$1} = $_;
1846 } elsif (/^# (CONFIG_\S*) is not set/) {
1847 $force_config{$1} = $_;
1848 }
1849 }
1850 close IN;
1851}
1852
Steven Rostedt2545eb62010-11-02 15:01:32 -04001853sub build {
1854 my ($type) = @_;
1855
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001856 unlink $buildlog;
1857
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001858 # Failed builds should not reboot the target
1859 my $save_no_reboot = $no_reboot;
1860 $no_reboot = 1;
1861
Steven Rostedt683a3e62012-05-18 13:34:35 -04001862 # Calculate a new version from here.
1863 $have_version = 0;
1864
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001865 if (defined($pre_build)) {
1866 my $ret = run_command $pre_build;
1867 if (!$ret && defined($pre_build_die) &&
1868 $pre_build_die) {
1869 dodie "failed to pre_build\n";
1870 }
1871 }
1872
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001873 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001874 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001875 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001876
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001877 $type = "oldconfig";
1878 }
1879
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001880 # old config can ask questions
1881 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001882 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001883
1884 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001885 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001886
Andrew Jones13488232011-08-12 15:32:04 +02001887 if (!$noclean) {
1888 run_command "mv $output_config $outputdir/config_temp" or
1889 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001890
Andrew Jones13488232011-08-12 15:32:04 +02001891 run_command "$make mrproper" or dodie "make mrproper";
1892
1893 run_command "mv $outputdir/config_temp $output_config" or
1894 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001895 }
1896
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001897 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001898 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001899 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001900 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001901 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001902
1903 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001904 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1905 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001906 close(OUT);
1907
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001908 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001909 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001910 }
1911
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001912 if ($type ne "oldnoconfig") {
1913 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001914 dodie "failed make config";
1915 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001916 # Run old config regardless, to enforce min configurations
1917 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001918
Steven Rostedta75fece2010-11-02 14:58:27 -04001919 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001920 my $build_ret = run_command "$make $build_options";
1921 undef $redirect;
1922
1923 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04001924 # Because a post build may change the kernel version
1925 # do it now.
1926 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001927 my $ret = run_command $post_build;
1928 if (!$ret && defined($post_build_die) &&
1929 $post_build_die) {
1930 dodie "failed to post_build\n";
1931 }
1932 }
1933
1934 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001935 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001936 if ($in_bisect) {
1937 $no_reboot = $save_no_reboot;
1938 return 0;
1939 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001940 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001941 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001942
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001943 $no_reboot = $save_no_reboot;
1944
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001945 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001946}
1947
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001948sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001949 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001950 if (defined($poweroff_after_halt)) {
1951 sleep $poweroff_after_halt;
1952 run_command "$power_off";
1953 }
1954 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001955 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001956 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001957 }
1958}
1959
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001960sub success {
1961 my ($i) = @_;
1962
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001963 if (defined($post_test)) {
1964 run_command $post_test;
1965 }
1966
Steven Rostedte48c5292010-11-02 14:35:37 -04001967 $successes++;
1968
Steven Rostedt9064af52011-06-13 10:38:48 -04001969 my $name = "";
1970
1971 if (defined($test_name)) {
1972 $name = " ($test_name)";
1973 }
1974
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001975 doprint "\n\n*******************************************\n";
1976 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001977 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001978 doprint "*******************************************\n";
1979 doprint "*******************************************\n";
1980
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301981 if (defined($store_successes)) {
1982 save_logs "success", $store_successes;
1983 }
1984
Steven Rostedt576f6272010-11-02 14:58:38 -04001985 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001986 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001987 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001988 }
1989}
1990
Steven Rostedtc960bb92011-03-08 09:22:39 -05001991sub answer_bisect {
1992 for (;;) {
1993 doprint "Pass or fail? [p/f]";
1994 my $ans = <STDIN>;
1995 chomp $ans;
1996 if ($ans eq "p" || $ans eq "P") {
1997 return 1;
1998 } elsif ($ans eq "f" || $ans eq "F") {
1999 return 0;
2000 } else {
2001 print "Please answer 'P' or 'F'\n";
2002 }
2003 }
2004}
2005
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002006sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002007 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002008
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002009 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002010 $reboot_on_error = 0;
2011 $poweroff_on_error = 0;
2012 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002013
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302014 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002015 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302016 undef $redirect;
2017
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002018 exit $failed;
2019}
2020
2021my $child_done;
2022
2023sub child_finished {
2024 $child_done = 1;
2025}
2026
2027sub do_run_test {
2028 my $child_pid;
2029 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002030 my $line;
2031 my $full_line;
2032 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002033
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002034 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002035
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002036 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002037
2038 $child_done = 0;
2039
2040 $SIG{CHLD} = qw(child_finished);
2041
2042 $child_pid = fork;
2043
2044 child_run_test if (!$child_pid);
2045
2046 $full_line = "";
2047
2048 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002049 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002050 if (defined($line)) {
2051
2052 # we are not guaranteed to get a full line
2053 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002054 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002055
2056 if ($full_line =~ /call trace:/i) {
2057 $bug = 1;
2058 }
2059
2060 if ($full_line =~ /Kernel panic -/) {
2061 $bug = 1;
2062 }
2063
2064 if ($line =~ /\n/) {
2065 $full_line = "";
2066 }
2067 }
2068 } while (!$child_done && !$bug);
2069
2070 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002071 my $failure_start = time;
2072 my $now;
2073 do {
2074 $line = wait_for_input($monitor_fp, 1);
2075 if (defined($line)) {
2076 doprint $line;
2077 }
2078 $now = time;
2079 if ($now - $failure_start >= $stop_after_failure) {
2080 last;
2081 }
2082 } while (defined($line));
2083
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002084 doprint "Detected kernel crash!\n";
2085 # kill the child with extreme prejudice
2086 kill 9, $child_pid;
2087 }
2088
2089 waitpid $child_pid, 0;
2090 $child_exit = $?;
2091
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002092 if (!$bug && $in_bisect) {
2093 if (defined($bisect_ret_good)) {
2094 if ($child_exit == $bisect_ret_good) {
2095 return 1;
2096 }
2097 }
2098 if (defined($bisect_ret_skip)) {
2099 if ($child_exit == $bisect_ret_skip) {
2100 return -1;
2101 }
2102 }
2103 if (defined($bisect_ret_abort)) {
2104 if ($child_exit == $bisect_ret_abort) {
2105 fail "test abort" and return -2;
2106 }
2107 }
2108 if (defined($bisect_ret_bad)) {
2109 if ($child_exit == $bisect_ret_skip) {
2110 return 0;
2111 }
2112 }
2113 if (defined($bisect_ret_default)) {
2114 if ($bisect_ret_default eq "good") {
2115 return 1;
2116 } elsif ($bisect_ret_default eq "bad") {
2117 return 0;
2118 } elsif ($bisect_ret_default eq "skip") {
2119 return -1;
2120 } elsif ($bisect_ret_default eq "abort") {
2121 return -2;
2122 } else {
2123 fail "unknown default action: $bisect_ret_default"
2124 and return -2;
2125 }
2126 }
2127 }
2128
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002129 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002130 return 0 if $in_bisect;
2131 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002132 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002133 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002134}
2135
Steven Rostedta75fece2010-11-02 14:58:27 -04002136sub run_git_bisect {
2137 my ($command) = @_;
2138
2139 doprint "$command ... ";
2140
2141 my $output = `$command 2>&1`;
2142 my $ret = $?;
2143
2144 logit $output;
2145
2146 if ($ret) {
2147 doprint "FAILED\n";
2148 dodie "Failed to git bisect";
2149 }
2150
2151 doprint "SUCCESS\n";
2152 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2153 doprint "$1 [$2]\n";
2154 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002155 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002156 doprint "Found bad commit... $1\n";
2157 return 0;
2158 } else {
2159 # we already logged it, just print it now.
2160 print $output;
2161 }
2162
2163 return 1;
2164}
2165
Steven Rostedtc23dca72011-03-08 09:26:31 -05002166sub bisect_reboot {
2167 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002168 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002169}
2170
2171# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002172sub run_bisect_test {
2173 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002174
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002175 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002176 my $result;
2177 my $output;
2178 my $ret;
2179
Steven Rostedt0a05c762010-11-08 11:14:10 -05002180 $in_bisect = 1;
2181
2182 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002183
2184 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002185 if ($failed && $bisect_skip) {
2186 $in_bisect = 0;
2187 return -1;
2188 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002189 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002190
2191 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002192 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002193
2194 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002195 if ($failed && $bisect_skip) {
2196 end_monitor;
2197 bisect_reboot;
2198 $in_bisect = 0;
2199 return -1;
2200 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002201 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002202
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002203 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002204 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002205 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002206 }
2207
2208 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002209 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002210 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002211 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002212 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002213
2214 # reboot the box to a kernel we can ssh to
2215 if ($type ne "build") {
2216 bisect_reboot;
2217 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002218 $in_bisect = 0;
2219
2220 return $result;
2221}
2222
2223sub run_bisect {
2224 my ($type) = @_;
2225 my $buildtype = "oldconfig";
2226
2227 # We should have a minconfig to use?
2228 if (defined($minconfig)) {
2229 $buildtype = "useconfig:$minconfig";
2230 }
2231
2232 my $ret = run_bisect_test $type, $buildtype;
2233
Steven Rostedtc960bb92011-03-08 09:22:39 -05002234 if ($bisect_manual) {
2235 $ret = answer_bisect;
2236 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002237
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002238 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002239 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002240 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002241 }
2242
Steven Rostedtc23dca72011-03-08 09:26:31 -05002243 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002244 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002245 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002246 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002247 } elsif ($bisect_skip) {
2248 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2249 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002250 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002251}
2252
Steven Rostedtdad98752011-11-22 20:48:57 -05002253sub update_bisect_replay {
2254 my $tmp_log = "$tmpdir/ktest_bisect_log";
2255 run_command "git bisect log > $tmp_log" or
2256 die "can't create bisect log";
2257 return $tmp_log;
2258}
2259
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002260sub bisect {
2261 my ($i) = @_;
2262
2263 my $result;
2264
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002265 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2266 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2267 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002268
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002269 my $good = $bisect_good;
2270 my $bad = $bisect_bad;
2271 my $type = $bisect_type;
2272 my $start = $bisect_start;
2273 my $replay = $bisect_replay;
2274 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002275
2276 if (defined($start_files)) {
2277 $start_files = " -- " . $start_files;
2278 } else {
2279 $start_files = "";
2280 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002281
Steven Rostedta57419b2010-11-02 15:13:54 -04002282 # convert to true sha1's
2283 $good = get_sha1($good);
2284 $bad = get_sha1($bad);
2285
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002286 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002287 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2288 $reverse_bisect = 1;
2289 } else {
2290 $reverse_bisect = 0;
2291 }
2292
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002293 # Can't have a test without having a test to run
2294 if ($type eq "test" && !defined($run_test)) {
2295 $type = "boot";
2296 }
2297
Steven Rostedtdad98752011-11-22 20:48:57 -05002298 # Check if a bisect was running
2299 my $bisect_start_file = "$builddir/.git/BISECT_START";
2300
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002301 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002302 my $do_check = defined($check) && $check ne "0";
2303
2304 if ( -f $bisect_start_file ) {
2305 print "Bisect in progress found\n";
2306 if ($do_check) {
2307 print " If you say yes, then no checks of good or bad will be done\n";
2308 }
2309 if (defined($replay)) {
2310 print "** BISECT_REPLAY is defined in config file **";
2311 print " Ignore config option and perform new git bisect log?\n";
2312 if (read_ync " (yes, no, or cancel) ") {
2313 $replay = update_bisect_replay;
2314 $do_check = 0;
2315 }
2316 } elsif (read_yn "read git log and continue?") {
2317 $replay = update_bisect_replay;
2318 $do_check = 0;
2319 }
2320 }
2321
2322 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002323
2324 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002325 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002326
2327 if ($check ne "good") {
2328 doprint "TESTING BISECT BAD [$bad]\n";
2329 run_command "git checkout $bad" or
2330 die "Failed to checkout $bad";
2331
2332 $result = run_bisect $type;
2333
2334 if ($result ne "bad") {
2335 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2336 }
2337 }
2338
2339 if ($check ne "bad") {
2340 doprint "TESTING BISECT GOOD [$good]\n";
2341 run_command "git checkout $good" or
2342 die "Failed to checkout $good";
2343
2344 $result = run_bisect $type;
2345
2346 if ($result ne "good") {
2347 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2348 }
2349 }
2350
2351 # checkout where we started
2352 run_command "git checkout $head" or
2353 die "Failed to checkout $head";
2354 }
2355
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002356 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002357 dodie "could not start bisect";
2358
2359 run_command "git bisect good $good" or
2360 dodie "could not set bisect good to $good";
2361
2362 run_git_bisect "git bisect bad $bad" or
2363 dodie "could not set bisect bad to $bad";
2364
2365 if (defined($replay)) {
2366 run_command "git bisect replay $replay" or
2367 dodie "failed to run replay";
2368 }
2369
2370 if (defined($start)) {
2371 run_command "git checkout $start" or
2372 dodie "failed to checkout $start";
2373 }
2374
2375 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002376 do {
2377 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002378 $test = run_git_bisect "git bisect $result";
2379 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002380
2381 run_command "git bisect log" or
2382 dodie "could not capture git bisect log";
2383
2384 run_command "git bisect reset" or
2385 dodie "could not reset git bisect";
2386
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002387 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002388
Steven Rostedt0a05c762010-11-08 11:14:10 -05002389 success $i;
2390}
2391
2392my %config_ignore;
2393my %config_set;
2394
2395my %config_list;
2396my %null_config;
2397
2398my %dependency;
2399
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002400sub assign_configs {
2401 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002402
2403 open (IN, $config)
2404 or dodie "Failed to read $config";
2405
2406 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002407 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002408 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002409 }
2410 }
2411
2412 close(IN);
2413}
2414
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002415sub process_config_ignore {
2416 my ($config) = @_;
2417
2418 assign_configs \%config_ignore, $config;
2419}
2420
Steven Rostedt0a05c762010-11-08 11:14:10 -05002421sub read_current_config {
2422 my ($config_ref) = @_;
2423
2424 %{$config_ref} = ();
2425 undef %{$config_ref};
2426
2427 my @key = keys %{$config_ref};
2428 if ($#key >= 0) {
2429 print "did not delete!\n";
2430 exit;
2431 }
2432 open (IN, "$output_config");
2433
2434 while (<IN>) {
2435 if (/^(CONFIG\S+)=(.*)/) {
2436 ${$config_ref}{$1} = $2;
2437 }
2438 }
2439 close(IN);
2440}
2441
2442sub get_dependencies {
2443 my ($config) = @_;
2444
2445 my $arr = $dependency{$config};
2446 if (!defined($arr)) {
2447 return ();
2448 }
2449
2450 my @deps = @{$arr};
2451
2452 foreach my $dep (@{$arr}) {
2453 print "ADD DEP $dep\n";
2454 @deps = (@deps, get_dependencies $dep);
2455 }
2456
2457 return @deps;
2458}
2459
2460sub create_config {
2461 my @configs = @_;
2462
2463 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2464
2465 foreach my $config (@configs) {
2466 print OUT "$config_set{$config}\n";
2467 my @deps = get_dependencies $config;
2468 foreach my $dep (@deps) {
2469 print OUT "$config_set{$dep}\n";
2470 }
2471 }
2472
2473 foreach my $config (keys %config_ignore) {
2474 print OUT "$config_ignore{$config}\n";
2475 }
2476 close(OUT);
2477
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002478 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002479}
2480
2481sub compare_configs {
2482 my (%a, %b) = @_;
2483
2484 foreach my $item (keys %a) {
2485 if (!defined($b{$item})) {
2486 print "diff $item\n";
2487 return 1;
2488 }
2489 delete $b{$item};
2490 }
2491
2492 my @keys = keys %b;
2493 if ($#keys) {
2494 print "diff2 $keys[0]\n";
2495 }
2496 return -1 if ($#keys >= 0);
2497
2498 return 0;
2499}
2500
2501sub run_config_bisect_test {
2502 my ($type) = @_;
2503
2504 return run_bisect_test $type, "oldconfig";
2505}
2506
2507sub process_passed {
2508 my (%configs) = @_;
2509
2510 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2511 # Passed! All these configs are part of a good compile.
2512 # Add them to the min options.
2513 foreach my $config (keys %configs) {
2514 if (defined($config_list{$config})) {
2515 doprint " removing $config\n";
2516 $config_ignore{$config} = $config_list{$config};
2517 delete $config_list{$config};
2518 }
2519 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002520 doprint "config copied to $outputdir/config_good\n";
2521 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002522}
2523
2524sub process_failed {
2525 my ($config) = @_;
2526
2527 doprint "\n\n***************************************\n";
2528 doprint "Found bad config: $config\n";
2529 doprint "***************************************\n\n";
2530}
2531
2532sub run_config_bisect {
2533
2534 my @start_list = keys %config_list;
2535
2536 if ($#start_list < 0) {
2537 doprint "No more configs to test!!!\n";
2538 return -1;
2539 }
2540
2541 doprint "***** RUN TEST ***\n";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002542 my $type = $config_bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002543 my $ret;
2544 my %current_config;
2545
2546 my $count = $#start_list + 1;
2547 doprint " $count configs to test\n";
2548
2549 my $half = int($#start_list / 2);
2550
2551 do {
2552 my @tophalf = @start_list[0 .. $half];
2553
2554 create_config @tophalf;
2555 read_current_config \%current_config;
2556
2557 $count = $#tophalf + 1;
2558 doprint "Testing $count configs\n";
2559 my $found = 0;
2560 # make sure we test something
2561 foreach my $config (@tophalf) {
2562 if (defined($current_config{$config})) {
2563 logit " $config\n";
2564 $found = 1;
2565 }
2566 }
2567 if (!$found) {
2568 # try the other half
2569 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002570 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05002571 create_config @tophalf;
2572 read_current_config \%current_config;
2573 foreach my $config (@tophalf) {
2574 if (defined($current_config{$config})) {
2575 logit " $config\n";
2576 $found = 1;
2577 }
2578 }
2579 if (!$found) {
2580 doprint "Failed: Can't make new config with current configs\n";
2581 foreach my $config (@start_list) {
2582 doprint " CONFIG: $config\n";
2583 }
2584 return -1;
2585 }
2586 $count = $#tophalf + 1;
2587 doprint "Testing $count configs\n";
2588 }
2589
2590 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002591 if ($bisect_manual) {
2592 $ret = answer_bisect;
2593 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002594 if ($ret) {
2595 process_passed %current_config;
2596 return 0;
2597 }
2598
2599 doprint "This config had a failure.\n";
2600 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002601 doprint "config copied to $outputdir/config_bad\n";
2602 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002603
2604 # A config exists in this group that was bad.
2605 foreach my $config (keys %config_list) {
2606 if (!defined($current_config{$config})) {
2607 doprint " removing $config\n";
2608 delete $config_list{$config};
2609 }
2610 }
2611
2612 @start_list = @tophalf;
2613
2614 if ($#start_list == 0) {
2615 process_failed $start_list[0];
2616 return 1;
2617 }
2618
2619 # remove half the configs we are looking at and see if
2620 # they are good.
2621 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002622 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002623
Steven Rostedtc960bb92011-03-08 09:22:39 -05002624 # we found a single config, try it again unless we are running manually
2625
2626 if ($bisect_manual) {
2627 process_failed $start_list[0];
2628 return 1;
2629 }
2630
Steven Rostedt0a05c762010-11-08 11:14:10 -05002631 my @tophalf = @start_list[0 .. 0];
2632
2633 $ret = run_config_bisect_test $type;
2634 if ($ret) {
2635 process_passed %current_config;
2636 return 0;
2637 }
2638
2639 process_failed $start_list[0];
2640 return 1;
2641}
2642
2643sub config_bisect {
2644 my ($i) = @_;
2645
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002646 my $start_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002647
2648 my $tmpconfig = "$tmpdir/use_config";
2649
Steven Rostedt30f75da2011-06-13 10:35:35 -04002650 if (defined($config_bisect_good)) {
2651 process_config_ignore $config_bisect_good;
2652 }
2653
Steven Rostedt0a05c762010-11-08 11:14:10 -05002654 # Make the file with the bad config and the min config
2655 if (defined($minconfig)) {
2656 # read the min config for things to ignore
2657 run_command "cp $minconfig $tmpconfig" or
2658 dodie "failed to copy $minconfig to $tmpconfig";
2659 } else {
2660 unlink $tmpconfig;
2661 }
2662
Steven Rostedt0a05c762010-11-08 11:14:10 -05002663 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002664 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002665 process_config_ignore $tmpconfig;
2666 }
2667
2668 # now process the start config
2669 run_command "cp $start_config $output_config" or
2670 dodie "failed to copy $start_config to $output_config";
2671
2672 # read directly what we want to check
2673 my %config_check;
2674 open (IN, $output_config)
Masanari Iidaf9dee312012-02-11 21:46:56 +09002675 or dodie "failed to open $output_config";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002676
2677 while (<IN>) {
2678 if (/^((CONFIG\S*)=.*)/) {
2679 $config_check{$2} = $1;
2680 }
2681 }
2682 close(IN);
2683
Steven Rostedt250bae82011-07-15 22:05:59 -04002684 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002685 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002686
2687 # check to see what we lost (or gained)
2688 open (IN, $output_config)
2689 or dodie "Failed to read $start_config";
2690
2691 my %removed_configs;
2692 my %added_configs;
2693
2694 while (<IN>) {
2695 if (/^((CONFIG\S*)=.*)/) {
2696 # save off all options
2697 $config_set{$2} = $1;
2698 if (defined($config_check{$2})) {
2699 if (defined($config_ignore{$2})) {
2700 $removed_configs{$2} = $1;
2701 } else {
2702 $config_list{$2} = $1;
2703 }
2704 } elsif (!defined($config_ignore{$2})) {
2705 $added_configs{$2} = $1;
2706 $config_list{$2} = $1;
2707 }
2708 }
2709 }
2710 close(IN);
2711
2712 my @confs = keys %removed_configs;
2713 if ($#confs >= 0) {
2714 doprint "Configs overridden by default configs and removed from check:\n";
2715 foreach my $config (@confs) {
2716 doprint " $config\n";
2717 }
2718 }
2719 @confs = keys %added_configs;
2720 if ($#confs >= 0) {
2721 doprint "Configs appearing in make oldconfig and added:\n";
2722 foreach my $config (@confs) {
2723 doprint " $config\n";
2724 }
2725 }
2726
2727 my %config_test;
2728 my $once = 0;
2729
2730 # Sometimes kconfig does weird things. We must make sure
2731 # that the config we autocreate has everything we need
2732 # to test, otherwise we may miss testing configs, or
2733 # may not be able to create a new config.
2734 # Here we create a config with everything set.
2735 create_config (keys %config_list);
2736 read_current_config \%config_test;
2737 foreach my $config (keys %config_list) {
2738 if (!defined($config_test{$config})) {
2739 if (!$once) {
2740 $once = 1;
2741 doprint "Configs not produced by kconfig (will not be checked):\n";
2742 }
2743 doprint " $config\n";
2744 delete $config_list{$config};
2745 }
2746 }
2747 my $ret;
Steven Rostedtb0918612012-07-19 15:26:00 -04002748
2749 if (defined($config_bisect_check) && $config_bisect_check) {
2750 doprint " Checking to make sure bad config with min config fails\n";
2751 create_config keys %config_list;
2752 $ret = run_config_bisect_test $config_bisect_type;
2753 if ($ret) {
2754 doprint " FAILED! Bad config with min config boots fine\n";
2755 return -1;
2756 }
2757 doprint " Bad config with min config fails as expected\n";
2758 }
2759
Steven Rostedt0a05c762010-11-08 11:14:10 -05002760 do {
2761 $ret = run_config_bisect;
2762 } while (!$ret);
2763
2764 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002765
2766 success $i;
2767}
2768
Steven Rostedt27d934b2011-05-20 09:18:18 -04002769sub patchcheck_reboot {
2770 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002771 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002772}
2773
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002774sub patchcheck {
2775 my ($i) = @_;
2776
2777 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002778 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002779 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002780 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002781
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002782 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002783
2784 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002785 if (defined($patchcheck_end)) {
2786 $end = $patchcheck_end;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002787 }
2788
Steven Rostedta57419b2010-11-02 15:13:54 -04002789 # Get the true sha1's since we can use things like HEAD~3
2790 $start = get_sha1($start);
2791 $end = get_sha1($end);
2792
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002793 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002794
2795 # Can't have a test without having a test to run
2796 if ($type eq "test" && !defined($run_test)) {
2797 $type = "boot";
2798 }
2799
2800 open (IN, "git log --pretty=oneline $end|") or
2801 dodie "could not get git list";
2802
2803 my @list;
2804
2805 while (<IN>) {
2806 chomp;
2807 $list[$#list+1] = $_;
2808 last if (/^$start/);
2809 }
2810 close(IN);
2811
2812 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002813 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002814 }
2815
2816 # go backwards in the list
2817 @list = reverse @list;
2818
2819 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002820 my %ignored_warnings;
2821
2822 if (defined($ignore_warnings)) {
2823 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2824 $ignored_warnings{$sha1} = 1;
2825 }
2826 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002827
2828 $in_patchcheck = 1;
2829 foreach my $item (@list) {
2830 my $sha1 = $item;
2831 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2832
2833 doprint "\nProcessing commit $item\n\n";
2834
2835 run_command "git checkout $sha1" or
2836 die "Failed to checkout $sha1";
2837
2838 # only clean on the first and last patch
2839 if ($item eq $list[0] ||
2840 $item eq $list[$#list]) {
2841 $noclean = $save_clean;
2842 } else {
2843 $noclean = 1;
2844 }
2845
2846 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002847 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002848 } else {
2849 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002850 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002851 }
2852
Steven Rostedt19902072011-06-14 20:46:25 -04002853
2854 if (!defined($ignored_warnings{$sha1})) {
2855 check_buildlog $sha1 or return 0;
2856 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002857
2858 next if ($type eq "build");
2859
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002860 my $failed = 0;
2861
Steven Rostedtddf607e2011-06-14 20:49:13 -04002862 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002863
2864 if (!$failed && $type ne "boot"){
2865 do_run_test or $failed = 1;
2866 }
2867 end_monitor;
2868 return 0 if ($failed);
2869
Steven Rostedt27d934b2011-05-20 09:18:18 -04002870 patchcheck_reboot;
2871
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002872 }
2873 $in_patchcheck = 0;
2874 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002875
2876 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002877}
2878
Steven Rostedtb9066f62011-07-15 21:25:24 -04002879my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002880my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002881my $iflevel = 0;
2882my @ifdeps;
2883
2884# prevent recursion
2885my %read_kconfigs;
2886
Steven Rostedtac6974c2011-10-04 09:40:17 -04002887sub add_dep {
2888 # $config depends on $dep
2889 my ($config, $dep) = @_;
2890
2891 if (defined($depends{$config})) {
2892 $depends{$config} .= " " . $dep;
2893 } else {
2894 $depends{$config} = $dep;
2895 }
2896
2897 # record the number of configs depending on $dep
2898 if (defined $depcount{$dep}) {
2899 $depcount{$dep}++;
2900 } else {
2901 $depcount{$dep} = 1;
2902 }
2903}
2904
Steven Rostedtb9066f62011-07-15 21:25:24 -04002905# taken from streamline_config.pl
2906sub read_kconfig {
2907 my ($kconfig) = @_;
2908
2909 my $state = "NONE";
2910 my $config;
2911 my @kconfigs;
2912
2913 my $cont = 0;
2914 my $line;
2915
2916
2917 if (! -f $kconfig) {
2918 doprint "file $kconfig does not exist, skipping\n";
2919 return;
2920 }
2921
2922 open(KIN, "$kconfig")
2923 or die "Can't open $kconfig";
2924 while (<KIN>) {
2925 chomp;
2926
2927 # Make sure that lines ending with \ continue
2928 if ($cont) {
2929 $_ = $line . " " . $_;
2930 }
2931
2932 if (s/\\$//) {
2933 $cont = 1;
2934 $line = $_;
2935 next;
2936 }
2937
2938 $cont = 0;
2939
2940 # collect any Kconfig sources
2941 if (/^source\s*"(.*)"/) {
2942 $kconfigs[$#kconfigs+1] = $1;
2943 }
2944
2945 # configs found
2946 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2947 $state = "NEW";
2948 $config = $2;
2949
2950 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04002951 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04002952 }
2953
2954 # collect the depends for the config
2955 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2956
Steven Rostedtac6974c2011-10-04 09:40:17 -04002957 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002958
2959 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04002960 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2961
2962 # selected by depends on config
2963 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002964
2965 # Check for if statements
2966 } elsif (/^if\s+(.*\S)\s*$/) {
2967 my $deps = $1;
2968 # remove beginning and ending non text
2969 $deps =~ s/^[^a-zA-Z0-9_]*//;
2970 $deps =~ s/[^a-zA-Z0-9_]*$//;
2971
2972 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2973
2974 $ifdeps[$iflevel++] = join ':', @deps;
2975
2976 } elsif (/^endif/) {
2977
2978 $iflevel-- if ($iflevel);
2979
2980 # stop on "help"
2981 } elsif (/^\s*help\s*$/) {
2982 $state = "NONE";
2983 }
2984 }
2985 close(KIN);
2986
2987 # read in any configs that were found.
2988 foreach $kconfig (@kconfigs) {
2989 if (!defined($read_kconfigs{$kconfig})) {
2990 $read_kconfigs{$kconfig} = 1;
2991 read_kconfig("$builddir/$kconfig");
2992 }
2993 }
2994}
2995
2996sub read_depends {
2997 # find out which arch this is by the kconfig file
2998 open (IN, $output_config)
2999 or dodie "Failed to read $output_config";
3000 my $arch;
3001 while (<IN>) {
3002 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3003 $arch = $1;
3004 last;
3005 }
3006 }
3007 close IN;
3008
3009 if (!defined($arch)) {
3010 doprint "Could not find arch from config file\n";
3011 doprint "no dependencies used\n";
3012 return;
3013 }
3014
3015 # arch is really the subarch, we need to know
3016 # what directory to look at.
3017 if ($arch eq "i386" || $arch eq "x86_64") {
3018 $arch = "x86";
3019 } elsif ($arch =~ /^tile/) {
3020 $arch = "tile";
3021 }
3022
3023 my $kconfig = "$builddir/arch/$arch/Kconfig";
3024
3025 if (! -f $kconfig && $arch =~ /\d$/) {
3026 my $orig = $arch;
3027 # some subarchs have numbers, truncate them
3028 $arch =~ s/\d*$//;
3029 $kconfig = "$builddir/arch/$arch/Kconfig";
3030 if (! -f $kconfig) {
3031 doprint "No idea what arch dir $orig is for\n";
3032 doprint "no dependencies used\n";
3033 return;
3034 }
3035 }
3036
3037 read_kconfig($kconfig);
3038}
3039
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003040sub read_config_list {
3041 my ($config) = @_;
3042
3043 open (IN, $config)
3044 or dodie "Failed to read $config";
3045
3046 while (<IN>) {
3047 if (/^((CONFIG\S*)=.*)/) {
3048 if (!defined($config_ignore{$2})) {
3049 $config_list{$2} = $1;
3050 }
3051 }
3052 }
3053
3054 close(IN);
3055}
3056
3057sub read_output_config {
3058 my ($config) = @_;
3059
3060 assign_configs \%config_ignore, $config;
3061}
3062
3063sub make_new_config {
3064 my @configs = @_;
3065
3066 open (OUT, ">$output_config")
3067 or dodie "Failed to write $output_config";
3068
3069 foreach my $config (@configs) {
3070 print OUT "$config\n";
3071 }
3072 close OUT;
3073}
3074
Steven Rostedtac6974c2011-10-04 09:40:17 -04003075sub chomp_config {
3076 my ($config) = @_;
3077
3078 $config =~ s/CONFIG_//;
3079
3080 return $config;
3081}
3082
Steven Rostedtb9066f62011-07-15 21:25:24 -04003083sub get_depends {
3084 my ($dep) = @_;
3085
Steven Rostedtac6974c2011-10-04 09:40:17 -04003086 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003087
3088 $dep = $depends{"$kconfig"};
3089
3090 # the dep string we have saves the dependencies as they
3091 # were found, including expressions like ! && ||. We
3092 # want to split this out into just an array of configs.
3093
3094 my $valid = "A-Za-z_0-9";
3095
3096 my @configs;
3097
3098 while ($dep =~ /[$valid]/) {
3099
3100 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3101 my $conf = "CONFIG_" . $1;
3102
3103 $configs[$#configs + 1] = $conf;
3104
3105 $dep =~ s/^[^$valid]*[$valid]+//;
3106 } else {
3107 die "this should never happen";
3108 }
3109 }
3110
3111 return @configs;
3112}
3113
3114my %min_configs;
3115my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003116my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003117my %processed_configs;
3118my %nochange_config;
3119
3120sub test_this_config {
3121 my ($config) = @_;
3122
3123 my $found;
3124
3125 # if we already processed this config, skip it
3126 if (defined($processed_configs{$config})) {
3127 return undef;
3128 }
3129 $processed_configs{$config} = 1;
3130
3131 # if this config failed during this round, skip it
3132 if (defined($nochange_config{$config})) {
3133 return undef;
3134 }
3135
Steven Rostedtac6974c2011-10-04 09:40:17 -04003136 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003137
3138 # Test dependencies first
3139 if (defined($depends{"$kconfig"})) {
3140 my @parents = get_depends $config;
3141 foreach my $parent (@parents) {
3142 # if the parent is in the min config, check it first
3143 next if (!defined($min_configs{$parent}));
3144 $found = test_this_config($parent);
3145 if (defined($found)) {
3146 return $found;
3147 }
3148 }
3149 }
3150
3151 # Remove this config from the list of configs
3152 # do a make oldnoconfig and then read the resulting
3153 # .config to make sure it is missing the config that
3154 # we had before
3155 my %configs = %min_configs;
3156 delete $configs{$config};
3157 make_new_config ((values %configs), (values %keep_configs));
3158 make_oldconfig;
3159 undef %configs;
3160 assign_configs \%configs, $output_config;
3161
3162 return $config if (!defined($configs{$config}));
3163
3164 doprint "disabling config $config did not change .config\n";
3165
3166 $nochange_config{$config} = 1;
3167
3168 return undef;
3169}
3170
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003171sub make_min_config {
3172 my ($i) = @_;
3173
Steven Rostedtccc513b2012-05-21 17:13:40 -04003174 my $type = $minconfig_type;
3175 if ($type ne "boot" && $type ne "test") {
3176 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3177 " make_min_config works only with 'boot' and 'test'\n" and return;
3178 }
3179
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003180 if (!defined($output_minconfig)) {
3181 fail "OUTPUT_MIN_CONFIG not defined" and return;
3182 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003183
3184 # If output_minconfig exists, and the start_minconfig
3185 # came from min_config, than ask if we should use
3186 # that instead.
3187 if (-f $output_minconfig && !$start_minconfig_defined) {
3188 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003189 if (!defined($use_output_minconfig)) {
3190 if (read_yn " Use it as minconfig?") {
3191 $start_minconfig = $output_minconfig;
3192 }
3193 } elsif ($use_output_minconfig > 0) {
3194 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003195 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003196 } else {
3197 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003198 }
3199 }
3200
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003201 if (!defined($start_minconfig)) {
3202 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3203 }
3204
Steven Rostedt35ce5952011-07-15 21:57:25 -04003205 my $temp_config = "$tmpdir/temp_config";
3206
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003207 # First things first. We build an allnoconfig to find
3208 # out what the defaults are that we can't touch.
3209 # Some are selections, but we really can't handle selections.
3210
3211 my $save_minconfig = $minconfig;
3212 undef $minconfig;
3213
3214 run_command "$make allnoconfig" or return 0;
3215
Steven Rostedtb9066f62011-07-15 21:25:24 -04003216 read_depends;
3217
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003218 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003219
Steven Rostedt43d1b652011-07-15 22:01:56 -04003220 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003221 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003222
3223 if (defined($ignore_config)) {
3224 # make sure the file exists
3225 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003226 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003227 }
3228
Steven Rostedt43d1b652011-07-15 22:01:56 -04003229 %keep_configs = %save_configs;
3230
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003231 doprint "Load initial configs from $start_minconfig\n";
3232
3233 # Look at the current min configs, and save off all the
3234 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003235 assign_configs \%min_configs, $start_minconfig;
3236
3237 my @config_keys = keys %min_configs;
3238
Steven Rostedtac6974c2011-10-04 09:40:17 -04003239 # All configs need a depcount
3240 foreach my $config (@config_keys) {
3241 my $kconfig = chomp_config $config;
3242 if (!defined $depcount{$kconfig}) {
3243 $depcount{$kconfig} = 0;
3244 }
3245 }
3246
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003247 # Remove anything that was set by the make allnoconfig
3248 # we shouldn't need them as they get set for us anyway.
3249 foreach my $config (@config_keys) {
3250 # Remove anything in the ignore_config
3251 if (defined($keep_configs{$config})) {
3252 my $file = $ignore_config;
3253 $file =~ s,.*/(.*?)$,$1,;
3254 doprint "$config set by $file ... ignored\n";
3255 delete $min_configs{$config};
3256 next;
3257 }
3258 # But make sure the settings are the same. If a min config
3259 # sets a selection, we do not want to get rid of it if
3260 # it is not the same as what we have. Just move it into
3261 # the keep configs.
3262 if (defined($config_ignore{$config})) {
3263 if ($config_ignore{$config} ne $min_configs{$config}) {
3264 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3265 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3266 $keep_configs{$config} = $min_configs{$config};
3267 } else {
3268 doprint "$config set by allnoconfig ... ignored\n";
3269 }
3270 delete $min_configs{$config};
3271 }
3272 }
3273
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003274 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003275 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003276
3277 while (!$done) {
3278
3279 my $config;
3280 my $found;
3281
3282 # Now disable each config one by one and do a make oldconfig
3283 # till we find a config that changes our list.
3284
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003285 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003286
3287 # Sort keys by who is most dependent on
3288 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3289 @test_configs ;
3290
3291 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003292 my $reset = 1;
3293 for (my $i = 0; $i < $#test_configs; $i++) {
3294 if (!defined($nochange_config{$test_configs[0]})) {
3295 $reset = 0;
3296 last;
3297 }
3298 # This config didn't change the .config last time.
3299 # Place it at the end
3300 my $config = shift @test_configs;
3301 push @test_configs, $config;
3302 }
3303
3304 # if every test config has failed to modify the .config file
3305 # in the past, then reset and start over.
3306 if ($reset) {
3307 undef %nochange_config;
3308 }
3309
Steven Rostedtb9066f62011-07-15 21:25:24 -04003310 undef %processed_configs;
3311
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003312 foreach my $config (@test_configs) {
3313
Steven Rostedtb9066f62011-07-15 21:25:24 -04003314 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003315
Steven Rostedtb9066f62011-07-15 21:25:24 -04003316 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003317
3318 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003319 }
3320
3321 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003322 # we could have failed due to the nochange_config hash
3323 # reset and try again
3324 if (!$take_two) {
3325 undef %nochange_config;
3326 $take_two = 1;
3327 next;
3328 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003329 doprint "No more configs found that we can disable\n";
3330 $done = 1;
3331 last;
3332 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003333 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003334
3335 $config = $found;
3336
3337 doprint "Test with $config disabled\n";
3338
3339 # set in_bisect to keep build and monitor from dieing
3340 $in_bisect = 1;
3341
3342 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003343 build "oldconfig" or $failed = 1;
3344 if (!$failed) {
3345 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003346
3347 if ($type eq "test" && !$failed) {
3348 do_run_test or $failed = 1;
3349 }
3350
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003351 end_monitor;
3352 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003353
3354 $in_bisect = 0;
3355
3356 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003357 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003358 # this config is needed, add it to the ignore list.
3359 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003360 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003361 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003362
3363 # update new ignore configs
3364 if (defined($ignore_config)) {
3365 open (OUT, ">$temp_config")
3366 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003367 foreach my $config (keys %save_configs) {
3368 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003369 }
3370 close OUT;
3371 run_command "mv $temp_config $ignore_config" or
3372 dodie "failed to copy update to $ignore_config";
3373 }
3374
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003375 } else {
3376 # We booted without this config, remove it from the minconfigs.
3377 doprint "$config is not needed, disabling\n";
3378
3379 delete $min_configs{$config};
3380
3381 # Also disable anything that is not enabled in this config
3382 my %configs;
3383 assign_configs \%configs, $output_config;
3384 my @config_keys = keys %min_configs;
3385 foreach my $config (@config_keys) {
3386 if (!defined($configs{$config})) {
3387 doprint "$config is not set, disabling\n";
3388 delete $min_configs{$config};
3389 }
3390 }
3391
3392 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003393 open (OUT, ">$temp_config")
3394 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003395 foreach my $config (keys %keep_configs) {
3396 print OUT "$keep_configs{$config}\n";
3397 }
3398 foreach my $config (keys %min_configs) {
3399 print OUT "$min_configs{$config}\n";
3400 }
3401 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003402
3403 run_command "mv $temp_config $output_minconfig" or
3404 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003405 }
3406
3407 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003408 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003409 }
3410
3411 success $i;
3412 return 1;
3413}
3414
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003415$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003416
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003417if ($#ARGV == 0) {
3418 $ktest_config = $ARGV[0];
3419 if (! -f $ktest_config) {
3420 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003421 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003422 exit 0;
3423 }
3424 }
3425} else {
3426 $ktest_config = "ktest.conf";
3427}
3428
3429if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003430 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003431 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003432 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3433 print OUT << "EOF"
3434# Generated by ktest.pl
3435#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003436
3437# PWD is a ktest.pl variable that will result in the process working
3438# directory that ktest.pl is executed in.
3439
3440# THIS_DIR is automatically assigned the PWD of the path that generated
3441# the config file. It is best to use this variable when assigning other
3442# directory paths within this directory. This allows you to easily
3443# move the test cases to other locations or to other machines.
3444#
3445THIS_DIR := $variable{"PWD"}
3446
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003447# Define each test with TEST_START
3448# The config options below it will override the defaults
3449TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003450TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003451
3452DEFAULTS
3453EOF
3454;
3455 close(OUT);
3456}
3457read_config $ktest_config;
3458
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003459if (defined($opt{"LOG_FILE"})) {
3460 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3461}
3462
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003463# Append any configs entered in manually to the config file.
3464my @new_configs = keys %entered_configs;
3465if ($#new_configs >= 0) {
3466 print "\nAppending entered in configs to $ktest_config\n";
3467 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3468 foreach my $config (@new_configs) {
3469 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003470 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003471 }
3472}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003473
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003474if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3475 unlink $opt{"LOG_FILE"};
3476}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003477
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003478doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3479
Steven Rostedta57419b2010-11-02 15:13:54 -04003480for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3481
3482 if (!$i) {
3483 doprint "DEFAULT OPTIONS:\n";
3484 } else {
3485 doprint "\nTEST $i OPTIONS";
3486 if (defined($repeat_tests{$i})) {
3487 $repeat = $repeat_tests{$i};
3488 doprint " ITERATE $repeat";
3489 }
3490 doprint "\n";
3491 }
3492
3493 foreach my $option (sort keys %opt) {
3494
3495 if ($option =~ /\[(\d+)\]$/) {
3496 next if ($i != $1);
3497 } else {
3498 next if ($i);
3499 }
3500
3501 doprint "$option = $opt{$option}\n";
3502 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003503}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003504
Steven Rostedt2a625122011-05-20 15:48:59 -04003505sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003506 my ($name, $i) = @_;
3507
3508 my $option = "$name\[$i\]";
3509
3510 if (defined($opt{$option})) {
3511 return $opt{$option};
3512 }
3513
Steven Rostedta57419b2010-11-02 15:13:54 -04003514 foreach my $test (keys %repeat_tests) {
3515 if ($i >= $test &&
3516 $i < $test + $repeat_tests{$test}) {
3517 $option = "$name\[$test\]";
3518 if (defined($opt{$option})) {
3519 return $opt{$option};
3520 }
3521 }
3522 }
3523
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003524 if (defined($opt{$name})) {
3525 return $opt{$name};
3526 }
3527
3528 return undef;
3529}
3530
Steven Rostedt2a625122011-05-20 15:48:59 -04003531sub set_test_option {
3532 my ($name, $i) = @_;
3533
3534 my $option = __set_test_option($name, $i);
3535 return $option if (!defined($option));
3536
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003537 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003538}
3539
Steven Rostedt2545eb62010-11-02 15:01:32 -04003540# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003541for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003542
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003543 # Do not reboot on failing test options
3544 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003545 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003546
Steven Rostedt683a3e62012-05-18 13:34:35 -04003547 $have_version = 0;
3548
Steven Rostedt576f6272010-11-02 14:58:38 -04003549 $iteration = $i;
3550
Steven Rostedta75fece2010-11-02 14:58:27 -04003551 my $makecmd = set_test_option("MAKE_CMD", $i);
3552
Steven Rostedt9cc9e092011-12-22 21:37:22 -05003553 # Load all the options into their mapped variable names
3554 foreach my $opt (keys %option_map) {
3555 ${$option_map{$opt}} = set_test_option($opt, $i);
3556 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003557
Steven Rostedt35ce5952011-07-15 21:57:25 -04003558 $start_minconfig_defined = 1;
3559
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003560 # The first test may override the PRE_KTEST option
3561 if (defined($pre_ktest) && $i == 1) {
3562 doprint "\n";
3563 run_command $pre_ktest;
3564 }
3565
3566 # Any test can override the POST_KTEST option
3567 # The last test takes precedence.
3568 if (defined($post_ktest)) {
3569 $final_post_ktest = $post_ktest;
3570 }
3571
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003572 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003573 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003574 $start_minconfig = $minconfig;
3575 }
3576
Steven Rostedta75fece2010-11-02 14:58:27 -04003577 chdir $builddir || die "can't change directory to $builddir";
3578
Andrew Jonesa908a662011-08-12 15:32:03 +02003579 foreach my $dir ($tmpdir, $outputdir) {
3580 if (!-d $dir) {
3581 mkpath($dir) or
3582 die "can't create $dir";
3583 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003584 }
3585
Steven Rostedte48c5292010-11-02 14:35:37 -04003586 $ENV{"SSH_USER"} = $ssh_user;
3587 $ENV{"MACHINE"} = $machine;
3588
Steven Rostedta75fece2010-11-02 14:58:27 -04003589 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303590 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003591 $dmesg = "$tmpdir/dmesg-$machine";
3592 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003593 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003594
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003595 if (!$buildonly) {
3596 $target = "$ssh_user\@$machine";
3597 if ($reboot_type eq "grub") {
3598 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003599 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003600 }
3601
3602 my $run_type = $build_type;
3603 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003604 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003605 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003606 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003607 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003608 $run_type = $config_bisect_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003609 }
3610
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003611 if ($test_type eq "make_min_config") {
3612 $run_type = "";
3613 }
3614
Steven Rostedta75fece2010-11-02 14:58:27 -04003615 # mistake in config file?
3616 if (!defined($run_type)) {
3617 $run_type = "ERROR";
3618 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003619
Steven Rostedte0a87422011-09-30 17:50:48 -04003620 my $installme = "";
3621 $installme = " no_install" if ($no_install);
3622
Steven Rostedt2545eb62010-11-02 15:01:32 -04003623 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003624 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003625
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003626 if (defined($pre_test)) {
3627 run_command $pre_test;
3628 }
3629
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003630 unlink $dmesg;
3631 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303632 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003633
Steven Rostedt250bae82011-07-15 22:05:59 -04003634 if (defined($addconfig)) {
3635 my $min = $minconfig;
3636 if (!defined($minconfig)) {
3637 $min = "";
3638 }
3639 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003640 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003641 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003642 }
3643
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003644 if (defined($checkout)) {
3645 run_command "git checkout $checkout" or
3646 die "failed to checkout $checkout";
3647 }
3648
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003649 $no_reboot = 0;
3650
Steven Rostedt648a1822012-03-21 11:18:27 -04003651 # A test may opt to not reboot the box
3652 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003653 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04003654 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003655
Steven Rostedta75fece2010-11-02 14:58:27 -04003656 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003657 bisect $i;
3658 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003659 } elsif ($test_type eq "config_bisect") {
3660 config_bisect $i;
3661 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003662 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003663 patchcheck $i;
3664 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003665 } elsif ($test_type eq "make_min_config") {
3666 make_min_config $i;
3667 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003668 }
3669
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003670 if ($build_type ne "nobuild") {
3671 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003672 }
3673
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003674 if ($test_type eq "install") {
3675 get_version;
3676 install;
3677 success $i;
3678 next;
3679 }
3680
Steven Rostedta75fece2010-11-02 14:58:27 -04003681 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003682 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003683 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003684
3685 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3686 do_run_test or $failed = 1;
3687 }
3688 end_monitor;
3689 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003690 }
3691
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003692 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003693}
3694
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003695if (defined($final_post_ktest)) {
3696 run_command $final_post_ktest;
3697}
3698
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003699if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003700 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003701} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003702 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04003703} elsif (defined($switch_to_good)) {
3704 # still need to get to the good kernel
3705 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003706}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003707
Steven Rostedt648a1822012-03-21 11:18:27 -04003708
Steven Rostedte48c5292010-11-02 14:35:37 -04003709doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3710
Steven Rostedt2545eb62010-11-02 15:01:32 -04003711exit 0;