blob: e91702eee580aabfbe69cbb9781f1de4b726e64d [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;
176
177my $patchcheck_type;
178my $patchcheck_start;
179my $patchcheck_end;
180
Steven Rostedt165708b2011-11-26 20:56:52 -0500181# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500182# which would require more options.
183my $buildonly = 1;
184
Steven Rostedtdbd37832011-11-23 16:00:48 -0500185# set when creating a new config
186my $newconfig = 0;
187
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500188my %entered_configs;
189my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400190my %variable;
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400191my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500192
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400193# do not force reboots on config problems
194my $no_reboot = 1;
195
Steven Rostedt759a3cc2012-05-01 08:20:12 -0400196# reboot on success
197my $reboot_success = 0;
198
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500199my %option_map = (
200 "MACHINE" => \$machine,
201 "SSH_USER" => \$ssh_user,
202 "TMP_DIR" => \$tmpdir,
203 "OUTPUT_DIR" => \$outputdir,
204 "BUILD_DIR" => \$builddir,
205 "TEST_TYPE" => \$test_type,
Steven Rostedt921ed4c2012-07-19 15:18:27 -0400206 "PRE_KTEST" => \$pre_ktest,
207 "POST_KTEST" => \$post_ktest,
208 "PRE_TEST" => \$pre_test,
209 "POST_TEST" => \$post_test,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500210 "BUILD_TYPE" => \$build_type,
211 "BUILD_OPTIONS" => \$build_options,
212 "PRE_BUILD" => \$pre_build,
213 "POST_BUILD" => \$post_build,
214 "PRE_BUILD_DIE" => \$pre_build_die,
215 "POST_BUILD_DIE" => \$post_build_die,
216 "POWER_CYCLE" => \$power_cycle,
217 "REBOOT" => \$reboot,
218 "BUILD_NOCLEAN" => \$noclean,
219 "MIN_CONFIG" => \$minconfig,
220 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
221 "START_MIN_CONFIG" => \$start_minconfig,
Steven Rostedtccc513b2012-05-21 17:13:40 -0400222 "MIN_CONFIG_TYPE" => \$minconfig_type,
Steven Rostedt43de3312012-05-21 23:35:12 -0400223 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500224 "IGNORE_CONFIG" => \$ignore_config,
225 "TEST" => \$run_test,
226 "ADD_CONFIG" => \$addconfig,
227 "REBOOT_TYPE" => \$reboot_type,
228 "GRUB_MENU" => \$grub_menu,
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400229 "PRE_INSTALL" => \$pre_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500230 "POST_INSTALL" => \$post_install,
231 "NO_INSTALL" => \$no_install,
232 "REBOOT_SCRIPT" => \$reboot_script,
233 "REBOOT_ON_ERROR" => \$reboot_on_error,
234 "SWITCH_TO_GOOD" => \$switch_to_good,
235 "SWITCH_TO_TEST" => \$switch_to_test,
236 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
Steven Rostedt648a1822012-03-21 11:18:27 -0400237 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500238 "DIE_ON_FAILURE" => \$die_on_failure,
239 "POWER_OFF" => \$power_off,
240 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
241 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
242 "SLEEP_TIME" => \$sleep_time,
243 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
244 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
245 "IGNORE_WARNINGS" => \$ignore_warnings,
Steven Rostedtbe405f92012-01-04 21:51:59 -0500246 "IGNORE_ERRORS" => \$ignore_errors,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500247 "BISECT_MANUAL" => \$bisect_manual,
248 "BISECT_SKIP" => \$bisect_skip,
249 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
250 "BISECT_RET_GOOD" => \$bisect_ret_good,
251 "BISECT_RET_BAD" => \$bisect_ret_bad,
252 "BISECT_RET_SKIP" => \$bisect_ret_skip,
253 "BISECT_RET_ABORT" => \$bisect_ret_abort,
254 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
255 "STORE_FAILURES" => \$store_failures,
256 "STORE_SUCCESSES" => \$store_successes,
257 "TEST_NAME" => \$test_name,
258 "TIMEOUT" => \$timeout,
259 "BOOTED_TIMEOUT" => \$booted_timeout,
260 "CONSOLE" => \$console,
261 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
262 "SUCCESS_LINE" => \$success_line,
263 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
264 "STOP_AFTER_SUCCESS" => \$stop_after_success,
265 "STOP_AFTER_FAILURE" => \$stop_after_failure,
266 "STOP_TEST_AFTER" => \$stop_test_after,
267 "BUILD_TARGET" => \$build_target,
268 "SSH_EXEC" => \$ssh_exec,
269 "SCP_TO_TARGET" => \$scp_to_target,
Steven Rostedt02ad2612012-03-21 08:21:24 -0400270 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500271 "CHECKOUT" => \$checkout,
272 "TARGET_IMAGE" => \$target_image,
273 "LOCALVERSION" => \$localversion,
274
275 "BISECT_GOOD" => \$bisect_good,
276 "BISECT_BAD" => \$bisect_bad,
277 "BISECT_TYPE" => \$bisect_type,
278 "BISECT_START" => \$bisect_start,
279 "BISECT_REPLAY" => \$bisect_replay,
280 "BISECT_FILES" => \$bisect_files,
281 "BISECT_REVERSE" => \$bisect_reverse,
282 "BISECT_CHECK" => \$bisect_check,
283
284 "CONFIG_BISECT" => \$config_bisect,
285 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
286
287 "PATCHCHECK_TYPE" => \$patchcheck_type,
288 "PATCHCHECK_START" => \$patchcheck_start,
289 "PATCHCHECK_END" => \$patchcheck_end,
290);
291
292# Options may be used by other options, record them.
293my %used_options;
294
Steven Rostedt7bf51072011-10-22 09:07:03 -0400295# default variables that can be used
296chomp ($variable{"PWD"} = `pwd`);
297
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500298$config_help{"MACHINE"} = << "EOF"
299 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500300 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500301EOF
302 ;
303$config_help{"SSH_USER"} = << "EOF"
304 The box is expected to have ssh on normal bootup, provide the user
305 (most likely root, since you need privileged operations)
306EOF
307 ;
308$config_help{"BUILD_DIR"} = << "EOF"
309 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500310 You can use \${PWD} that will be the path where ktest.pl is run, or use
311 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500312EOF
313 ;
314$config_help{"OUTPUT_DIR"} = << "EOF"
315 The directory that the objects will be built (full path).
316 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500317 You can use \${PWD} that will be the path where ktest.pl is run, or use
318 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500319EOF
320 ;
321$config_help{"BUILD_TARGET"} = << "EOF"
322 The location of the compiled file to copy to the target.
323 (relative to OUTPUT_DIR)
324EOF
325 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500326$config_help{"BUILD_OPTIONS"} = << "EOF"
327 Options to add to \"make\" when building.
328 i.e. -j20
329EOF
330 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500331$config_help{"TARGET_IMAGE"} = << "EOF"
332 The place to put your image on the test machine.
333EOF
334 ;
335$config_help{"POWER_CYCLE"} = << "EOF"
336 A script or command to reboot the box.
337
338 Here is a digital loggers power switch example
339 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
340
341 Here is an example to reboot a virtual box on the current host
342 with the name "Guest".
343 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
344EOF
345 ;
346$config_help{"CONSOLE"} = << "EOF"
347 The script or command that reads the console
348
349 If you use ttywatch server, something like the following would work.
350CONSOLE = nc -d localhost 3001
351
352 For a virtual machine with guest name "Guest".
353CONSOLE = virsh console Guest
354EOF
355 ;
356$config_help{"LOCALVERSION"} = << "EOF"
357 Required version ending to differentiate the test
358 from other linux builds on the system.
359EOF
360 ;
361$config_help{"REBOOT_TYPE"} = << "EOF"
362 Way to reboot the box to the test kernel.
363 Only valid options so far are "grub" and "script".
364
365 If you specify grub, it will assume grub version 1
366 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
367 and select that target to reboot to the kernel. If this is not
368 your setup, then specify "script" and have a command or script
369 specified in REBOOT_SCRIPT to boot to the target.
370
371 The entry in /boot/grub/menu.lst must be entered in manually.
372 The test will not modify that file.
373EOF
374 ;
375$config_help{"GRUB_MENU"} = << "EOF"
376 The grub title name for the test kernel to boot
377 (Only mandatory if REBOOT_TYPE = grub)
378
379 Note, ktest.pl will not update the grub menu.lst, you need to
380 manually add an option for the test. ktest.pl will search
381 the grub menu.lst for this option to find what kernel to
382 reboot into.
383
384 For example, if in the /boot/grub/menu.lst the test kernel title has:
385 title Test Kernel
386 kernel vmlinuz-test
387 GRUB_MENU = Test Kernel
388EOF
389 ;
390$config_help{"REBOOT_SCRIPT"} = << "EOF"
391 A script to reboot the target into the test kernel
392 (Only mandatory if REBOOT_TYPE = script)
393EOF
394 ;
395
Steven Rostedtdad98752011-11-22 20:48:57 -0500396sub read_prompt {
397 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400398
399 my $ans;
400
401 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500402 if ($cancel) {
403 print "$prompt [y/n/C] ";
404 } else {
405 print "$prompt [Y/n] ";
406 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400407 $ans = <STDIN>;
408 chomp $ans;
409 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500410 if ($cancel) {
411 $ans = "c";
412 } else {
413 $ans = "y";
414 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400415 }
416 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500417 if ($cancel) {
418 last if ($ans =~ /^c$/i);
419 print "Please answer either 'y', 'n' or 'c'.\n";
420 } else {
421 print "Please answer either 'y' or 'n'.\n";
422 }
423 }
424 if ($ans =~ /^c/i) {
425 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400426 }
427 if ($ans !~ /^y$/i) {
428 return 0;
429 }
430 return 1;
431}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500432
Steven Rostedtdad98752011-11-22 20:48:57 -0500433sub read_yn {
434 my ($prompt) = @_;
435
436 return read_prompt 0, $prompt;
437}
438
439sub read_ync {
440 my ($prompt) = @_;
441
442 return read_prompt 1, $prompt;
443}
444
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500445sub get_ktest_config {
446 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400447 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500448
449 return if (defined($opt{$config}));
450
451 if (defined($config_help{$config})) {
452 print "\n";
453 print $config_help{$config};
454 }
455
456 for (;;) {
457 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500458 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500459 print "\[$default{$config}\] ";
460 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400461 $ans = <STDIN>;
462 $ans =~ s/^\s*(.*\S)\s*$/$1/;
463 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500464 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400465 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500466 } else {
467 print "Your answer can not be blank\n";
468 next;
469 }
470 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500471 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500472 last;
473 }
474}
475
476sub get_ktest_configs {
477 get_ktest_config("MACHINE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500478 get_ktest_config("BUILD_DIR");
479 get_ktest_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500480
Steven Rostedtdbd37832011-11-23 16:00:48 -0500481 if ($newconfig) {
482 get_ktest_config("BUILD_OPTIONS");
483 }
484
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500485 # options required for other than just building a kernel
486 if (!$buildonly) {
Steven Rostedt165708b2011-11-26 20:56:52 -0500487 get_ktest_config("POWER_CYCLE");
488 get_ktest_config("CONSOLE");
489 }
490
491 # options required for install and more
492 if ($buildonly != 1) {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500493 get_ktest_config("SSH_USER");
494 get_ktest_config("BUILD_TARGET");
495 get_ktest_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500496 }
497
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500498 get_ktest_config("LOCALVERSION");
499
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500500 return if ($buildonly);
501
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500502 my $rtype = $opt{"REBOOT_TYPE"};
503
504 if (!defined($rtype)) {
505 if (!defined($opt{"GRUB_MENU"})) {
506 get_ktest_config("REBOOT_TYPE");
507 $rtype = $entered_configs{"REBOOT_TYPE"};
508 } else {
509 $rtype = "grub";
510 }
511 }
512
513 if ($rtype eq "grub") {
514 get_ktest_config("GRUB_MENU");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500515 }
516}
517
Steven Rostedt77d942c2011-05-20 13:36:58 -0400518sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400519 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400520 my $retval = "";
521
522 # We want to check for '\', and it is just easier
523 # to check the previous characet of '$' and not need
524 # to worry if '$' is the first character. By adding
525 # a space to $value, we can just check [^\\]\$ and
526 # it will still work.
527 $value = " $value";
528
529 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
530 my $begin = $1;
531 my $var = $2;
532 my $end = $3;
533 # append beginning of value to retval
534 $retval = "$retval$begin";
535 if (defined($variable{$var})) {
536 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400537 } elsif (defined($remove_undef) && $remove_undef) {
538 # for if statements, any variable that is not defined,
539 # we simple convert to 0
540 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400541 } else {
542 # put back the origin piece.
543 $retval = "$retval\$\{$var\}";
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500544 # This could be an option that is used later, save
545 # it so we don't warn if this option is not one of
546 # ktests options.
547 $used_options{$var} = 1;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400548 }
549 $value = $end;
550 }
551 $retval = "$retval$value";
552
553 # remove the space added in the beginning
554 $retval =~ s/ //;
555
556 return "$retval"
557}
558
Steven Rostedta57419b2010-11-02 15:13:54 -0400559sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400560 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400561
Steven Rostedtcad96662011-12-22 11:32:52 -0500562 my $prvalue = process_variables($rvalue);
563
564 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500565 # Note if a test is something other than build, then we
566 # will need other manditory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500567 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500568 $buildonly = 0;
569 } else {
570 # install still limits some manditory options.
571 $buildonly = 2;
572 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500573 }
574
Steven Rostedta57419b2010-11-02 15:13:54 -0400575 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400576 if (!$override || defined(${$overrides}{$lvalue})) {
577 my $extra = "";
578 if ($override) {
579 $extra = "In the same override section!\n";
580 }
581 die "$name: $.: Option $lvalue defined more than once!\n$extra";
582 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500583 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400584 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500585 if ($rvalue =~ /^\s*$/) {
586 delete $opt{$lvalue};
587 } else {
Steven Rostedtcad96662011-12-22 11:32:52 -0500588 $opt{$lvalue} = $prvalue;
Steven Rostedt21a96792010-11-08 16:45:50 -0500589 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400590}
591
Steven Rostedt77d942c2011-05-20 13:36:58 -0400592sub set_variable {
593 my ($lvalue, $rvalue) = @_;
594
595 if ($rvalue =~ /^\s*$/) {
596 delete $variable{$lvalue};
597 } else {
598 $rvalue = process_variables($rvalue);
599 $variable{$lvalue} = $rvalue;
600 }
601}
602
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400603sub process_compare {
604 my ($lval, $cmp, $rval) = @_;
605
606 # remove whitespace
607
608 $lval =~ s/^\s*//;
609 $lval =~ s/\s*$//;
610
611 $rval =~ s/^\s*//;
612 $rval =~ s/\s*$//;
613
614 if ($cmp eq "==") {
615 return $lval eq $rval;
616 } elsif ($cmp eq "!=") {
617 return $lval ne $rval;
618 }
619
620 my $statement = "$lval $cmp $rval";
621 my $ret = eval $statement;
622
623 # $@ stores error of eval
624 if ($@) {
625 return -1;
626 }
627
628 return $ret;
629}
630
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400631sub value_defined {
632 my ($val) = @_;
633
634 return defined($variable{$2}) ||
635 defined($opt{$2});
636}
637
Steven Rostedt8d735212011-10-17 11:36:44 -0400638my $d = 0;
639sub process_expression {
640 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400641
Steven Rostedt8d735212011-10-17 11:36:44 -0400642 my $c = $d++;
643
644 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
645 my $express = $1;
646
647 if (process_expression($name, $express)) {
648 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
649 } else {
650 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
651 }
652 }
653
654 $d--;
655 my $OR = "\\|\\|";
656 my $AND = "\\&\\&";
657
658 while ($val =~ s/^(.*?)($OR|$AND)//) {
659 my $express = $1;
660 my $op = $2;
661
662 if (process_expression($name, $express)) {
663 if ($op eq "||") {
664 return 1;
665 }
666 } else {
667 if ($op eq "&&") {
668 return 0;
669 }
670 }
671 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400672
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400673 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
674 my $ret = process_compare($1, $2, $3);
675 if ($ret < 0) {
676 die "$name: $.: Unable to process comparison\n";
677 }
678 return $ret;
679 }
680
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400681 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
682 if (defined $1) {
683 return !value_defined($2);
684 } else {
685 return value_defined($2);
686 }
687 }
688
Steven Rostedt45d73a52011-09-30 19:44:53 -0400689 if ($val =~ /^\s*0\s*$/) {
690 return 0;
691 } elsif ($val =~ /^\s*\d+\s*$/) {
692 return 1;
693 }
694
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400695 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400696}
697
698sub process_if {
699 my ($name, $value) = @_;
700
701 # Convert variables and replace undefined ones with 0
702 my $val = process_variables($value, 1);
703 my $ret = process_expression $name, $val;
704
705 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400706}
707
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400708sub __read_config {
709 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400710
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400711 my $in;
712 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400713
Steven Rostedta57419b2010-11-02 15:13:54 -0400714 my $name = $config;
715 $name =~ s,.*/(.*),$1,;
716
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400717 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400718 my $default = 1;
719 my $repeat = 1;
720 my $num_tests_set = 0;
721 my $skip = 0;
722 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400723 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400724 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400725 my $if = 0;
726 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400727 my $override = 0;
728
729 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400730
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400731 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400732
733 # ignore blank lines and comments
734 next if (/^\s*$/ || /\s*\#/);
735
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400736 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400737
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400738 my $type = $1;
739 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400740 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400741
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400742 my $old_test_num;
743 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400744 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400745
746 if ($type eq "TEST_START") {
747
748 if ($num_tests_set) {
749 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
750 }
751
752 $old_test_num = $test_num;
753 $old_repeat = $repeat;
754
755 $test_num += $repeat;
756 $default = 0;
757 $repeat = 1;
758 } else {
759 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400760 }
761
Steven Rostedta9f84422011-10-17 11:06:29 -0400762 # If SKIP is anywhere in the line, the command will be skipped
763 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400764 $skip = 1;
765 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400766 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400767 $skip = 0;
768 }
769
Steven Rostedta9f84422011-10-17 11:06:29 -0400770 if ($rest =~ s/\sELSE\b//) {
771 if (!$if) {
772 die "$name: $.: ELSE found with out matching IF section\n$_";
773 }
774 $if = 0;
775
776 if ($if_set) {
777 $skip = 1;
778 } else {
779 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400780 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400781 }
782
Steven Rostedta9f84422011-10-17 11:06:29 -0400783 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400784 if (process_if($name, $1)) {
785 $if_set = 1;
786 } else {
787 $skip = 1;
788 }
789 $if = 1;
790 } else {
791 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400792 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400793 }
794
Steven Rostedta9f84422011-10-17 11:06:29 -0400795 if (!$skip) {
796 if ($type eq "TEST_START") {
797 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
798 $repeat = $1;
799 $repeat_tests{"$test_num"} = $repeat;
800 }
801 } elsif ($rest =~ s/\sOVERRIDE\b//) {
802 # DEFAULT only
803 $override = 1;
804 # Clear previous overrides
805 %overrides = ();
806 }
807 }
808
809 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400810 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400811 }
812
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400813 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400814 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400815 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400816 }
817
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400818 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400819 if (!$if) {
820 die "$name: $.: ELSE found with out matching IF section\n$_";
821 }
822 $rest = $1;
823 if ($if_set) {
824 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400825 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400826 } else {
827 $skip = 0;
828
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400829 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400830 # May be a ELSE IF section.
831 if (!process_if($name, $1)) {
832 $skip = 1;
833 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400834 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400835 } else {
836 $if = 0;
837 }
838 }
839
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400840 if ($rest !~ /^\s*$/) {
841 die "$name: $.: Gargbage found after DEFAULTS\n$_";
842 }
843
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400844 } elsif (/^\s*INCLUDE\s+(\S+)/) {
845
846 next if ($skip);
847
848 if (!$default) {
849 die "$name: $.: INCLUDE can only be done in default sections\n$_";
850 }
851
852 my $file = process_variables($1);
853
854 if ($file !~ m,^/,) {
855 # check the path of the config file first
856 if ($config =~ m,(.*)/,) {
857 if (-f "$1/$file") {
858 $file = "$1/$file";
859 }
860 }
861 }
862
863 if ( ! -r $file ) {
864 die "$name: $.: Can't read file $file\n$_";
865 }
866
867 if (__read_config($file, \$test_num)) {
868 $test_case = 1;
869 }
870
Steven Rostedta57419b2010-11-02 15:13:54 -0400871 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
872
873 next if ($skip);
874
Steven Rostedt2545eb62010-11-02 15:01:32 -0400875 my $lvalue = $1;
876 my $rvalue = $2;
877
Steven Rostedta57419b2010-11-02 15:13:54 -0400878 if (!$default &&
879 ($lvalue eq "NUM_TESTS" ||
880 $lvalue eq "LOG_FILE" ||
881 $lvalue eq "CLEAR_LOG")) {
882 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400883 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400884
885 if ($lvalue eq "NUM_TESTS") {
886 if ($test_num) {
887 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
888 }
889 if (!$default) {
890 die "$name: $.: NUM_TESTS must be set in default section\n";
891 }
892 $num_tests_set = 1;
893 }
894
895 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400896 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400897 } else {
898 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400899 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400900
901 if ($repeat > 1) {
902 $repeats{$val} = $repeat;
903 }
904 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400905 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
906 next if ($skip);
907
908 my $lvalue = $1;
909 my $rvalue = $2;
910
911 # process config variables.
912 # Config variables are only active while reading the
913 # config and can be defined anywhere. They also ignore
914 # TEST_START and DEFAULTS, but are skipped if they are in
915 # on of these sections that have SKIP defined.
916 # The save variable can be
917 # defined multiple times and the new one simply overrides
918 # the prevous one.
919 set_variable($lvalue, $rvalue);
920
Steven Rostedta57419b2010-11-02 15:13:54 -0400921 } else {
922 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400923 }
924 }
925
Steven Rostedta57419b2010-11-02 15:13:54 -0400926 if ($test_num) {
927 $test_num += $repeat - 1;
928 $opt{"NUM_TESTS"} = $test_num;
929 }
930
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400931 close($in);
932
933 $$current_test_num = $test_num;
934
935 return $test_case;
936}
937
Steven Rostedtc4261d02011-11-23 13:41:18 -0500938sub get_test_case {
939 print "What test case would you like to run?\n";
940 print " (build, install or boot)\n";
941 print " Other tests are available but require editing the config file\n";
942 my $ans = <STDIN>;
943 chomp $ans;
944 $default{"TEST_TYPE"} = $ans;
945}
946
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400947sub read_config {
948 my ($config) = @_;
949
950 my $test_case;
951 my $test_num = 0;
952
953 $test_case = __read_config $config, \$test_num;
954
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500955 # make sure we have all mandatory configs
956 get_ktest_configs;
957
Steven Rostedt0df213c2011-06-14 20:51:37 -0400958 # was a test specified?
959 if (!$test_case) {
960 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -0500961 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400962 }
963
Steven Rostedta75fece2010-11-02 14:58:27 -0400964 # set any defaults
965
966 foreach my $default (keys %default) {
967 if (!defined($opt{$default})) {
968 $opt{$default} = $default{$default};
969 }
970 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500971
972 if ($opt{"IGNORE_UNUSED"} == 1) {
973 return;
974 }
975
976 my %not_used;
977
978 # check if there are any stragglers (typos?)
979 foreach my $option (keys %opt) {
980 my $op = $option;
981 # remove per test labels.
982 $op =~ s/\[.*\]//;
983 if (!exists($option_map{$op}) &&
984 !exists($default{$op}) &&
985 !exists($used_options{$op})) {
986 $not_used{$op} = 1;
987 }
988 }
989
990 if (%not_used) {
991 my $s = "s are";
992 $s = " is" if (keys %not_used == 1);
993 print "The following option$s not used; could be a typo:\n";
994 foreach my $option (keys %not_used) {
995 print "$option\n";
996 }
997 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
998 if (!read_yn "Do you want to continue?") {
999 exit -1;
1000 }
1001 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001002}
1003
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001004sub __eval_option {
1005 my ($option, $i) = @_;
1006
1007 # Add space to evaluate the character before $
1008 $option = " $option";
1009 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301010 my $repeated = 0;
1011 my $parent = 0;
1012
1013 foreach my $test (keys %repeat_tests) {
1014 if ($i >= $test &&
1015 $i < $test + $repeat_tests{$test}) {
1016
1017 $repeated = 1;
1018 $parent = $test;
1019 last;
1020 }
1021 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001022
1023 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1024 my $start = $1;
1025 my $var = $2;
1026 my $end = $3;
1027
1028 # Append beginning of line
1029 $retval = "$retval$start";
1030
1031 # If the iteration option OPT[$i] exists, then use that.
1032 # otherwise see if the default OPT (without [$i]) exists.
1033
1034 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301035 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001036
1037 if (defined($opt{$o})) {
1038 $o = $opt{$o};
1039 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301040 } elsif ($repeated && defined($opt{$parento})) {
1041 $o = $opt{$parento};
1042 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001043 } elsif (defined($opt{$var})) {
1044 $o = $opt{$var};
1045 $retval = "$retval$o";
1046 } else {
1047 $retval = "$retval\$\{$var\}";
1048 }
1049
1050 $option = $end;
1051 }
1052
1053 $retval = "$retval$option";
1054
1055 $retval =~ s/^ //;
1056
1057 return $retval;
1058}
1059
1060sub eval_option {
1061 my ($option, $i) = @_;
1062
1063 my $prev = "";
1064
1065 # Since an option can evaluate to another option,
1066 # keep iterating until we do not evaluate any more
1067 # options.
1068 my $r = 0;
1069 while ($prev ne $option) {
1070 # Check for recursive evaluations.
1071 # 100 deep should be more than enough.
1072 if ($r++ > 100) {
1073 die "Over 100 evaluations accurred with $option\n" .
1074 "Check for recursive variables\n";
1075 }
1076 $prev = $option;
1077 $option = __eval_option($option, $i);
1078 }
1079
1080 return $option;
1081}
1082
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001083sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001084 if (defined($opt{"LOG_FILE"})) {
1085 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1086 print OUT @_;
1087 close(OUT);
1088 }
1089}
1090
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001091sub logit {
1092 if (defined($opt{"LOG_FILE"})) {
1093 _logit @_;
1094 } else {
1095 print @_;
1096 }
1097}
1098
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001099sub doprint {
1100 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001101 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001102}
1103
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001104sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001105sub start_monitor;
1106sub end_monitor;
1107sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001108
1109sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001110 my ($time) = @_;
1111
Steven Rostedt2b803362011-09-30 18:00:23 -04001112 if (defined($time)) {
1113 start_monitor;
1114 # flush out current monitor
1115 # May contain the reboot success line
1116 wait_for_monitor 1;
1117 }
1118
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001119 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001120 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001121 if (defined($powercycle_after_reboot)) {
1122 sleep $powercycle_after_reboot;
1123 run_command "$power_cycle";
1124 }
1125 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001126 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001127 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001128 }
Andrew Jones2728be42011-08-12 15:32:05 +02001129
1130 if (defined($time)) {
Steven Rostedt2b803362011-09-30 18:00:23 -04001131 wait_for_monitor($time, $reboot_success_line);
Andrew Jones2728be42011-08-12 15:32:05 +02001132 end_monitor;
1133 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001134}
1135
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001136sub reboot_to_good {
1137 my ($time) = @_;
1138
1139 if (defined($switch_to_good)) {
1140 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001141 }
1142
1143 reboot $time;
1144}
1145
Steven Rostedt576f6272010-11-02 14:58:38 -04001146sub do_not_reboot {
1147 my $i = $iteration;
1148
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001149 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001150 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1151 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1152}
1153
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001154sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001155 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001156
Steven Rostedt576f6272010-11-02 14:58:38 -04001157 my $i = $iteration;
1158
1159 if ($reboot_on_error && !do_not_reboot) {
1160
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001161 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001162 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001163
Steven Rostedta75fece2010-11-02 14:58:27 -04001164 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001165 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001166 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001167 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001168
Steven Rostedtf80802c2011-03-07 13:18:47 -05001169 if (defined($opt{"LOG_FILE"})) {
1170 print " See $opt{LOG_FILE} for more info.\n";
1171 }
1172
Steven Rostedt576f6272010-11-02 14:58:38 -04001173 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001174}
1175
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001176sub open_console {
1177 my ($fp) = @_;
1178
1179 my $flags;
1180
Steven Rostedta75fece2010-11-02 14:58:27 -04001181 my $pid = open($fp, "$console|") or
1182 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001183
1184 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001185 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001186 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001187 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001188
1189 return $pid;
1190}
1191
1192sub close_console {
1193 my ($fp, $pid) = @_;
1194
1195 doprint "kill child process $pid\n";
1196 kill 2, $pid;
1197
1198 print "closing!\n";
1199 close($fp);
1200}
1201
1202sub start_monitor {
1203 if ($monitor_cnt++) {
1204 return;
1205 }
1206 $monitor_fp = \*MONFD;
1207 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001208
1209 return;
1210
1211 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001212}
1213
1214sub end_monitor {
1215 if (--$monitor_cnt) {
1216 return;
1217 }
1218 close_console($monitor_fp, $monitor_pid);
1219}
1220
1221sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001222 my ($time, $stop) = @_;
1223 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001224 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001225 my $booted = 0;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001226
Steven Rostedta75fece2010-11-02 14:58:27 -04001227 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001228
1229 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001230 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001231 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001232 last if (!defined($line));
1233 print "$line";
1234 $full_line .= $line;
1235
1236 if (defined($stop) && $full_line =~ /$stop/) {
1237 doprint "wait for monitor detected $stop\n";
1238 $booted = 1;
1239 }
1240
1241 if ($line =~ /\n/) {
1242 $full_line = "";
1243 }
1244 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001245 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001246}
1247
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301248sub save_logs {
1249 my ($result, $basedir) = @_;
1250 my @t = localtime;
1251 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1252 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1253
1254 my $type = $build_type;
1255 if ($type =~ /useconfig/) {
1256 $type = "useconfig";
1257 }
1258
1259 my $dir = "$machine-$test_type-$type-$result-$date";
1260
1261 $dir = "$basedir/$dir";
1262
1263 if (!-d $dir) {
1264 mkpath($dir) or
1265 die "can't create $dir";
1266 }
1267
1268 my %files = (
1269 "config" => $output_config,
1270 "buildlog" => $buildlog,
1271 "dmesg" => $dmesg,
1272 "testlog" => $testlog,
1273 );
1274
1275 while (my ($name, $source) = each(%files)) {
1276 if (-f "$source") {
1277 cp "$source", "$dir/$name" or
1278 die "failed to copy $source";
1279 }
1280 }
1281
1282 doprint "*** Saved info to $dir ***\n";
1283}
1284
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001285sub fail {
1286
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001287 if (defined($post_test)) {
1288 run_command $post_test;
1289 }
1290
Steven Rostedta75fece2010-11-02 14:58:27 -04001291 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001292 dodie @_;
1293 }
1294
Steven Rostedta75fece2010-11-02 14:58:27 -04001295 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001296
Steven Rostedt576f6272010-11-02 14:58:38 -04001297 my $i = $iteration;
1298
Steven Rostedta75fece2010-11-02 14:58:27 -04001299 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001300 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001301 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001302 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001303 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001304
Steven Rostedt9064af52011-06-13 10:38:48 -04001305 my $name = "";
1306
1307 if (defined($test_name)) {
1308 $name = " ($test_name)";
1309 }
1310
Steven Rostedt576f6272010-11-02 14:58:38 -04001311 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1312 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001313 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001314 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1315 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001316
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301317 if (defined($store_failures)) {
1318 save_logs "fail", $store_failures;
1319 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001320
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001321 return 1;
1322}
1323
Steven Rostedt2545eb62010-11-02 15:01:32 -04001324sub run_command {
1325 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001326 my $dolog = 0;
1327 my $dord = 0;
1328 my $pid;
1329
Steven Rostedte48c5292010-11-02 14:35:37 -04001330 $command =~ s/\$SSH_USER/$ssh_user/g;
1331 $command =~ s/\$MACHINE/$machine/g;
1332
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001333 doprint("$command ... ");
1334
1335 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001336 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001337
1338 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001339 open(LOG, ">>$opt{LOG_FILE}") or
1340 dodie "failed to write to log";
1341 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001342 }
1343
1344 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001345 open (RD, ">$redirect") or
1346 dodie "failed to write to redirect $redirect";
1347 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001348 }
1349
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001350 while (<CMD>) {
1351 print LOG if ($dolog);
1352 print RD if ($dord);
1353 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001354
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001355 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001356 my $failed = $?;
1357
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001358 close(CMD);
1359 close(LOG) if ($dolog);
1360 close(RD) if ($dord);
1361
Steven Rostedt2545eb62010-11-02 15:01:32 -04001362 if ($failed) {
1363 doprint "FAILED!\n";
1364 } else {
1365 doprint "SUCCESS\n";
1366 }
1367
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001368 return !$failed;
1369}
1370
Steven Rostedte48c5292010-11-02 14:35:37 -04001371sub run_ssh {
1372 my ($cmd) = @_;
1373 my $cp_exec = $ssh_exec;
1374
1375 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1376 return run_command "$cp_exec";
1377}
1378
1379sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001380 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001381
1382 $cp_scp =~ s/\$SRC_FILE/$src/g;
1383 $cp_scp =~ s/\$DST_FILE/$dst/g;
1384
1385 return run_command "$cp_scp";
1386}
1387
Steven Rostedt02ad2612012-03-21 08:21:24 -04001388sub run_scp_install {
1389 my ($src, $dst) = @_;
1390
1391 my $cp_scp = $scp_to_target_install;
1392
1393 return run_scp($src, $dst, $cp_scp);
1394}
1395
1396sub run_scp_mod {
1397 my ($src, $dst) = @_;
1398
1399 my $cp_scp = $scp_to_target;
1400
1401 return run_scp($src, $dst, $cp_scp);
1402}
1403
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001404sub get_grub_index {
1405
Steven Rostedta75fece2010-11-02 14:58:27 -04001406 if ($reboot_type ne "grub") {
1407 return;
1408 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001409 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001410
1411 doprint "Find grub menu ... ";
1412 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001413
1414 my $ssh_grub = $ssh_exec;
1415 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1416
1417 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001418 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001419
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001420 my $found = 0;
1421
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001422 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001423 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001424 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001425 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001426 last;
1427 } elsif (/^\s*title\s/) {
1428 $grub_number++;
1429 }
1430 }
1431 close(IN);
1432
Steven Rostedta75fece2010-11-02 14:58:27 -04001433 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001434 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001435 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001436}
1437
Steven Rostedt2545eb62010-11-02 15:01:32 -04001438sub wait_for_input
1439{
1440 my ($fp, $time) = @_;
1441 my $rin;
1442 my $ready;
1443 my $line;
1444 my $ch;
1445
1446 if (!defined($time)) {
1447 $time = $timeout;
1448 }
1449
1450 $rin = '';
1451 vec($rin, fileno($fp), 1) = 1;
1452 $ready = select($rin, undef, undef, $time);
1453
1454 $line = "";
1455
1456 # try to read one char at a time
1457 while (sysread $fp, $ch, 1) {
1458 $line .= $ch;
1459 last if ($ch eq "\n");
1460 }
1461
1462 if (!length($line)) {
1463 return undef;
1464 }
1465
1466 return $line;
1467}
1468
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001469sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001470 if (defined($switch_to_test)) {
1471 run_command $switch_to_test;
1472 }
1473
Steven Rostedta75fece2010-11-02 14:58:27 -04001474 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001475 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001476 } elsif (defined $reboot_script) {
1477 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001478 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001479 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001480}
1481
Steven Rostedta57419b2010-11-02 15:13:54 -04001482sub get_sha1 {
1483 my ($commit) = @_;
1484
1485 doprint "git rev-list --max-count=1 $commit ... ";
1486 my $sha1 = `git rev-list --max-count=1 $commit`;
1487 my $ret = $?;
1488
1489 logit $sha1;
1490
1491 if ($ret) {
1492 doprint "FAILED\n";
1493 dodie "Failed to get git $commit";
1494 }
1495
1496 print "SUCCESS\n";
1497
1498 chomp $sha1;
1499
1500 return $sha1;
1501}
1502
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001503sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001504 my $booted = 0;
1505 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001506 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001507 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001508 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001509
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001510 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001511
1512 my $line;
1513 my $full_line = "";
1514
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001515 open(DMESG, "> $dmesg") or
1516 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001517
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001518 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001519
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001520 my $success_start;
1521 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001522 my $monitor_start = time;
1523 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001524 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001525
Steven Rostedt2d01b262011-03-08 09:47:54 -05001526 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001527
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001528 if ($bug && defined($stop_after_failure) &&
1529 $stop_after_failure >= 0) {
1530 my $time = $stop_after_failure - (time - $failure_start);
1531 $line = wait_for_input($monitor_fp, $time);
1532 if (!defined($line)) {
1533 doprint "bug timed out after $booted_timeout seconds\n";
1534 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1535 last;
1536 }
1537 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001538 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001539 if (!defined($line)) {
1540 my $s = $booted_timeout == 1 ? "" : "s";
1541 doprint "Successful boot found: break after $booted_timeout second$s\n";
1542 last;
1543 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001544 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001545 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001546 if (!defined($line)) {
1547 my $s = $timeout == 1 ? "" : "s";
1548 doprint "Timed out after $timeout second$s\n";
1549 last;
1550 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001551 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001552
Steven Rostedt2545eb62010-11-02 15:01:32 -04001553 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001554 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001555
1556 # we are not guaranteed to get a full line
1557 $full_line .= $line;
1558
Steven Rostedta75fece2010-11-02 14:58:27 -04001559 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001560 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001561 $success_start = time;
1562 }
1563
1564 if ($booted && defined($stop_after_success) &&
1565 $stop_after_success >= 0) {
1566 my $now = time;
1567 if ($now - $success_start >= $stop_after_success) {
1568 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1569 last;
1570 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001571 }
1572
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001573 if ($full_line =~ /\[ backtrace testing \]/) {
1574 $skip_call_trace = 1;
1575 }
1576
Steven Rostedt2545eb62010-11-02 15:01:32 -04001577 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001578 if (!$bug && !$skip_call_trace) {
1579 if ($ignore_errors) {
1580 $bug_ignored = 1;
1581 } else {
1582 $bug = 1;
1583 $failure_start = time;
1584 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001585 }
1586 }
1587
1588 if ($bug && defined($stop_after_failure) &&
1589 $stop_after_failure >= 0) {
1590 my $now = time;
1591 if ($now - $failure_start >= $stop_after_failure) {
1592 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1593 last;
1594 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001595 }
1596
1597 if ($full_line =~ /\[ end of backtrace testing \]/) {
1598 $skip_call_trace = 0;
1599 }
1600
1601 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001602 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001603 $bug = 1;
1604 }
1605
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001606 # Detect triple faults by testing the banner
1607 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1608 if ($1 eq $version) {
1609 $version_found = 1;
1610 } elsif ($version_found && $detect_triplefault) {
1611 # We already booted into the kernel we are testing,
1612 # but now we booted into another kernel?
1613 # Consider this a triple fault.
1614 doprint "Aleady booted in Linux kernel $version, but now\n";
1615 doprint "we booted into Linux kernel $1.\n";
1616 doprint "Assuming that this is a triple fault.\n";
1617 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1618 last;
1619 }
1620 }
1621
Steven Rostedt2545eb62010-11-02 15:01:32 -04001622 if ($line =~ /\n/) {
1623 $full_line = "";
1624 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001625
1626 if ($stop_test_after > 0 && !$booted && !$bug) {
1627 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001628 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001629 $done = 1;
1630 }
1631 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001632 }
1633
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001634 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001635
Steven Rostedt2545eb62010-11-02 15:01:32 -04001636 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001637 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001638 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001639 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001640
Steven Rostedta75fece2010-11-02 14:58:27 -04001641 if (!$booted) {
1642 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001643 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001644 }
1645
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001646 if ($bug_ignored) {
1647 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1648 }
1649
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001650 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001651}
1652
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001653sub eval_kernel_version {
1654 my ($option) = @_;
1655
1656 $option =~ s/\$KERNEL_VERSION/$version/g;
1657
1658 return $option;
1659}
1660
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001661sub do_post_install {
1662
1663 return if (!defined($post_install));
1664
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001665 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001666 run_command "$cp_post_install" or
1667 dodie "Failed to run post install";
1668}
1669
Steven Rostedt2545eb62010-11-02 15:01:32 -04001670sub install {
1671
Steven Rostedte0a87422011-09-30 17:50:48 -04001672 return if ($no_install);
1673
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001674 if (defined($pre_install)) {
1675 my $cp_pre_install = eval_kernel_version $pre_install;
1676 run_command "$cp_pre_install" or
1677 dodie "Failed to run pre install";
1678 }
1679
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001680 my $cp_target = eval_kernel_version $target_image;
1681
Steven Rostedt02ad2612012-03-21 08:21:24 -04001682 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001683 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001684
1685 my $install_mods = 0;
1686
1687 # should we process modules?
1688 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001689 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001690 while (<IN>) {
1691 if (/CONFIG_MODULES(=y)?/) {
1692 $install_mods = 1 if (defined($1));
1693 last;
1694 }
1695 }
1696 close(IN);
1697
1698 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001699 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001700 doprint "No modules needed\n";
1701 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001702 }
1703
Steven Rostedt627977d2012-03-21 08:16:15 -04001704 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001705 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001706
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001707 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001708 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001709
Steven Rostedte48c5292010-11-02 14:35:37 -04001710 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001711 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001712
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001713 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001714 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001715 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001716
Steven Rostedt02ad2612012-03-21 08:21:24 -04001717 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001718 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001719
Steven Rostedta75fece2010-11-02 14:58:27 -04001720 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001721
Steven Rostedte7b13442011-06-14 20:44:36 -04001722 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001723 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001724
Steven Rostedte48c5292010-11-02 14:35:37 -04001725 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001726
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001727 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001728}
1729
Steven Rostedtddf607e2011-06-14 20:49:13 -04001730sub get_version {
1731 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04001732 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001733 doprint "$make kernelrelease ... ";
1734 $version = `$make kernelrelease | tail -1`;
1735 chomp($version);
1736 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04001737 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04001738}
1739
1740sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001741 # Make sure the stable kernel has finished booting
1742 start_monitor;
1743 wait_for_monitor 5;
1744 end_monitor;
1745
Steven Rostedtddf607e2011-06-14 20:49:13 -04001746 get_grub_index;
1747 get_version;
1748 install;
1749
1750 start_monitor;
1751 return monitor;
1752}
1753
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001754sub check_buildlog {
1755 my ($patch) = @_;
1756
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001757 my @files = `git show $patch | diffstat -l`;
1758
1759 open(IN, "git show $patch |") or
1760 dodie "failed to show $patch";
1761 while (<IN>) {
1762 if (m,^--- a/(.*),) {
1763 chomp $1;
1764 $files[$#files] = $1;
1765 }
1766 }
1767 close(IN);
1768
1769 open(IN, $buildlog) or dodie "Can't open $buildlog";
1770 while (<IN>) {
1771 if (/^\s*(.*?):.*(warning|error)/) {
1772 my $err = $1;
1773 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001774 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001775 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001776 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001777 }
1778 }
1779 }
1780 }
1781 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001782
1783 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001784}
1785
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001786sub apply_min_config {
1787 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001788
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001789 # Read the config file and remove anything that
1790 # is in the force_config hash (from minconfig and others)
1791 # then add the force config back.
1792
1793 doprint "Applying minimum configurations into $output_config.new\n";
1794
1795 open (OUT, ">$outconfig") or
1796 dodie "Can't create $outconfig";
1797
1798 if (-f $output_config) {
1799 open (IN, $output_config) or
1800 dodie "Failed to open $output_config";
1801 while (<IN>) {
1802 if (/^(# )?(CONFIG_[^\s=]*)/) {
1803 next if (defined($force_config{$2}));
1804 }
1805 print OUT;
1806 }
1807 close IN;
1808 }
1809 foreach my $config (keys %force_config) {
1810 print OUT "$force_config{$config}\n";
1811 }
1812 close OUT;
1813
1814 run_command "mv $outconfig $output_config";
1815}
1816
1817sub make_oldconfig {
1818
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001819 my @force_list = keys %force_config;
1820
1821 if ($#force_list >= 0) {
1822 apply_min_config;
1823 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001824
1825 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001826 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1827 # try a yes '' | oldconfig
1828 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001829 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001830 dodie "failed make config oldconfig";
1831 }
1832}
1833
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001834# read a config file and use this to force new configs.
1835sub load_force_config {
1836 my ($config) = @_;
1837
1838 open(IN, $config) or
1839 dodie "failed to read $config";
1840 while (<IN>) {
1841 chomp;
1842 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1843 $force_config{$1} = $_;
1844 } elsif (/^# (CONFIG_\S*) is not set/) {
1845 $force_config{$1} = $_;
1846 }
1847 }
1848 close IN;
1849}
1850
Steven Rostedt2545eb62010-11-02 15:01:32 -04001851sub build {
1852 my ($type) = @_;
1853
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001854 unlink $buildlog;
1855
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001856 # Failed builds should not reboot the target
1857 my $save_no_reboot = $no_reboot;
1858 $no_reboot = 1;
1859
Steven Rostedt683a3e62012-05-18 13:34:35 -04001860 # Calculate a new version from here.
1861 $have_version = 0;
1862
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001863 if (defined($pre_build)) {
1864 my $ret = run_command $pre_build;
1865 if (!$ret && defined($pre_build_die) &&
1866 $pre_build_die) {
1867 dodie "failed to pre_build\n";
1868 }
1869 }
1870
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001871 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001872 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001873 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001874
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001875 $type = "oldconfig";
1876 }
1877
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001878 # old config can ask questions
1879 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001880 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001881
1882 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001883 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001884
Andrew Jones13488232011-08-12 15:32:04 +02001885 if (!$noclean) {
1886 run_command "mv $output_config $outputdir/config_temp" or
1887 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001888
Andrew Jones13488232011-08-12 15:32:04 +02001889 run_command "$make mrproper" or dodie "make mrproper";
1890
1891 run_command "mv $outputdir/config_temp $output_config" or
1892 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001893 }
1894
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001895 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001896 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001897 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001898 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001899 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001900
1901 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001902 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1903 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001904 close(OUT);
1905
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001906 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001907 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001908 }
1909
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001910 if ($type ne "oldnoconfig") {
1911 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001912 dodie "failed make config";
1913 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001914 # Run old config regardless, to enforce min configurations
1915 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001916
Steven Rostedta75fece2010-11-02 14:58:27 -04001917 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001918 my $build_ret = run_command "$make $build_options";
1919 undef $redirect;
1920
1921 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04001922 # Because a post build may change the kernel version
1923 # do it now.
1924 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001925 my $ret = run_command $post_build;
1926 if (!$ret && defined($post_build_die) &&
1927 $post_build_die) {
1928 dodie "failed to post_build\n";
1929 }
1930 }
1931
1932 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001933 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001934 if ($in_bisect) {
1935 $no_reboot = $save_no_reboot;
1936 return 0;
1937 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001938 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001939 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001940
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001941 $no_reboot = $save_no_reboot;
1942
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001943 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001944}
1945
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001946sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001947 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001948 if (defined($poweroff_after_halt)) {
1949 sleep $poweroff_after_halt;
1950 run_command "$power_off";
1951 }
1952 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001953 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001954 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001955 }
1956}
1957
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001958sub success {
1959 my ($i) = @_;
1960
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001961 if (defined($post_test)) {
1962 run_command $post_test;
1963 }
1964
Steven Rostedte48c5292010-11-02 14:35:37 -04001965 $successes++;
1966
Steven Rostedt9064af52011-06-13 10:38:48 -04001967 my $name = "";
1968
1969 if (defined($test_name)) {
1970 $name = " ($test_name)";
1971 }
1972
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001973 doprint "\n\n*******************************************\n";
1974 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001975 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001976 doprint "*******************************************\n";
1977 doprint "*******************************************\n";
1978
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301979 if (defined($store_successes)) {
1980 save_logs "success", $store_successes;
1981 }
1982
Steven Rostedt576f6272010-11-02 14:58:38 -04001983 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001984 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001985 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001986 }
1987}
1988
Steven Rostedtc960bb92011-03-08 09:22:39 -05001989sub answer_bisect {
1990 for (;;) {
1991 doprint "Pass or fail? [p/f]";
1992 my $ans = <STDIN>;
1993 chomp $ans;
1994 if ($ans eq "p" || $ans eq "P") {
1995 return 1;
1996 } elsif ($ans eq "f" || $ans eq "F") {
1997 return 0;
1998 } else {
1999 print "Please answer 'P' or 'F'\n";
2000 }
2001 }
2002}
2003
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002004sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002005 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002006
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002007 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002008 $reboot_on_error = 0;
2009 $poweroff_on_error = 0;
2010 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002011
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302012 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002013 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302014 undef $redirect;
2015
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002016 exit $failed;
2017}
2018
2019my $child_done;
2020
2021sub child_finished {
2022 $child_done = 1;
2023}
2024
2025sub do_run_test {
2026 my $child_pid;
2027 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002028 my $line;
2029 my $full_line;
2030 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002031
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002032 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002033
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002034 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002035
2036 $child_done = 0;
2037
2038 $SIG{CHLD} = qw(child_finished);
2039
2040 $child_pid = fork;
2041
2042 child_run_test if (!$child_pid);
2043
2044 $full_line = "";
2045
2046 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002047 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002048 if (defined($line)) {
2049
2050 # we are not guaranteed to get a full line
2051 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002052 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002053
2054 if ($full_line =~ /call trace:/i) {
2055 $bug = 1;
2056 }
2057
2058 if ($full_line =~ /Kernel panic -/) {
2059 $bug = 1;
2060 }
2061
2062 if ($line =~ /\n/) {
2063 $full_line = "";
2064 }
2065 }
2066 } while (!$child_done && !$bug);
2067
2068 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002069 my $failure_start = time;
2070 my $now;
2071 do {
2072 $line = wait_for_input($monitor_fp, 1);
2073 if (defined($line)) {
2074 doprint $line;
2075 }
2076 $now = time;
2077 if ($now - $failure_start >= $stop_after_failure) {
2078 last;
2079 }
2080 } while (defined($line));
2081
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002082 doprint "Detected kernel crash!\n";
2083 # kill the child with extreme prejudice
2084 kill 9, $child_pid;
2085 }
2086
2087 waitpid $child_pid, 0;
2088 $child_exit = $?;
2089
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002090 if (!$bug && $in_bisect) {
2091 if (defined($bisect_ret_good)) {
2092 if ($child_exit == $bisect_ret_good) {
2093 return 1;
2094 }
2095 }
2096 if (defined($bisect_ret_skip)) {
2097 if ($child_exit == $bisect_ret_skip) {
2098 return -1;
2099 }
2100 }
2101 if (defined($bisect_ret_abort)) {
2102 if ($child_exit == $bisect_ret_abort) {
2103 fail "test abort" and return -2;
2104 }
2105 }
2106 if (defined($bisect_ret_bad)) {
2107 if ($child_exit == $bisect_ret_skip) {
2108 return 0;
2109 }
2110 }
2111 if (defined($bisect_ret_default)) {
2112 if ($bisect_ret_default eq "good") {
2113 return 1;
2114 } elsif ($bisect_ret_default eq "bad") {
2115 return 0;
2116 } elsif ($bisect_ret_default eq "skip") {
2117 return -1;
2118 } elsif ($bisect_ret_default eq "abort") {
2119 return -2;
2120 } else {
2121 fail "unknown default action: $bisect_ret_default"
2122 and return -2;
2123 }
2124 }
2125 }
2126
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002127 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002128 return 0 if $in_bisect;
2129 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002130 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002131 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002132}
2133
Steven Rostedta75fece2010-11-02 14:58:27 -04002134sub run_git_bisect {
2135 my ($command) = @_;
2136
2137 doprint "$command ... ";
2138
2139 my $output = `$command 2>&1`;
2140 my $ret = $?;
2141
2142 logit $output;
2143
2144 if ($ret) {
2145 doprint "FAILED\n";
2146 dodie "Failed to git bisect";
2147 }
2148
2149 doprint "SUCCESS\n";
2150 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2151 doprint "$1 [$2]\n";
2152 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002153 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002154 doprint "Found bad commit... $1\n";
2155 return 0;
2156 } else {
2157 # we already logged it, just print it now.
2158 print $output;
2159 }
2160
2161 return 1;
2162}
2163
Steven Rostedtc23dca72011-03-08 09:26:31 -05002164sub bisect_reboot {
2165 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002166 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002167}
2168
2169# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002170sub run_bisect_test {
2171 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002172
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002173 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002174 my $result;
2175 my $output;
2176 my $ret;
2177
Steven Rostedt0a05c762010-11-08 11:14:10 -05002178 $in_bisect = 1;
2179
2180 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002181
2182 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002183 if ($failed && $bisect_skip) {
2184 $in_bisect = 0;
2185 return -1;
2186 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002187 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002188
2189 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002190 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002191
2192 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002193 if ($failed && $bisect_skip) {
2194 end_monitor;
2195 bisect_reboot;
2196 $in_bisect = 0;
2197 return -1;
2198 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002199 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002200
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002201 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002202 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002203 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002204 }
2205
2206 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002207 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002208 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002209 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002210 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002211
2212 # reboot the box to a kernel we can ssh to
2213 if ($type ne "build") {
2214 bisect_reboot;
2215 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002216 $in_bisect = 0;
2217
2218 return $result;
2219}
2220
2221sub run_bisect {
2222 my ($type) = @_;
2223 my $buildtype = "oldconfig";
2224
2225 # We should have a minconfig to use?
2226 if (defined($minconfig)) {
2227 $buildtype = "useconfig:$minconfig";
2228 }
2229
2230 my $ret = run_bisect_test $type, $buildtype;
2231
Steven Rostedtc960bb92011-03-08 09:22:39 -05002232 if ($bisect_manual) {
2233 $ret = answer_bisect;
2234 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002235
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002236 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002237 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002238 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002239 }
2240
Steven Rostedtc23dca72011-03-08 09:26:31 -05002241 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002242 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002243 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002244 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002245 } elsif ($bisect_skip) {
2246 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2247 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002248 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002249}
2250
Steven Rostedtdad98752011-11-22 20:48:57 -05002251sub update_bisect_replay {
2252 my $tmp_log = "$tmpdir/ktest_bisect_log";
2253 run_command "git bisect log > $tmp_log" or
2254 die "can't create bisect log";
2255 return $tmp_log;
2256}
2257
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002258sub bisect {
2259 my ($i) = @_;
2260
2261 my $result;
2262
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002263 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2264 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2265 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002266
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002267 my $good = $bisect_good;
2268 my $bad = $bisect_bad;
2269 my $type = $bisect_type;
2270 my $start = $bisect_start;
2271 my $replay = $bisect_replay;
2272 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002273
2274 if (defined($start_files)) {
2275 $start_files = " -- " . $start_files;
2276 } else {
2277 $start_files = "";
2278 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002279
Steven Rostedta57419b2010-11-02 15:13:54 -04002280 # convert to true sha1's
2281 $good = get_sha1($good);
2282 $bad = get_sha1($bad);
2283
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002284 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002285 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2286 $reverse_bisect = 1;
2287 } else {
2288 $reverse_bisect = 0;
2289 }
2290
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002291 # Can't have a test without having a test to run
2292 if ($type eq "test" && !defined($run_test)) {
2293 $type = "boot";
2294 }
2295
Steven Rostedtdad98752011-11-22 20:48:57 -05002296 # Check if a bisect was running
2297 my $bisect_start_file = "$builddir/.git/BISECT_START";
2298
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002299 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002300 my $do_check = defined($check) && $check ne "0";
2301
2302 if ( -f $bisect_start_file ) {
2303 print "Bisect in progress found\n";
2304 if ($do_check) {
2305 print " If you say yes, then no checks of good or bad will be done\n";
2306 }
2307 if (defined($replay)) {
2308 print "** BISECT_REPLAY is defined in config file **";
2309 print " Ignore config option and perform new git bisect log?\n";
2310 if (read_ync " (yes, no, or cancel) ") {
2311 $replay = update_bisect_replay;
2312 $do_check = 0;
2313 }
2314 } elsif (read_yn "read git log and continue?") {
2315 $replay = update_bisect_replay;
2316 $do_check = 0;
2317 }
2318 }
2319
2320 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002321
2322 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002323 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002324
2325 if ($check ne "good") {
2326 doprint "TESTING BISECT BAD [$bad]\n";
2327 run_command "git checkout $bad" or
2328 die "Failed to checkout $bad";
2329
2330 $result = run_bisect $type;
2331
2332 if ($result ne "bad") {
2333 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2334 }
2335 }
2336
2337 if ($check ne "bad") {
2338 doprint "TESTING BISECT GOOD [$good]\n";
2339 run_command "git checkout $good" or
2340 die "Failed to checkout $good";
2341
2342 $result = run_bisect $type;
2343
2344 if ($result ne "good") {
2345 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2346 }
2347 }
2348
2349 # checkout where we started
2350 run_command "git checkout $head" or
2351 die "Failed to checkout $head";
2352 }
2353
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002354 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002355 dodie "could not start bisect";
2356
2357 run_command "git bisect good $good" or
2358 dodie "could not set bisect good to $good";
2359
2360 run_git_bisect "git bisect bad $bad" or
2361 dodie "could not set bisect bad to $bad";
2362
2363 if (defined($replay)) {
2364 run_command "git bisect replay $replay" or
2365 dodie "failed to run replay";
2366 }
2367
2368 if (defined($start)) {
2369 run_command "git checkout $start" or
2370 dodie "failed to checkout $start";
2371 }
2372
2373 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002374 do {
2375 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002376 $test = run_git_bisect "git bisect $result";
2377 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002378
2379 run_command "git bisect log" or
2380 dodie "could not capture git bisect log";
2381
2382 run_command "git bisect reset" or
2383 dodie "could not reset git bisect";
2384
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002385 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002386
Steven Rostedt0a05c762010-11-08 11:14:10 -05002387 success $i;
2388}
2389
2390my %config_ignore;
2391my %config_set;
2392
2393my %config_list;
2394my %null_config;
2395
2396my %dependency;
2397
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002398sub assign_configs {
2399 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002400
2401 open (IN, $config)
2402 or dodie "Failed to read $config";
2403
2404 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002405 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002406 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002407 }
2408 }
2409
2410 close(IN);
2411}
2412
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002413sub process_config_ignore {
2414 my ($config) = @_;
2415
2416 assign_configs \%config_ignore, $config;
2417}
2418
Steven Rostedt0a05c762010-11-08 11:14:10 -05002419sub read_current_config {
2420 my ($config_ref) = @_;
2421
2422 %{$config_ref} = ();
2423 undef %{$config_ref};
2424
2425 my @key = keys %{$config_ref};
2426 if ($#key >= 0) {
2427 print "did not delete!\n";
2428 exit;
2429 }
2430 open (IN, "$output_config");
2431
2432 while (<IN>) {
2433 if (/^(CONFIG\S+)=(.*)/) {
2434 ${$config_ref}{$1} = $2;
2435 }
2436 }
2437 close(IN);
2438}
2439
2440sub get_dependencies {
2441 my ($config) = @_;
2442
2443 my $arr = $dependency{$config};
2444 if (!defined($arr)) {
2445 return ();
2446 }
2447
2448 my @deps = @{$arr};
2449
2450 foreach my $dep (@{$arr}) {
2451 print "ADD DEP $dep\n";
2452 @deps = (@deps, get_dependencies $dep);
2453 }
2454
2455 return @deps;
2456}
2457
2458sub create_config {
2459 my @configs = @_;
2460
2461 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2462
2463 foreach my $config (@configs) {
2464 print OUT "$config_set{$config}\n";
2465 my @deps = get_dependencies $config;
2466 foreach my $dep (@deps) {
2467 print OUT "$config_set{$dep}\n";
2468 }
2469 }
2470
2471 foreach my $config (keys %config_ignore) {
2472 print OUT "$config_ignore{$config}\n";
2473 }
2474 close(OUT);
2475
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002476 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002477}
2478
2479sub compare_configs {
2480 my (%a, %b) = @_;
2481
2482 foreach my $item (keys %a) {
2483 if (!defined($b{$item})) {
2484 print "diff $item\n";
2485 return 1;
2486 }
2487 delete $b{$item};
2488 }
2489
2490 my @keys = keys %b;
2491 if ($#keys) {
2492 print "diff2 $keys[0]\n";
2493 }
2494 return -1 if ($#keys >= 0);
2495
2496 return 0;
2497}
2498
2499sub run_config_bisect_test {
2500 my ($type) = @_;
2501
2502 return run_bisect_test $type, "oldconfig";
2503}
2504
2505sub process_passed {
2506 my (%configs) = @_;
2507
2508 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2509 # Passed! All these configs are part of a good compile.
2510 # Add them to the min options.
2511 foreach my $config (keys %configs) {
2512 if (defined($config_list{$config})) {
2513 doprint " removing $config\n";
2514 $config_ignore{$config} = $config_list{$config};
2515 delete $config_list{$config};
2516 }
2517 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002518 doprint "config copied to $outputdir/config_good\n";
2519 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002520}
2521
2522sub process_failed {
2523 my ($config) = @_;
2524
2525 doprint "\n\n***************************************\n";
2526 doprint "Found bad config: $config\n";
2527 doprint "***************************************\n\n";
2528}
2529
2530sub run_config_bisect {
2531
2532 my @start_list = keys %config_list;
2533
2534 if ($#start_list < 0) {
2535 doprint "No more configs to test!!!\n";
2536 return -1;
2537 }
2538
2539 doprint "***** RUN TEST ***\n";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002540 my $type = $config_bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002541 my $ret;
2542 my %current_config;
2543
2544 my $count = $#start_list + 1;
2545 doprint " $count configs to test\n";
2546
2547 my $half = int($#start_list / 2);
2548
2549 do {
2550 my @tophalf = @start_list[0 .. $half];
2551
2552 create_config @tophalf;
2553 read_current_config \%current_config;
2554
2555 $count = $#tophalf + 1;
2556 doprint "Testing $count configs\n";
2557 my $found = 0;
2558 # make sure we test something
2559 foreach my $config (@tophalf) {
2560 if (defined($current_config{$config})) {
2561 logit " $config\n";
2562 $found = 1;
2563 }
2564 }
2565 if (!$found) {
2566 # try the other half
2567 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002568 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05002569 create_config @tophalf;
2570 read_current_config \%current_config;
2571 foreach my $config (@tophalf) {
2572 if (defined($current_config{$config})) {
2573 logit " $config\n";
2574 $found = 1;
2575 }
2576 }
2577 if (!$found) {
2578 doprint "Failed: Can't make new config with current configs\n";
2579 foreach my $config (@start_list) {
2580 doprint " CONFIG: $config\n";
2581 }
2582 return -1;
2583 }
2584 $count = $#tophalf + 1;
2585 doprint "Testing $count configs\n";
2586 }
2587
2588 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002589 if ($bisect_manual) {
2590 $ret = answer_bisect;
2591 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002592 if ($ret) {
2593 process_passed %current_config;
2594 return 0;
2595 }
2596
2597 doprint "This config had a failure.\n";
2598 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002599 doprint "config copied to $outputdir/config_bad\n";
2600 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002601
2602 # A config exists in this group that was bad.
2603 foreach my $config (keys %config_list) {
2604 if (!defined($current_config{$config})) {
2605 doprint " removing $config\n";
2606 delete $config_list{$config};
2607 }
2608 }
2609
2610 @start_list = @tophalf;
2611
2612 if ($#start_list == 0) {
2613 process_failed $start_list[0];
2614 return 1;
2615 }
2616
2617 # remove half the configs we are looking at and see if
2618 # they are good.
2619 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002620 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002621
Steven Rostedtc960bb92011-03-08 09:22:39 -05002622 # we found a single config, try it again unless we are running manually
2623
2624 if ($bisect_manual) {
2625 process_failed $start_list[0];
2626 return 1;
2627 }
2628
Steven Rostedt0a05c762010-11-08 11:14:10 -05002629 my @tophalf = @start_list[0 .. 0];
2630
2631 $ret = run_config_bisect_test $type;
2632 if ($ret) {
2633 process_passed %current_config;
2634 return 0;
2635 }
2636
2637 process_failed $start_list[0];
2638 return 1;
2639}
2640
2641sub config_bisect {
2642 my ($i) = @_;
2643
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002644 my $start_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002645
2646 my $tmpconfig = "$tmpdir/use_config";
2647
Steven Rostedt30f75da2011-06-13 10:35:35 -04002648 if (defined($config_bisect_good)) {
2649 process_config_ignore $config_bisect_good;
2650 }
2651
Steven Rostedt0a05c762010-11-08 11:14:10 -05002652 # Make the file with the bad config and the min config
2653 if (defined($minconfig)) {
2654 # read the min config for things to ignore
2655 run_command "cp $minconfig $tmpconfig" or
2656 dodie "failed to copy $minconfig to $tmpconfig";
2657 } else {
2658 unlink $tmpconfig;
2659 }
2660
Steven Rostedt0a05c762010-11-08 11:14:10 -05002661 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002662 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002663 process_config_ignore $tmpconfig;
2664 }
2665
2666 # now process the start config
2667 run_command "cp $start_config $output_config" or
2668 dodie "failed to copy $start_config to $output_config";
2669
2670 # read directly what we want to check
2671 my %config_check;
2672 open (IN, $output_config)
Masanari Iidaf9dee312012-02-11 21:46:56 +09002673 or dodie "failed to open $output_config";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002674
2675 while (<IN>) {
2676 if (/^((CONFIG\S*)=.*)/) {
2677 $config_check{$2} = $1;
2678 }
2679 }
2680 close(IN);
2681
Steven Rostedt250bae82011-07-15 22:05:59 -04002682 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002683 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002684
2685 # check to see what we lost (or gained)
2686 open (IN, $output_config)
2687 or dodie "Failed to read $start_config";
2688
2689 my %removed_configs;
2690 my %added_configs;
2691
2692 while (<IN>) {
2693 if (/^((CONFIG\S*)=.*)/) {
2694 # save off all options
2695 $config_set{$2} = $1;
2696 if (defined($config_check{$2})) {
2697 if (defined($config_ignore{$2})) {
2698 $removed_configs{$2} = $1;
2699 } else {
2700 $config_list{$2} = $1;
2701 }
2702 } elsif (!defined($config_ignore{$2})) {
2703 $added_configs{$2} = $1;
2704 $config_list{$2} = $1;
2705 }
2706 }
2707 }
2708 close(IN);
2709
2710 my @confs = keys %removed_configs;
2711 if ($#confs >= 0) {
2712 doprint "Configs overridden by default configs and removed from check:\n";
2713 foreach my $config (@confs) {
2714 doprint " $config\n";
2715 }
2716 }
2717 @confs = keys %added_configs;
2718 if ($#confs >= 0) {
2719 doprint "Configs appearing in make oldconfig and added:\n";
2720 foreach my $config (@confs) {
2721 doprint " $config\n";
2722 }
2723 }
2724
2725 my %config_test;
2726 my $once = 0;
2727
2728 # Sometimes kconfig does weird things. We must make sure
2729 # that the config we autocreate has everything we need
2730 # to test, otherwise we may miss testing configs, or
2731 # may not be able to create a new config.
2732 # Here we create a config with everything set.
2733 create_config (keys %config_list);
2734 read_current_config \%config_test;
2735 foreach my $config (keys %config_list) {
2736 if (!defined($config_test{$config})) {
2737 if (!$once) {
2738 $once = 1;
2739 doprint "Configs not produced by kconfig (will not be checked):\n";
2740 }
2741 doprint " $config\n";
2742 delete $config_list{$config};
2743 }
2744 }
2745 my $ret;
2746 do {
2747 $ret = run_config_bisect;
2748 } while (!$ret);
2749
2750 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002751
2752 success $i;
2753}
2754
Steven Rostedt27d934b2011-05-20 09:18:18 -04002755sub patchcheck_reboot {
2756 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002757 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002758}
2759
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002760sub patchcheck {
2761 my ($i) = @_;
2762
2763 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002764 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002765 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002766 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002767
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002768 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002769
2770 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002771 if (defined($patchcheck_end)) {
2772 $end = $patchcheck_end;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002773 }
2774
Steven Rostedta57419b2010-11-02 15:13:54 -04002775 # Get the true sha1's since we can use things like HEAD~3
2776 $start = get_sha1($start);
2777 $end = get_sha1($end);
2778
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002779 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002780
2781 # Can't have a test without having a test to run
2782 if ($type eq "test" && !defined($run_test)) {
2783 $type = "boot";
2784 }
2785
2786 open (IN, "git log --pretty=oneline $end|") or
2787 dodie "could not get git list";
2788
2789 my @list;
2790
2791 while (<IN>) {
2792 chomp;
2793 $list[$#list+1] = $_;
2794 last if (/^$start/);
2795 }
2796 close(IN);
2797
2798 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002799 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002800 }
2801
2802 # go backwards in the list
2803 @list = reverse @list;
2804
2805 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002806 my %ignored_warnings;
2807
2808 if (defined($ignore_warnings)) {
2809 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2810 $ignored_warnings{$sha1} = 1;
2811 }
2812 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002813
2814 $in_patchcheck = 1;
2815 foreach my $item (@list) {
2816 my $sha1 = $item;
2817 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2818
2819 doprint "\nProcessing commit $item\n\n";
2820
2821 run_command "git checkout $sha1" or
2822 die "Failed to checkout $sha1";
2823
2824 # only clean on the first and last patch
2825 if ($item eq $list[0] ||
2826 $item eq $list[$#list]) {
2827 $noclean = $save_clean;
2828 } else {
2829 $noclean = 1;
2830 }
2831
2832 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002833 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002834 } else {
2835 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002836 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002837 }
2838
Steven Rostedt19902072011-06-14 20:46:25 -04002839
2840 if (!defined($ignored_warnings{$sha1})) {
2841 check_buildlog $sha1 or return 0;
2842 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002843
2844 next if ($type eq "build");
2845
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002846 my $failed = 0;
2847
Steven Rostedtddf607e2011-06-14 20:49:13 -04002848 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002849
2850 if (!$failed && $type ne "boot"){
2851 do_run_test or $failed = 1;
2852 }
2853 end_monitor;
2854 return 0 if ($failed);
2855
Steven Rostedt27d934b2011-05-20 09:18:18 -04002856 patchcheck_reboot;
2857
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002858 }
2859 $in_patchcheck = 0;
2860 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002861
2862 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002863}
2864
Steven Rostedtb9066f62011-07-15 21:25:24 -04002865my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002866my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002867my $iflevel = 0;
2868my @ifdeps;
2869
2870# prevent recursion
2871my %read_kconfigs;
2872
Steven Rostedtac6974c2011-10-04 09:40:17 -04002873sub add_dep {
2874 # $config depends on $dep
2875 my ($config, $dep) = @_;
2876
2877 if (defined($depends{$config})) {
2878 $depends{$config} .= " " . $dep;
2879 } else {
2880 $depends{$config} = $dep;
2881 }
2882
2883 # record the number of configs depending on $dep
2884 if (defined $depcount{$dep}) {
2885 $depcount{$dep}++;
2886 } else {
2887 $depcount{$dep} = 1;
2888 }
2889}
2890
Steven Rostedtb9066f62011-07-15 21:25:24 -04002891# taken from streamline_config.pl
2892sub read_kconfig {
2893 my ($kconfig) = @_;
2894
2895 my $state = "NONE";
2896 my $config;
2897 my @kconfigs;
2898
2899 my $cont = 0;
2900 my $line;
2901
2902
2903 if (! -f $kconfig) {
2904 doprint "file $kconfig does not exist, skipping\n";
2905 return;
2906 }
2907
2908 open(KIN, "$kconfig")
2909 or die "Can't open $kconfig";
2910 while (<KIN>) {
2911 chomp;
2912
2913 # Make sure that lines ending with \ continue
2914 if ($cont) {
2915 $_ = $line . " " . $_;
2916 }
2917
2918 if (s/\\$//) {
2919 $cont = 1;
2920 $line = $_;
2921 next;
2922 }
2923
2924 $cont = 0;
2925
2926 # collect any Kconfig sources
2927 if (/^source\s*"(.*)"/) {
2928 $kconfigs[$#kconfigs+1] = $1;
2929 }
2930
2931 # configs found
2932 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2933 $state = "NEW";
2934 $config = $2;
2935
2936 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04002937 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04002938 }
2939
2940 # collect the depends for the config
2941 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2942
Steven Rostedtac6974c2011-10-04 09:40:17 -04002943 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002944
2945 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04002946 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2947
2948 # selected by depends on config
2949 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002950
2951 # Check for if statements
2952 } elsif (/^if\s+(.*\S)\s*$/) {
2953 my $deps = $1;
2954 # remove beginning and ending non text
2955 $deps =~ s/^[^a-zA-Z0-9_]*//;
2956 $deps =~ s/[^a-zA-Z0-9_]*$//;
2957
2958 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2959
2960 $ifdeps[$iflevel++] = join ':', @deps;
2961
2962 } elsif (/^endif/) {
2963
2964 $iflevel-- if ($iflevel);
2965
2966 # stop on "help"
2967 } elsif (/^\s*help\s*$/) {
2968 $state = "NONE";
2969 }
2970 }
2971 close(KIN);
2972
2973 # read in any configs that were found.
2974 foreach $kconfig (@kconfigs) {
2975 if (!defined($read_kconfigs{$kconfig})) {
2976 $read_kconfigs{$kconfig} = 1;
2977 read_kconfig("$builddir/$kconfig");
2978 }
2979 }
2980}
2981
2982sub read_depends {
2983 # find out which arch this is by the kconfig file
2984 open (IN, $output_config)
2985 or dodie "Failed to read $output_config";
2986 my $arch;
2987 while (<IN>) {
2988 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2989 $arch = $1;
2990 last;
2991 }
2992 }
2993 close IN;
2994
2995 if (!defined($arch)) {
2996 doprint "Could not find arch from config file\n";
2997 doprint "no dependencies used\n";
2998 return;
2999 }
3000
3001 # arch is really the subarch, we need to know
3002 # what directory to look at.
3003 if ($arch eq "i386" || $arch eq "x86_64") {
3004 $arch = "x86";
3005 } elsif ($arch =~ /^tile/) {
3006 $arch = "tile";
3007 }
3008
3009 my $kconfig = "$builddir/arch/$arch/Kconfig";
3010
3011 if (! -f $kconfig && $arch =~ /\d$/) {
3012 my $orig = $arch;
3013 # some subarchs have numbers, truncate them
3014 $arch =~ s/\d*$//;
3015 $kconfig = "$builddir/arch/$arch/Kconfig";
3016 if (! -f $kconfig) {
3017 doprint "No idea what arch dir $orig is for\n";
3018 doprint "no dependencies used\n";
3019 return;
3020 }
3021 }
3022
3023 read_kconfig($kconfig);
3024}
3025
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003026sub read_config_list {
3027 my ($config) = @_;
3028
3029 open (IN, $config)
3030 or dodie "Failed to read $config";
3031
3032 while (<IN>) {
3033 if (/^((CONFIG\S*)=.*)/) {
3034 if (!defined($config_ignore{$2})) {
3035 $config_list{$2} = $1;
3036 }
3037 }
3038 }
3039
3040 close(IN);
3041}
3042
3043sub read_output_config {
3044 my ($config) = @_;
3045
3046 assign_configs \%config_ignore, $config;
3047}
3048
3049sub make_new_config {
3050 my @configs = @_;
3051
3052 open (OUT, ">$output_config")
3053 or dodie "Failed to write $output_config";
3054
3055 foreach my $config (@configs) {
3056 print OUT "$config\n";
3057 }
3058 close OUT;
3059}
3060
Steven Rostedtac6974c2011-10-04 09:40:17 -04003061sub chomp_config {
3062 my ($config) = @_;
3063
3064 $config =~ s/CONFIG_//;
3065
3066 return $config;
3067}
3068
Steven Rostedtb9066f62011-07-15 21:25:24 -04003069sub get_depends {
3070 my ($dep) = @_;
3071
Steven Rostedtac6974c2011-10-04 09:40:17 -04003072 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003073
3074 $dep = $depends{"$kconfig"};
3075
3076 # the dep string we have saves the dependencies as they
3077 # were found, including expressions like ! && ||. We
3078 # want to split this out into just an array of configs.
3079
3080 my $valid = "A-Za-z_0-9";
3081
3082 my @configs;
3083
3084 while ($dep =~ /[$valid]/) {
3085
3086 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3087 my $conf = "CONFIG_" . $1;
3088
3089 $configs[$#configs + 1] = $conf;
3090
3091 $dep =~ s/^[^$valid]*[$valid]+//;
3092 } else {
3093 die "this should never happen";
3094 }
3095 }
3096
3097 return @configs;
3098}
3099
3100my %min_configs;
3101my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003102my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003103my %processed_configs;
3104my %nochange_config;
3105
3106sub test_this_config {
3107 my ($config) = @_;
3108
3109 my $found;
3110
3111 # if we already processed this config, skip it
3112 if (defined($processed_configs{$config})) {
3113 return undef;
3114 }
3115 $processed_configs{$config} = 1;
3116
3117 # if this config failed during this round, skip it
3118 if (defined($nochange_config{$config})) {
3119 return undef;
3120 }
3121
Steven Rostedtac6974c2011-10-04 09:40:17 -04003122 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003123
3124 # Test dependencies first
3125 if (defined($depends{"$kconfig"})) {
3126 my @parents = get_depends $config;
3127 foreach my $parent (@parents) {
3128 # if the parent is in the min config, check it first
3129 next if (!defined($min_configs{$parent}));
3130 $found = test_this_config($parent);
3131 if (defined($found)) {
3132 return $found;
3133 }
3134 }
3135 }
3136
3137 # Remove this config from the list of configs
3138 # do a make oldnoconfig and then read the resulting
3139 # .config to make sure it is missing the config that
3140 # we had before
3141 my %configs = %min_configs;
3142 delete $configs{$config};
3143 make_new_config ((values %configs), (values %keep_configs));
3144 make_oldconfig;
3145 undef %configs;
3146 assign_configs \%configs, $output_config;
3147
3148 return $config if (!defined($configs{$config}));
3149
3150 doprint "disabling config $config did not change .config\n";
3151
3152 $nochange_config{$config} = 1;
3153
3154 return undef;
3155}
3156
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003157sub make_min_config {
3158 my ($i) = @_;
3159
Steven Rostedtccc513b2012-05-21 17:13:40 -04003160 my $type = $minconfig_type;
3161 if ($type ne "boot" && $type ne "test") {
3162 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3163 " make_min_config works only with 'boot' and 'test'\n" and return;
3164 }
3165
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003166 if (!defined($output_minconfig)) {
3167 fail "OUTPUT_MIN_CONFIG not defined" and return;
3168 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003169
3170 # If output_minconfig exists, and the start_minconfig
3171 # came from min_config, than ask if we should use
3172 # that instead.
3173 if (-f $output_minconfig && !$start_minconfig_defined) {
3174 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003175 if (!defined($use_output_minconfig)) {
3176 if (read_yn " Use it as minconfig?") {
3177 $start_minconfig = $output_minconfig;
3178 }
3179 } elsif ($use_output_minconfig > 0) {
3180 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003181 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003182 } else {
3183 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003184 }
3185 }
3186
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003187 if (!defined($start_minconfig)) {
3188 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3189 }
3190
Steven Rostedt35ce5952011-07-15 21:57:25 -04003191 my $temp_config = "$tmpdir/temp_config";
3192
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003193 # First things first. We build an allnoconfig to find
3194 # out what the defaults are that we can't touch.
3195 # Some are selections, but we really can't handle selections.
3196
3197 my $save_minconfig = $minconfig;
3198 undef $minconfig;
3199
3200 run_command "$make allnoconfig" or return 0;
3201
Steven Rostedtb9066f62011-07-15 21:25:24 -04003202 read_depends;
3203
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003204 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003205
Steven Rostedt43d1b652011-07-15 22:01:56 -04003206 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003207 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003208
3209 if (defined($ignore_config)) {
3210 # make sure the file exists
3211 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003212 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003213 }
3214
Steven Rostedt43d1b652011-07-15 22:01:56 -04003215 %keep_configs = %save_configs;
3216
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003217 doprint "Load initial configs from $start_minconfig\n";
3218
3219 # Look at the current min configs, and save off all the
3220 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003221 assign_configs \%min_configs, $start_minconfig;
3222
3223 my @config_keys = keys %min_configs;
3224
Steven Rostedtac6974c2011-10-04 09:40:17 -04003225 # All configs need a depcount
3226 foreach my $config (@config_keys) {
3227 my $kconfig = chomp_config $config;
3228 if (!defined $depcount{$kconfig}) {
3229 $depcount{$kconfig} = 0;
3230 }
3231 }
3232
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003233 # Remove anything that was set by the make allnoconfig
3234 # we shouldn't need them as they get set for us anyway.
3235 foreach my $config (@config_keys) {
3236 # Remove anything in the ignore_config
3237 if (defined($keep_configs{$config})) {
3238 my $file = $ignore_config;
3239 $file =~ s,.*/(.*?)$,$1,;
3240 doprint "$config set by $file ... ignored\n";
3241 delete $min_configs{$config};
3242 next;
3243 }
3244 # But make sure the settings are the same. If a min config
3245 # sets a selection, we do not want to get rid of it if
3246 # it is not the same as what we have. Just move it into
3247 # the keep configs.
3248 if (defined($config_ignore{$config})) {
3249 if ($config_ignore{$config} ne $min_configs{$config}) {
3250 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3251 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3252 $keep_configs{$config} = $min_configs{$config};
3253 } else {
3254 doprint "$config set by allnoconfig ... ignored\n";
3255 }
3256 delete $min_configs{$config};
3257 }
3258 }
3259
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003260 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003261 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003262
3263 while (!$done) {
3264
3265 my $config;
3266 my $found;
3267
3268 # Now disable each config one by one and do a make oldconfig
3269 # till we find a config that changes our list.
3270
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003271 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003272
3273 # Sort keys by who is most dependent on
3274 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3275 @test_configs ;
3276
3277 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003278 my $reset = 1;
3279 for (my $i = 0; $i < $#test_configs; $i++) {
3280 if (!defined($nochange_config{$test_configs[0]})) {
3281 $reset = 0;
3282 last;
3283 }
3284 # This config didn't change the .config last time.
3285 # Place it at the end
3286 my $config = shift @test_configs;
3287 push @test_configs, $config;
3288 }
3289
3290 # if every test config has failed to modify the .config file
3291 # in the past, then reset and start over.
3292 if ($reset) {
3293 undef %nochange_config;
3294 }
3295
Steven Rostedtb9066f62011-07-15 21:25:24 -04003296 undef %processed_configs;
3297
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003298 foreach my $config (@test_configs) {
3299
Steven Rostedtb9066f62011-07-15 21:25:24 -04003300 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003301
Steven Rostedtb9066f62011-07-15 21:25:24 -04003302 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003303
3304 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003305 }
3306
3307 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003308 # we could have failed due to the nochange_config hash
3309 # reset and try again
3310 if (!$take_two) {
3311 undef %nochange_config;
3312 $take_two = 1;
3313 next;
3314 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003315 doprint "No more configs found that we can disable\n";
3316 $done = 1;
3317 last;
3318 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003319 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003320
3321 $config = $found;
3322
3323 doprint "Test with $config disabled\n";
3324
3325 # set in_bisect to keep build and monitor from dieing
3326 $in_bisect = 1;
3327
3328 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003329 build "oldconfig" or $failed = 1;
3330 if (!$failed) {
3331 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003332
3333 if ($type eq "test" && !$failed) {
3334 do_run_test or $failed = 1;
3335 }
3336
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003337 end_monitor;
3338 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003339
3340 $in_bisect = 0;
3341
3342 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003343 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003344 # this config is needed, add it to the ignore list.
3345 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003346 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003347 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003348
3349 # update new ignore configs
3350 if (defined($ignore_config)) {
3351 open (OUT, ">$temp_config")
3352 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003353 foreach my $config (keys %save_configs) {
3354 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003355 }
3356 close OUT;
3357 run_command "mv $temp_config $ignore_config" or
3358 dodie "failed to copy update to $ignore_config";
3359 }
3360
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003361 } else {
3362 # We booted without this config, remove it from the minconfigs.
3363 doprint "$config is not needed, disabling\n";
3364
3365 delete $min_configs{$config};
3366
3367 # Also disable anything that is not enabled in this config
3368 my %configs;
3369 assign_configs \%configs, $output_config;
3370 my @config_keys = keys %min_configs;
3371 foreach my $config (@config_keys) {
3372 if (!defined($configs{$config})) {
3373 doprint "$config is not set, disabling\n";
3374 delete $min_configs{$config};
3375 }
3376 }
3377
3378 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003379 open (OUT, ">$temp_config")
3380 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003381 foreach my $config (keys %keep_configs) {
3382 print OUT "$keep_configs{$config}\n";
3383 }
3384 foreach my $config (keys %min_configs) {
3385 print OUT "$min_configs{$config}\n";
3386 }
3387 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003388
3389 run_command "mv $temp_config $output_minconfig" or
3390 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003391 }
3392
3393 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003394 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003395 }
3396
3397 success $i;
3398 return 1;
3399}
3400
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003401$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003402
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003403if ($#ARGV == 0) {
3404 $ktest_config = $ARGV[0];
3405 if (! -f $ktest_config) {
3406 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003407 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003408 exit 0;
3409 }
3410 }
3411} else {
3412 $ktest_config = "ktest.conf";
3413}
3414
3415if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003416 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003417 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003418 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3419 print OUT << "EOF"
3420# Generated by ktest.pl
3421#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003422
3423# PWD is a ktest.pl variable that will result in the process working
3424# directory that ktest.pl is executed in.
3425
3426# THIS_DIR is automatically assigned the PWD of the path that generated
3427# the config file. It is best to use this variable when assigning other
3428# directory paths within this directory. This allows you to easily
3429# move the test cases to other locations or to other machines.
3430#
3431THIS_DIR := $variable{"PWD"}
3432
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003433# Define each test with TEST_START
3434# The config options below it will override the defaults
3435TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003436TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003437
3438DEFAULTS
3439EOF
3440;
3441 close(OUT);
3442}
3443read_config $ktest_config;
3444
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003445if (defined($opt{"LOG_FILE"})) {
3446 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3447}
3448
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003449# Append any configs entered in manually to the config file.
3450my @new_configs = keys %entered_configs;
3451if ($#new_configs >= 0) {
3452 print "\nAppending entered in configs to $ktest_config\n";
3453 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3454 foreach my $config (@new_configs) {
3455 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003456 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003457 }
3458}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003459
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003460if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3461 unlink $opt{"LOG_FILE"};
3462}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003463
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003464doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3465
Steven Rostedta57419b2010-11-02 15:13:54 -04003466for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3467
3468 if (!$i) {
3469 doprint "DEFAULT OPTIONS:\n";
3470 } else {
3471 doprint "\nTEST $i OPTIONS";
3472 if (defined($repeat_tests{$i})) {
3473 $repeat = $repeat_tests{$i};
3474 doprint " ITERATE $repeat";
3475 }
3476 doprint "\n";
3477 }
3478
3479 foreach my $option (sort keys %opt) {
3480
3481 if ($option =~ /\[(\d+)\]$/) {
3482 next if ($i != $1);
3483 } else {
3484 next if ($i);
3485 }
3486
3487 doprint "$option = $opt{$option}\n";
3488 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003489}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003490
Steven Rostedt2a625122011-05-20 15:48:59 -04003491sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003492 my ($name, $i) = @_;
3493
3494 my $option = "$name\[$i\]";
3495
3496 if (defined($opt{$option})) {
3497 return $opt{$option};
3498 }
3499
Steven Rostedta57419b2010-11-02 15:13:54 -04003500 foreach my $test (keys %repeat_tests) {
3501 if ($i >= $test &&
3502 $i < $test + $repeat_tests{$test}) {
3503 $option = "$name\[$test\]";
3504 if (defined($opt{$option})) {
3505 return $opt{$option};
3506 }
3507 }
3508 }
3509
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003510 if (defined($opt{$name})) {
3511 return $opt{$name};
3512 }
3513
3514 return undef;
3515}
3516
Steven Rostedt2a625122011-05-20 15:48:59 -04003517sub set_test_option {
3518 my ($name, $i) = @_;
3519
3520 my $option = __set_test_option($name, $i);
3521 return $option if (!defined($option));
3522
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003523 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003524}
3525
Steven Rostedt2545eb62010-11-02 15:01:32 -04003526# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003527for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003528
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003529 # Do not reboot on failing test options
3530 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003531 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003532
Steven Rostedt683a3e62012-05-18 13:34:35 -04003533 $have_version = 0;
3534
Steven Rostedt576f6272010-11-02 14:58:38 -04003535 $iteration = $i;
3536
Steven Rostedta75fece2010-11-02 14:58:27 -04003537 my $makecmd = set_test_option("MAKE_CMD", $i);
3538
Steven Rostedt9cc9e092011-12-22 21:37:22 -05003539 # Load all the options into their mapped variable names
3540 foreach my $opt (keys %option_map) {
3541 ${$option_map{$opt}} = set_test_option($opt, $i);
3542 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003543
Steven Rostedt35ce5952011-07-15 21:57:25 -04003544 $start_minconfig_defined = 1;
3545
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003546 # The first test may override the PRE_KTEST option
3547 if (defined($pre_ktest) && $i == 1) {
3548 doprint "\n";
3549 run_command $pre_ktest;
3550 }
3551
3552 # Any test can override the POST_KTEST option
3553 # The last test takes precedence.
3554 if (defined($post_ktest)) {
3555 $final_post_ktest = $post_ktest;
3556 }
3557
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003558 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003559 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003560 $start_minconfig = $minconfig;
3561 }
3562
Steven Rostedta75fece2010-11-02 14:58:27 -04003563 chdir $builddir || die "can't change directory to $builddir";
3564
Andrew Jonesa908a662011-08-12 15:32:03 +02003565 foreach my $dir ($tmpdir, $outputdir) {
3566 if (!-d $dir) {
3567 mkpath($dir) or
3568 die "can't create $dir";
3569 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003570 }
3571
Steven Rostedte48c5292010-11-02 14:35:37 -04003572 $ENV{"SSH_USER"} = $ssh_user;
3573 $ENV{"MACHINE"} = $machine;
3574
Steven Rostedta75fece2010-11-02 14:58:27 -04003575 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303576 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003577 $dmesg = "$tmpdir/dmesg-$machine";
3578 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003579 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003580
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003581 if (!$buildonly) {
3582 $target = "$ssh_user\@$machine";
3583 if ($reboot_type eq "grub") {
3584 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003585 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003586 }
3587
3588 my $run_type = $build_type;
3589 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003590 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003591 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003592 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003593 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003594 $run_type = $config_bisect_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003595 }
3596
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003597 if ($test_type eq "make_min_config") {
3598 $run_type = "";
3599 }
3600
Steven Rostedta75fece2010-11-02 14:58:27 -04003601 # mistake in config file?
3602 if (!defined($run_type)) {
3603 $run_type = "ERROR";
3604 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003605
Steven Rostedte0a87422011-09-30 17:50:48 -04003606 my $installme = "";
3607 $installme = " no_install" if ($no_install);
3608
Steven Rostedt2545eb62010-11-02 15:01:32 -04003609 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003610 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003611
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003612 if (defined($pre_test)) {
3613 run_command $pre_test;
3614 }
3615
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003616 unlink $dmesg;
3617 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303618 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003619
Steven Rostedt250bae82011-07-15 22:05:59 -04003620 if (defined($addconfig)) {
3621 my $min = $minconfig;
3622 if (!defined($minconfig)) {
3623 $min = "";
3624 }
3625 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003626 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003627 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003628 }
3629
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003630 if (defined($checkout)) {
3631 run_command "git checkout $checkout" or
3632 die "failed to checkout $checkout";
3633 }
3634
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003635 $no_reboot = 0;
3636
Steven Rostedt648a1822012-03-21 11:18:27 -04003637 # A test may opt to not reboot the box
3638 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003639 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04003640 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003641
Steven Rostedta75fece2010-11-02 14:58:27 -04003642 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003643 bisect $i;
3644 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003645 } elsif ($test_type eq "config_bisect") {
3646 config_bisect $i;
3647 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003648 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003649 patchcheck $i;
3650 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003651 } elsif ($test_type eq "make_min_config") {
3652 make_min_config $i;
3653 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003654 }
3655
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003656 if ($build_type ne "nobuild") {
3657 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003658 }
3659
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003660 if ($test_type eq "install") {
3661 get_version;
3662 install;
3663 success $i;
3664 next;
3665 }
3666
Steven Rostedta75fece2010-11-02 14:58:27 -04003667 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003668 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003669 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003670
3671 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3672 do_run_test or $failed = 1;
3673 }
3674 end_monitor;
3675 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003676 }
3677
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003678 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003679}
3680
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003681if (defined($final_post_ktest)) {
3682 run_command $final_post_ktest;
3683}
3684
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003685if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003686 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003687} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003688 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04003689} elsif (defined($switch_to_good)) {
3690 # still need to get to the good kernel
3691 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003692}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003693
Steven Rostedt648a1822012-03-21 11:18:27 -04003694
Steven Rostedte48c5292010-11-02 14:35:37 -04003695doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3696
Steven Rostedt2545eb62010-11-02 15:01:32 -04003697exit 0;