blob: 6b1e0c5edc5b9be047b50c214f77c7854a9f30e3 [file] [log] [blame]
Steven Rostedt2545eb62010-11-02 15:01:32 -04001#!/usr/bin/perl -w
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002#
Uwe Kleine-Königcce1dac2011-01-24 21:12:01 +01003# Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04004# Licensed under the terms of the GNU GPL License version 2
5#
Steven Rostedt2545eb62010-11-02 15:01:32 -04006
7use strict;
8use IPC::Open2;
9use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
Steven Rostedt7faafbd2010-11-02 14:58:22 -040010use File::Path qw(mkpath);
11use File::Copy qw(cp);
Steven Rostedt2545eb62010-11-02 15:01:32 -040012use FileHandle;
13
Steven Rostedte48c5292010-11-02 14:35:37 -040014my $VERSION = "0.2";
15
Steven Rostedt2545eb62010-11-02 15:01:32 -040016$| = 1;
17
18my %opt;
Steven Rostedta57419b2010-11-02 15:13:54 -040019my %repeat_tests;
20my %repeats;
Steven Rostedt2545eb62010-11-02 15:01:32 -040021
22#default opts
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050023my %default = (
24 "NUM_TESTS" => 1,
25 "TEST_TYPE" => "build",
26 "BUILD_TYPE" => "randconfig",
27 "MAKE_CMD" => "make",
28 "TIMEOUT" => 120,
29 "TMP_DIR" => "/tmp/ktest/\${MACHINE}",
30 "SLEEP_TIME" => 60, # sleep time between tests
31 "BUILD_NOCLEAN" => 0,
32 "REBOOT_ON_ERROR" => 0,
33 "POWEROFF_ON_ERROR" => 0,
34 "REBOOT_ON_SUCCESS" => 1,
35 "POWEROFF_ON_SUCCESS" => 0,
36 "BUILD_OPTIONS" => "",
37 "BISECT_SLEEP_TIME" => 60, # sleep time between bisects
38 "PATCHCHECK_SLEEP_TIME" => 60, # sleep time between patch checks
39 "CLEAR_LOG" => 0,
40 "BISECT_MANUAL" => 0,
41 "BISECT_SKIP" => 1,
Steven Rostedtccc513b2012-05-21 17:13:40 -040042 "MIN_CONFIG_TYPE" => "boot",
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050043 "SUCCESS_LINE" => "login:",
44 "DETECT_TRIPLE_FAULT" => 1,
45 "NO_INSTALL" => 0,
46 "BOOTED_TIMEOUT" => 1,
47 "DIE_ON_FAILURE" => 1,
48 "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
49 "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
Steven Rostedt02ad2612012-03-21 08:21:24 -040050 "SCP_TO_TARGET_INSTALL" => "\${SCP_TO_TARGET}",
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050051 "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
52 "STOP_AFTER_SUCCESS" => 10,
53 "STOP_AFTER_FAILURE" => 60,
54 "STOP_TEST_AFTER" => 600,
Steven Rostedt407b95b2012-07-19 16:05:42 -040055 "MAX_MONITOR_WAIT" => 1800,
Steven Rostedta15ba912012-11-13 14:30:37 -050056 "GRUB_REBOOT" => "grub2-reboot",
Steven Rostedt77869542012-12-11 17:37:41 -050057 "SYSLINUX" => "extlinux",
58 "SYSLINUX_PATH" => "/boot/extlinux",
Steven Rostedt600bbf02011-11-21 20:12:04 -050059
60# required, and we will ask users if they don't have them but we keep the default
61# value something that is common.
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050062 "REBOOT_TYPE" => "grub",
63 "LOCALVERSION" => "-test",
64 "SSH_USER" => "root",
65 "BUILD_TARGET" => "arch/x86/boot/bzImage",
66 "TARGET_IMAGE" => "/boot/vmlinuz-test",
Steven Rostedt9cc9e092011-12-22 21:37:22 -050067
68 "LOG_FILE" => undef,
69 "IGNORE_UNUSED" => 0,
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050070);
Steven Rostedt2545eb62010-11-02 15:01:32 -040071
Steven Rostedt8d1491b2010-11-18 15:39:48 -050072my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040073my $version;
Steven Rostedt683a3e62012-05-18 13:34:35 -040074my $have_version = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040075my $machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040076my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040077my $tmpdir;
78my $builddir;
79my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050080my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040081my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040082my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040083my $build_options;
Steven Rostedt921ed4c2012-07-19 15:18:27 -040084my $final_post_ktest;
85my $pre_ktest;
86my $post_ktest;
87my $pre_test;
88my $post_test;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -040089my $pre_build;
90my $post_build;
91my $pre_build_die;
92my $post_build_die;
Steven Rostedta75fece2010-11-02 14:58:27 -040093my $reboot_type;
94my $reboot_script;
95my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040096my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -040097my $reboot_on_error;
Steven Rostedtbc7c5802011-12-22 16:29:10 -050098my $switch_to_good;
99my $switch_to_test;
Steven Rostedta75fece2010-11-02 14:58:27 -0400100my $poweroff_on_error;
Steven Rostedt648a1822012-03-21 11:18:27 -0400101my $reboot_on_success;
Steven Rostedta75fece2010-11-02 14:58:27 -0400102my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -0400103my $powercycle_after_reboot;
104my $poweroff_after_halt;
Steven Rostedt407b95b2012-07-19 16:05:42 -0400105my $max_monitor_wait;
Steven Rostedte48c5292010-11-02 14:35:37 -0400106my $ssh_exec;
107my $scp_to_target;
Steven Rostedt02ad2612012-03-21 08:21:24 -0400108my $scp_to_target_install;
Steven Rostedta75fece2010-11-02 14:58:27 -0400109my $power_off;
110my $grub_menu;
Steven Rostedta15ba912012-11-13 14:30:37 -0500111my $grub_file;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400112my $grub_number;
Steven Rostedta15ba912012-11-13 14:30:37 -0500113my $grub_reboot;
Steven Rostedt77869542012-12-11 17:37:41 -0500114my $syslinux;
115my $syslinux_path;
116my $syslinux_label;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400117my $target;
118my $make;
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400119my $pre_install;
Steven Rostedt8b37ca82010-11-02 14:58:33 -0400120my $post_install;
Steven Rostedte0a87422011-09-30 17:50:48 -0400121my $no_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400122my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400123my $minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400124my $start_minconfig;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400125my $start_minconfig_defined;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400126my $output_minconfig;
Steven Rostedtccc513b2012-05-21 17:13:40 -0400127my $minconfig_type;
Steven Rostedt43de3312012-05-21 23:35:12 -0400128my $use_output_minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400129my $ignore_config;
Steven Rostedtbe405f92012-01-04 21:51:59 -0500130my $ignore_errors;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400131my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400132my $in_bisect = 0;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500133my $bisect_bad_commit = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400134my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -0500135my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -0500136my $bisect_skip;
Steven Rostedt30f75da2011-06-13 10:35:35 -0400137my $config_bisect_good;
Steven Rostedtc5dacb82011-12-22 12:43:57 -0500138my $bisect_ret_good;
139my $bisect_ret_bad;
140my $bisect_ret_skip;
141my $bisect_ret_abort;
142my $bisect_ret_default;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400143my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400144my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400145my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400146my $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +0530147my $testlog;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400148my $dmesg;
149my $monitor_fp;
150my $monitor_pid;
151my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400152my $sleep_time;
153my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400154my $patchcheck_sleep_time;
Steven Rostedt19902072011-06-14 20:46:25 -0400155my $ignore_warnings;
Steven Rostedta75fece2010-11-02 14:58:27 -0400156my $store_failures;
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530157my $store_successes;
Steven Rostedt9064af52011-06-13 10:38:48 -0400158my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400159my $timeout;
160my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400161my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400162my $console;
Steven Rostedt2b803362011-09-30 18:00:23 -0400163my $reboot_success_line;
Steven Rostedta75fece2010-11-02 14:58:27 -0400164my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500165my $stop_after_success;
166my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500167my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400168my $build_target;
169my $target_image;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500170my $checkout;
Steven Rostedta75fece2010-11-02 14:58:27 -0400171my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400172my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400173my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400174
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500175my $bisect_good;
176my $bisect_bad;
177my $bisect_type;
178my $bisect_start;
179my $bisect_replay;
180my $bisect_files;
181my $bisect_reverse;
182my $bisect_check;
183
184my $config_bisect;
185my $config_bisect_type;
Steven Rostedtb0918612012-07-19 15:26:00 -0400186my $config_bisect_check;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500187
188my $patchcheck_type;
189my $patchcheck_start;
190my $patchcheck_end;
191
Steven Rostedt165708b2011-11-26 20:56:52 -0500192# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500193# which would require more options.
194my $buildonly = 1;
195
Steven Rostedtdbd37832011-11-23 16:00:48 -0500196# set when creating a new config
197my $newconfig = 0;
198
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500199my %entered_configs;
200my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400201my %variable;
Steven Rostedtcf79fab2012-07-19 15:29:43 -0400202
203# force_config is the list of configs that we force enabled (or disabled)
204# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400205my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500206
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400207# do not force reboots on config problems
208my $no_reboot = 1;
209
Steven Rostedt759a3cc2012-05-01 08:20:12 -0400210# reboot on success
211my $reboot_success = 0;
212
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500213my %option_map = (
214 "MACHINE" => \$machine,
215 "SSH_USER" => \$ssh_user,
216 "TMP_DIR" => \$tmpdir,
217 "OUTPUT_DIR" => \$outputdir,
218 "BUILD_DIR" => \$builddir,
219 "TEST_TYPE" => \$test_type,
Steven Rostedt921ed4c2012-07-19 15:18:27 -0400220 "PRE_KTEST" => \$pre_ktest,
221 "POST_KTEST" => \$post_ktest,
222 "PRE_TEST" => \$pre_test,
223 "POST_TEST" => \$post_test,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500224 "BUILD_TYPE" => \$build_type,
225 "BUILD_OPTIONS" => \$build_options,
226 "PRE_BUILD" => \$pre_build,
227 "POST_BUILD" => \$post_build,
228 "PRE_BUILD_DIE" => \$pre_build_die,
229 "POST_BUILD_DIE" => \$post_build_die,
230 "POWER_CYCLE" => \$power_cycle,
231 "REBOOT" => \$reboot,
232 "BUILD_NOCLEAN" => \$noclean,
233 "MIN_CONFIG" => \$minconfig,
234 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
235 "START_MIN_CONFIG" => \$start_minconfig,
Steven Rostedtccc513b2012-05-21 17:13:40 -0400236 "MIN_CONFIG_TYPE" => \$minconfig_type,
Steven Rostedt43de3312012-05-21 23:35:12 -0400237 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500238 "IGNORE_CONFIG" => \$ignore_config,
239 "TEST" => \$run_test,
240 "ADD_CONFIG" => \$addconfig,
241 "REBOOT_TYPE" => \$reboot_type,
242 "GRUB_MENU" => \$grub_menu,
Steven Rostedta15ba912012-11-13 14:30:37 -0500243 "GRUB_FILE" => \$grub_file,
244 "GRUB_REBOOT" => \$grub_reboot,
Steven Rostedt77869542012-12-11 17:37:41 -0500245 "SYSLINUX" => \$syslinux,
246 "SYSLINUX_PATH" => \$syslinux_path,
247 "SYSLINUX_LABEL" => \$syslinux_label,
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400248 "PRE_INSTALL" => \$pre_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500249 "POST_INSTALL" => \$post_install,
250 "NO_INSTALL" => \$no_install,
251 "REBOOT_SCRIPT" => \$reboot_script,
252 "REBOOT_ON_ERROR" => \$reboot_on_error,
253 "SWITCH_TO_GOOD" => \$switch_to_good,
254 "SWITCH_TO_TEST" => \$switch_to_test,
255 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
Steven Rostedt648a1822012-03-21 11:18:27 -0400256 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500257 "DIE_ON_FAILURE" => \$die_on_failure,
258 "POWER_OFF" => \$power_off,
259 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
260 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
Steven Rostedt407b95b2012-07-19 16:05:42 -0400261 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500262 "SLEEP_TIME" => \$sleep_time,
263 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
264 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
265 "IGNORE_WARNINGS" => \$ignore_warnings,
Steven Rostedtbe405f92012-01-04 21:51:59 -0500266 "IGNORE_ERRORS" => \$ignore_errors,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500267 "BISECT_MANUAL" => \$bisect_manual,
268 "BISECT_SKIP" => \$bisect_skip,
269 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
270 "BISECT_RET_GOOD" => \$bisect_ret_good,
271 "BISECT_RET_BAD" => \$bisect_ret_bad,
272 "BISECT_RET_SKIP" => \$bisect_ret_skip,
273 "BISECT_RET_ABORT" => \$bisect_ret_abort,
274 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
275 "STORE_FAILURES" => \$store_failures,
276 "STORE_SUCCESSES" => \$store_successes,
277 "TEST_NAME" => \$test_name,
278 "TIMEOUT" => \$timeout,
279 "BOOTED_TIMEOUT" => \$booted_timeout,
280 "CONSOLE" => \$console,
281 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
282 "SUCCESS_LINE" => \$success_line,
283 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
284 "STOP_AFTER_SUCCESS" => \$stop_after_success,
285 "STOP_AFTER_FAILURE" => \$stop_after_failure,
286 "STOP_TEST_AFTER" => \$stop_test_after,
287 "BUILD_TARGET" => \$build_target,
288 "SSH_EXEC" => \$ssh_exec,
289 "SCP_TO_TARGET" => \$scp_to_target,
Steven Rostedt02ad2612012-03-21 08:21:24 -0400290 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500291 "CHECKOUT" => \$checkout,
292 "TARGET_IMAGE" => \$target_image,
293 "LOCALVERSION" => \$localversion,
294
295 "BISECT_GOOD" => \$bisect_good,
296 "BISECT_BAD" => \$bisect_bad,
297 "BISECT_TYPE" => \$bisect_type,
298 "BISECT_START" => \$bisect_start,
299 "BISECT_REPLAY" => \$bisect_replay,
300 "BISECT_FILES" => \$bisect_files,
301 "BISECT_REVERSE" => \$bisect_reverse,
302 "BISECT_CHECK" => \$bisect_check,
303
304 "CONFIG_BISECT" => \$config_bisect,
305 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
Steven Rostedtb0918612012-07-19 15:26:00 -0400306 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500307
308 "PATCHCHECK_TYPE" => \$patchcheck_type,
309 "PATCHCHECK_START" => \$patchcheck_start,
310 "PATCHCHECK_END" => \$patchcheck_end,
311);
312
313# Options may be used by other options, record them.
314my %used_options;
315
Steven Rostedt7bf51072011-10-22 09:07:03 -0400316# default variables that can be used
317chomp ($variable{"PWD"} = `pwd`);
318
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500319$config_help{"MACHINE"} = << "EOF"
320 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500321 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500322EOF
323 ;
324$config_help{"SSH_USER"} = << "EOF"
325 The box is expected to have ssh on normal bootup, provide the user
326 (most likely root, since you need privileged operations)
327EOF
328 ;
329$config_help{"BUILD_DIR"} = << "EOF"
330 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500331 You can use \${PWD} that will be the path where ktest.pl is run, or use
332 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500333EOF
334 ;
335$config_help{"OUTPUT_DIR"} = << "EOF"
336 The directory that the objects will be built (full path).
337 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500338 You can use \${PWD} that will be the path where ktest.pl is run, or use
339 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500340EOF
341 ;
342$config_help{"BUILD_TARGET"} = << "EOF"
343 The location of the compiled file to copy to the target.
344 (relative to OUTPUT_DIR)
345EOF
346 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500347$config_help{"BUILD_OPTIONS"} = << "EOF"
348 Options to add to \"make\" when building.
349 i.e. -j20
350EOF
351 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500352$config_help{"TARGET_IMAGE"} = << "EOF"
353 The place to put your image on the test machine.
354EOF
355 ;
356$config_help{"POWER_CYCLE"} = << "EOF"
357 A script or command to reboot the box.
358
359 Here is a digital loggers power switch example
360 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
361
362 Here is an example to reboot a virtual box on the current host
363 with the name "Guest".
364 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
365EOF
366 ;
367$config_help{"CONSOLE"} = << "EOF"
368 The script or command that reads the console
369
370 If you use ttywatch server, something like the following would work.
371CONSOLE = nc -d localhost 3001
372
373 For a virtual machine with guest name "Guest".
374CONSOLE = virsh console Guest
375EOF
376 ;
377$config_help{"LOCALVERSION"} = << "EOF"
378 Required version ending to differentiate the test
379 from other linux builds on the system.
380EOF
381 ;
382$config_help{"REBOOT_TYPE"} = << "EOF"
383 Way to reboot the box to the test kernel.
Steven Rostedt77869542012-12-11 17:37:41 -0500384 Only valid options so far are "grub", "grub2", "syslinux", and "script".
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500385
386 If you specify grub, it will assume grub version 1
387 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
388 and select that target to reboot to the kernel. If this is not
389 your setup, then specify "script" and have a command or script
390 specified in REBOOT_SCRIPT to boot to the target.
391
392 The entry in /boot/grub/menu.lst must be entered in manually.
393 The test will not modify that file.
Steven Rostedta15ba912012-11-13 14:30:37 -0500394
395 If you specify grub2, then you also need to specify both \$GRUB_MENU
396 and \$GRUB_FILE.
Steven Rostedt77869542012-12-11 17:37:41 -0500397
398 If you specify syslinux, then you may use SYSLINUX to define the syslinux
399 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
400 the syslinux install (defaults to /boot/extlinux). But you have to specify
401 SYSLINUX_LABEL to define the label to boot to for the test kernel.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500402EOF
403 ;
404$config_help{"GRUB_MENU"} = << "EOF"
405 The grub title name for the test kernel to boot
Steven Rostedta15ba912012-11-13 14:30:37 -0500406 (Only mandatory if REBOOT_TYPE = grub or grub2)
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500407
408 Note, ktest.pl will not update the grub menu.lst, you need to
409 manually add an option for the test. ktest.pl will search
410 the grub menu.lst for this option to find what kernel to
411 reboot into.
412
413 For example, if in the /boot/grub/menu.lst the test kernel title has:
414 title Test Kernel
415 kernel vmlinuz-test
416 GRUB_MENU = Test Kernel
Steven Rostedta15ba912012-11-13 14:30:37 -0500417
418 For grub2, a search of \$GRUB_FILE is performed for the lines
419 that begin with "menuentry". It will not detect submenus. The
420 menu must be a non-nested menu. Add the quotes used in the menu
421 to guarantee your selection, as the first menuentry with the content
422 of \$GRUB_MENU that is found will be used.
423EOF
424 ;
425$config_help{"GRUB_FILE"} = << "EOF"
426 If grub2 is used, the full path for the grub.cfg file is placed
427 here. Use something like /boot/grub2/grub.cfg to search.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500428EOF
429 ;
Steven Rostedt77869542012-12-11 17:37:41 -0500430$config_help{"SYSLINUX_LABEL"} = << "EOF"
431 If syslinux is used, the label that boots the target kernel must
432 be specified with SYSLINUX_LABEL.
433EOF
434 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500435$config_help{"REBOOT_SCRIPT"} = << "EOF"
436 A script to reboot the target into the test kernel
437 (Only mandatory if REBOOT_TYPE = script)
438EOF
439 ;
440
Steven Rostedtdad98752011-11-22 20:48:57 -0500441sub read_prompt {
442 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400443
444 my $ans;
445
446 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500447 if ($cancel) {
448 print "$prompt [y/n/C] ";
449 } else {
450 print "$prompt [Y/n] ";
451 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400452 $ans = <STDIN>;
453 chomp $ans;
454 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500455 if ($cancel) {
456 $ans = "c";
457 } else {
458 $ans = "y";
459 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400460 }
461 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500462 if ($cancel) {
463 last if ($ans =~ /^c$/i);
464 print "Please answer either 'y', 'n' or 'c'.\n";
465 } else {
466 print "Please answer either 'y' or 'n'.\n";
467 }
468 }
469 if ($ans =~ /^c/i) {
470 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400471 }
472 if ($ans !~ /^y$/i) {
473 return 0;
474 }
475 return 1;
476}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500477
Steven Rostedtdad98752011-11-22 20:48:57 -0500478sub read_yn {
479 my ($prompt) = @_;
480
481 return read_prompt 0, $prompt;
482}
483
484sub read_ync {
485 my ($prompt) = @_;
486
487 return read_prompt 1, $prompt;
488}
489
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500490sub get_ktest_config {
491 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400492 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500493
494 return if (defined($opt{$config}));
495
496 if (defined($config_help{$config})) {
497 print "\n";
498 print $config_help{$config};
499 }
500
501 for (;;) {
502 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500503 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500504 print "\[$default{$config}\] ";
505 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400506 $ans = <STDIN>;
507 $ans =~ s/^\s*(.*\S)\s*$/$1/;
508 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500509 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400510 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500511 } else {
512 print "Your answer can not be blank\n";
513 next;
514 }
515 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500516 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500517 last;
518 }
519}
520
521sub get_ktest_configs {
522 get_ktest_config("MACHINE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500523 get_ktest_config("BUILD_DIR");
524 get_ktest_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500525
Steven Rostedtdbd37832011-11-23 16:00:48 -0500526 if ($newconfig) {
527 get_ktest_config("BUILD_OPTIONS");
528 }
529
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500530 # options required for other than just building a kernel
531 if (!$buildonly) {
Steven Rostedt165708b2011-11-26 20:56:52 -0500532 get_ktest_config("POWER_CYCLE");
533 get_ktest_config("CONSOLE");
534 }
535
536 # options required for install and more
537 if ($buildonly != 1) {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500538 get_ktest_config("SSH_USER");
539 get_ktest_config("BUILD_TARGET");
540 get_ktest_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500541 }
542
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500543 get_ktest_config("LOCALVERSION");
544
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500545 return if ($buildonly);
546
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500547 my $rtype = $opt{"REBOOT_TYPE"};
548
549 if (!defined($rtype)) {
550 if (!defined($opt{"GRUB_MENU"})) {
551 get_ktest_config("REBOOT_TYPE");
552 $rtype = $entered_configs{"REBOOT_TYPE"};
553 } else {
554 $rtype = "grub";
555 }
556 }
557
558 if ($rtype eq "grub") {
559 get_ktest_config("GRUB_MENU");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500560 }
Steven Rostedta15ba912012-11-13 14:30:37 -0500561
562 if ($rtype eq "grub2") {
563 get_ktest_config("GRUB_MENU");
564 get_ktest_config("GRUB_FILE");
565 }
Steven Rostedt77869542012-12-11 17:37:41 -0500566
567 if ($rtype eq "syslinux") {
568 get_ktest_config("SYSLINUX_LABEL");
569 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500570}
571
Steven Rostedt77d942c2011-05-20 13:36:58 -0400572sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400573 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400574 my $retval = "";
575
576 # We want to check for '\', and it is just easier
577 # to check the previous characet of '$' and not need
578 # to worry if '$' is the first character. By adding
579 # a space to $value, we can just check [^\\]\$ and
580 # it will still work.
581 $value = " $value";
582
583 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
584 my $begin = $1;
585 my $var = $2;
586 my $end = $3;
587 # append beginning of value to retval
588 $retval = "$retval$begin";
589 if (defined($variable{$var})) {
590 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400591 } elsif (defined($remove_undef) && $remove_undef) {
592 # for if statements, any variable that is not defined,
593 # we simple convert to 0
594 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400595 } else {
596 # put back the origin piece.
597 $retval = "$retval\$\{$var\}";
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500598 # This could be an option that is used later, save
599 # it so we don't warn if this option is not one of
600 # ktests options.
601 $used_options{$var} = 1;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400602 }
603 $value = $end;
604 }
605 $retval = "$retval$value";
606
607 # remove the space added in the beginning
608 $retval =~ s/ //;
609
610 return "$retval"
611}
612
Steven Rostedta57419b2010-11-02 15:13:54 -0400613sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400614 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400615
Steven Rostedtcad96662011-12-22 11:32:52 -0500616 my $prvalue = process_variables($rvalue);
617
618 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500619 # Note if a test is something other than build, then we
620 # will need other manditory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500621 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500622 $buildonly = 0;
623 } else {
624 # install still limits some manditory options.
625 $buildonly = 2;
626 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500627 }
628
Steven Rostedta57419b2010-11-02 15:13:54 -0400629 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400630 if (!$override || defined(${$overrides}{$lvalue})) {
631 my $extra = "";
632 if ($override) {
633 $extra = "In the same override section!\n";
634 }
635 die "$name: $.: Option $lvalue defined more than once!\n$extra";
636 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500637 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400638 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500639 if ($rvalue =~ /^\s*$/) {
640 delete $opt{$lvalue};
641 } else {
Steven Rostedtcad96662011-12-22 11:32:52 -0500642 $opt{$lvalue} = $prvalue;
Steven Rostedt21a96792010-11-08 16:45:50 -0500643 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400644}
645
Steven Rostedt77d942c2011-05-20 13:36:58 -0400646sub set_variable {
647 my ($lvalue, $rvalue) = @_;
648
649 if ($rvalue =~ /^\s*$/) {
650 delete $variable{$lvalue};
651 } else {
652 $rvalue = process_variables($rvalue);
653 $variable{$lvalue} = $rvalue;
654 }
655}
656
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400657sub process_compare {
658 my ($lval, $cmp, $rval) = @_;
659
660 # remove whitespace
661
662 $lval =~ s/^\s*//;
663 $lval =~ s/\s*$//;
664
665 $rval =~ s/^\s*//;
666 $rval =~ s/\s*$//;
667
668 if ($cmp eq "==") {
669 return $lval eq $rval;
670 } elsif ($cmp eq "!=") {
671 return $lval ne $rval;
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400672 } elsif ($cmp eq "=~") {
673 return $lval =~ m/$rval/;
674 } elsif ($cmp eq "!~") {
675 return $lval !~ m/$rval/;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400676 }
677
678 my $statement = "$lval $cmp $rval";
679 my $ret = eval $statement;
680
681 # $@ stores error of eval
682 if ($@) {
683 return -1;
684 }
685
686 return $ret;
687}
688
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400689sub value_defined {
690 my ($val) = @_;
691
692 return defined($variable{$2}) ||
693 defined($opt{$2});
694}
695
Steven Rostedt8d735212011-10-17 11:36:44 -0400696my $d = 0;
697sub process_expression {
698 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400699
Steven Rostedt8d735212011-10-17 11:36:44 -0400700 my $c = $d++;
701
702 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
703 my $express = $1;
704
705 if (process_expression($name, $express)) {
706 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
707 } else {
708 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
709 }
710 }
711
712 $d--;
713 my $OR = "\\|\\|";
714 my $AND = "\\&\\&";
715
716 while ($val =~ s/^(.*?)($OR|$AND)//) {
717 my $express = $1;
718 my $op = $2;
719
720 if (process_expression($name, $express)) {
721 if ($op eq "||") {
722 return 1;
723 }
724 } else {
725 if ($op eq "&&") {
726 return 0;
727 }
728 }
729 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400730
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400731 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400732 my $ret = process_compare($1, $2, $3);
733 if ($ret < 0) {
734 die "$name: $.: Unable to process comparison\n";
735 }
736 return $ret;
737 }
738
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400739 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
740 if (defined $1) {
741 return !value_defined($2);
742 } else {
743 return value_defined($2);
744 }
745 }
746
Steven Rostedt45d73a52011-09-30 19:44:53 -0400747 if ($val =~ /^\s*0\s*$/) {
748 return 0;
749 } elsif ($val =~ /^\s*\d+\s*$/) {
750 return 1;
751 }
752
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400753 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400754}
755
756sub process_if {
757 my ($name, $value) = @_;
758
759 # Convert variables and replace undefined ones with 0
760 my $val = process_variables($value, 1);
761 my $ret = process_expression $name, $val;
762
763 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400764}
765
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400766sub __read_config {
767 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400768
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400769 my $in;
770 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400771
Steven Rostedta57419b2010-11-02 15:13:54 -0400772 my $name = $config;
773 $name =~ s,.*/(.*),$1,;
774
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400775 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400776 my $default = 1;
777 my $repeat = 1;
778 my $num_tests_set = 0;
779 my $skip = 0;
780 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400781 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400782 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400783 my $if = 0;
784 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400785 my $override = 0;
786
787 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400788
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400789 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400790
791 # ignore blank lines and comments
792 next if (/^\s*$/ || /\s*\#/);
793
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400794 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400795
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400796 my $type = $1;
797 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400798 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400799
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400800 my $old_test_num;
801 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400802 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400803
804 if ($type eq "TEST_START") {
805
806 if ($num_tests_set) {
807 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
808 }
809
810 $old_test_num = $test_num;
811 $old_repeat = $repeat;
812
813 $test_num += $repeat;
814 $default = 0;
815 $repeat = 1;
816 } else {
817 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400818 }
819
Steven Rostedta9f84422011-10-17 11:06:29 -0400820 # If SKIP is anywhere in the line, the command will be skipped
821 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400822 $skip = 1;
823 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400824 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400825 $skip = 0;
826 }
827
Steven Rostedta9f84422011-10-17 11:06:29 -0400828 if ($rest =~ s/\sELSE\b//) {
829 if (!$if) {
830 die "$name: $.: ELSE found with out matching IF section\n$_";
831 }
832 $if = 0;
833
834 if ($if_set) {
835 $skip = 1;
836 } else {
837 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400838 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400839 }
840
Steven Rostedta9f84422011-10-17 11:06:29 -0400841 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400842 if (process_if($name, $1)) {
843 $if_set = 1;
844 } else {
845 $skip = 1;
846 }
847 $if = 1;
848 } else {
849 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400850 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400851 }
852
Steven Rostedta9f84422011-10-17 11:06:29 -0400853 if (!$skip) {
854 if ($type eq "TEST_START") {
855 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
856 $repeat = $1;
857 $repeat_tests{"$test_num"} = $repeat;
858 }
859 } elsif ($rest =~ s/\sOVERRIDE\b//) {
860 # DEFAULT only
861 $override = 1;
862 # Clear previous overrides
863 %overrides = ();
864 }
865 }
866
867 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400868 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400869 }
870
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400871 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400872 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400873 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400874 }
875
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400876 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400877 if (!$if) {
878 die "$name: $.: ELSE found with out matching IF section\n$_";
879 }
880 $rest = $1;
881 if ($if_set) {
882 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400883 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400884 } else {
885 $skip = 0;
886
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400887 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400888 # May be a ELSE IF section.
Steven Rostedt95f57832012-09-26 14:48:17 -0400889 if (process_if($name, $1)) {
890 $if_set = 1;
891 } else {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400892 $skip = 1;
893 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400894 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400895 } else {
896 $if = 0;
897 }
898 }
899
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400900 if ($rest !~ /^\s*$/) {
901 die "$name: $.: Gargbage found after DEFAULTS\n$_";
902 }
903
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400904 } elsif (/^\s*INCLUDE\s+(\S+)/) {
905
906 next if ($skip);
907
908 if (!$default) {
909 die "$name: $.: INCLUDE can only be done in default sections\n$_";
910 }
911
912 my $file = process_variables($1);
913
914 if ($file !~ m,^/,) {
915 # check the path of the config file first
916 if ($config =~ m,(.*)/,) {
917 if (-f "$1/$file") {
918 $file = "$1/$file";
919 }
920 }
921 }
922
923 if ( ! -r $file ) {
924 die "$name: $.: Can't read file $file\n$_";
925 }
926
927 if (__read_config($file, \$test_num)) {
928 $test_case = 1;
929 }
930
Steven Rostedta57419b2010-11-02 15:13:54 -0400931 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
932
933 next if ($skip);
934
Steven Rostedt2545eb62010-11-02 15:01:32 -0400935 my $lvalue = $1;
936 my $rvalue = $2;
937
Steven Rostedta57419b2010-11-02 15:13:54 -0400938 if (!$default &&
939 ($lvalue eq "NUM_TESTS" ||
940 $lvalue eq "LOG_FILE" ||
941 $lvalue eq "CLEAR_LOG")) {
942 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400943 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400944
945 if ($lvalue eq "NUM_TESTS") {
946 if ($test_num) {
947 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
948 }
949 if (!$default) {
950 die "$name: $.: NUM_TESTS must be set in default section\n";
951 }
952 $num_tests_set = 1;
953 }
954
955 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400956 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400957 } else {
958 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400959 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400960
961 if ($repeat > 1) {
962 $repeats{$val} = $repeat;
963 }
964 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400965 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
966 next if ($skip);
967
968 my $lvalue = $1;
969 my $rvalue = $2;
970
971 # process config variables.
972 # Config variables are only active while reading the
973 # config and can be defined anywhere. They also ignore
974 # TEST_START and DEFAULTS, but are skipped if they are in
975 # on of these sections that have SKIP defined.
976 # The save variable can be
977 # defined multiple times and the new one simply overrides
978 # the prevous one.
979 set_variable($lvalue, $rvalue);
980
Steven Rostedta57419b2010-11-02 15:13:54 -0400981 } else {
982 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400983 }
984 }
985
Steven Rostedta57419b2010-11-02 15:13:54 -0400986 if ($test_num) {
987 $test_num += $repeat - 1;
988 $opt{"NUM_TESTS"} = $test_num;
989 }
990
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400991 close($in);
992
993 $$current_test_num = $test_num;
994
995 return $test_case;
996}
997
Steven Rostedtc4261d02011-11-23 13:41:18 -0500998sub get_test_case {
999 print "What test case would you like to run?\n";
1000 print " (build, install or boot)\n";
1001 print " Other tests are available but require editing the config file\n";
1002 my $ans = <STDIN>;
1003 chomp $ans;
1004 $default{"TEST_TYPE"} = $ans;
1005}
1006
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001007sub read_config {
1008 my ($config) = @_;
1009
1010 my $test_case;
1011 my $test_num = 0;
1012
1013 $test_case = __read_config $config, \$test_num;
1014
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001015 # make sure we have all mandatory configs
1016 get_ktest_configs;
1017
Steven Rostedt0df213c2011-06-14 20:51:37 -04001018 # was a test specified?
1019 if (!$test_case) {
1020 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -05001021 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -04001022 }
1023
Steven Rostedta75fece2010-11-02 14:58:27 -04001024 # set any defaults
1025
1026 foreach my $default (keys %default) {
1027 if (!defined($opt{$default})) {
1028 $opt{$default} = $default{$default};
1029 }
1030 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -05001031
1032 if ($opt{"IGNORE_UNUSED"} == 1) {
1033 return;
1034 }
1035
1036 my %not_used;
1037
1038 # check if there are any stragglers (typos?)
1039 foreach my $option (keys %opt) {
1040 my $op = $option;
1041 # remove per test labels.
1042 $op =~ s/\[.*\]//;
1043 if (!exists($option_map{$op}) &&
1044 !exists($default{$op}) &&
1045 !exists($used_options{$op})) {
1046 $not_used{$op} = 1;
1047 }
1048 }
1049
1050 if (%not_used) {
1051 my $s = "s are";
1052 $s = " is" if (keys %not_used == 1);
1053 print "The following option$s not used; could be a typo:\n";
1054 foreach my $option (keys %not_used) {
1055 print "$option\n";
1056 }
1057 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1058 if (!read_yn "Do you want to continue?") {
1059 exit -1;
1060 }
1061 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001062}
1063
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001064sub __eval_option {
1065 my ($option, $i) = @_;
1066
1067 # Add space to evaluate the character before $
1068 $option = " $option";
1069 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301070 my $repeated = 0;
1071 my $parent = 0;
1072
1073 foreach my $test (keys %repeat_tests) {
1074 if ($i >= $test &&
1075 $i < $test + $repeat_tests{$test}) {
1076
1077 $repeated = 1;
1078 $parent = $test;
1079 last;
1080 }
1081 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001082
1083 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1084 my $start = $1;
1085 my $var = $2;
1086 my $end = $3;
1087
1088 # Append beginning of line
1089 $retval = "$retval$start";
1090
1091 # If the iteration option OPT[$i] exists, then use that.
1092 # otherwise see if the default OPT (without [$i]) exists.
1093
1094 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301095 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001096
1097 if (defined($opt{$o})) {
1098 $o = $opt{$o};
1099 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301100 } elsif ($repeated && defined($opt{$parento})) {
1101 $o = $opt{$parento};
1102 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001103 } elsif (defined($opt{$var})) {
1104 $o = $opt{$var};
1105 $retval = "$retval$o";
1106 } else {
1107 $retval = "$retval\$\{$var\}";
1108 }
1109
1110 $option = $end;
1111 }
1112
1113 $retval = "$retval$option";
1114
1115 $retval =~ s/^ //;
1116
1117 return $retval;
1118}
1119
1120sub eval_option {
1121 my ($option, $i) = @_;
1122
1123 my $prev = "";
1124
1125 # Since an option can evaluate to another option,
1126 # keep iterating until we do not evaluate any more
1127 # options.
1128 my $r = 0;
1129 while ($prev ne $option) {
1130 # Check for recursive evaluations.
1131 # 100 deep should be more than enough.
1132 if ($r++ > 100) {
1133 die "Over 100 evaluations accurred with $option\n" .
1134 "Check for recursive variables\n";
1135 }
1136 $prev = $option;
1137 $option = __eval_option($option, $i);
1138 }
1139
1140 return $option;
1141}
1142
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001143sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001144 if (defined($opt{"LOG_FILE"})) {
1145 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1146 print OUT @_;
1147 close(OUT);
1148 }
1149}
1150
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001151sub logit {
1152 if (defined($opt{"LOG_FILE"})) {
1153 _logit @_;
1154 } else {
1155 print @_;
1156 }
1157}
1158
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001159sub doprint {
1160 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001161 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001162}
1163
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001164sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001165sub start_monitor;
1166sub end_monitor;
1167sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001168
1169sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001170 my ($time) = @_;
1171
Steven Rostedta4968722012-12-11 14:59:05 -05001172 # Make sure everything has been written to disk
1173 run_ssh("sync");
1174
Steven Rostedt2b803362011-09-30 18:00:23 -04001175 if (defined($time)) {
1176 start_monitor;
1177 # flush out current monitor
1178 # May contain the reboot success line
1179 wait_for_monitor 1;
1180 }
1181
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001182 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001183 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001184 if (defined($powercycle_after_reboot)) {
1185 sleep $powercycle_after_reboot;
1186 run_command "$power_cycle";
1187 }
1188 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001189 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001190 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001191 }
Andrew Jones2728be42011-08-12 15:32:05 +02001192
1193 if (defined($time)) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001194 if (wait_for_monitor($time, $reboot_success_line)) {
1195 # reboot got stuck?
Steven Rostedt8a80c722012-07-19 16:08:33 -04001196 doprint "Reboot did not finish. Forcing power cycle\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001197 run_command "$power_cycle";
1198 }
Andrew Jones2728be42011-08-12 15:32:05 +02001199 end_monitor;
1200 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001201}
1202
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001203sub reboot_to_good {
1204 my ($time) = @_;
1205
1206 if (defined($switch_to_good)) {
1207 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001208 }
1209
1210 reboot $time;
1211}
1212
Steven Rostedt576f6272010-11-02 14:58:38 -04001213sub do_not_reboot {
1214 my $i = $iteration;
1215
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001216 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001217 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1218 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1219}
1220
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001221sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001222 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001223
Steven Rostedt576f6272010-11-02 14:58:38 -04001224 my $i = $iteration;
1225
1226 if ($reboot_on_error && !do_not_reboot) {
1227
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001228 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001229 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001230
Steven Rostedta75fece2010-11-02 14:58:27 -04001231 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001232 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001233 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001234 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001235
Steven Rostedtf80802c2011-03-07 13:18:47 -05001236 if (defined($opt{"LOG_FILE"})) {
1237 print " See $opt{LOG_FILE} for more info.\n";
1238 }
1239
Steven Rostedt576f6272010-11-02 14:58:38 -04001240 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001241}
1242
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001243sub open_console {
1244 my ($fp) = @_;
1245
1246 my $flags;
1247
Steven Rostedta75fece2010-11-02 14:58:27 -04001248 my $pid = open($fp, "$console|") or
1249 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001250
1251 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001252 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001253 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001254 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001255
1256 return $pid;
1257}
1258
1259sub close_console {
1260 my ($fp, $pid) = @_;
1261
1262 doprint "kill child process $pid\n";
1263 kill 2, $pid;
1264
1265 print "closing!\n";
1266 close($fp);
1267}
1268
1269sub start_monitor {
1270 if ($monitor_cnt++) {
1271 return;
1272 }
1273 $monitor_fp = \*MONFD;
1274 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001275
1276 return;
1277
1278 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001279}
1280
1281sub end_monitor {
1282 if (--$monitor_cnt) {
1283 return;
1284 }
1285 close_console($monitor_fp, $monitor_pid);
1286}
1287
1288sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001289 my ($time, $stop) = @_;
1290 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001291 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001292 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001293 my $start_time = time;
Steven Rostedt8a80c722012-07-19 16:08:33 -04001294 my $skip_call_trace = 0;
1295 my $bug = 0;
1296 my $bug_ignored = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001297 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001298
Steven Rostedta75fece2010-11-02 14:58:27 -04001299 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001300
1301 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001302 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001303 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001304 last if (!defined($line));
1305 print "$line";
1306 $full_line .= $line;
1307
1308 if (defined($stop) && $full_line =~ /$stop/) {
1309 doprint "wait for monitor detected $stop\n";
1310 $booted = 1;
1311 }
1312
Steven Rostedt8a80c722012-07-19 16:08:33 -04001313 if ($full_line =~ /\[ backtrace testing \]/) {
1314 $skip_call_trace = 1;
1315 }
1316
1317 if ($full_line =~ /call trace:/i) {
1318 if (!$bug && !$skip_call_trace) {
1319 if ($ignore_errors) {
1320 $bug_ignored = 1;
1321 } else {
1322 $bug = 1;
1323 }
1324 }
1325 }
1326
1327 if ($full_line =~ /\[ end of backtrace testing \]/) {
1328 $skip_call_trace = 0;
1329 }
1330
1331 if ($full_line =~ /Kernel panic -/) {
1332 $bug = 1;
1333 }
1334
Steven Rostedt2b803362011-09-30 18:00:23 -04001335 if ($line =~ /\n/) {
1336 $full_line = "";
1337 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001338 $now = time;
1339 if ($now - $start_time >= $max_monitor_wait) {
1340 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1341 return 1;
1342 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001343 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001344 print "** Monitor flushed **\n";
Steven Rostedt8a80c722012-07-19 16:08:33 -04001345 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001346}
1347
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301348sub save_logs {
1349 my ($result, $basedir) = @_;
1350 my @t = localtime;
1351 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1352 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1353
1354 my $type = $build_type;
1355 if ($type =~ /useconfig/) {
1356 $type = "useconfig";
1357 }
1358
1359 my $dir = "$machine-$test_type-$type-$result-$date";
1360
1361 $dir = "$basedir/$dir";
1362
1363 if (!-d $dir) {
1364 mkpath($dir) or
1365 die "can't create $dir";
1366 }
1367
1368 my %files = (
1369 "config" => $output_config,
1370 "buildlog" => $buildlog,
1371 "dmesg" => $dmesg,
1372 "testlog" => $testlog,
1373 );
1374
1375 while (my ($name, $source) = each(%files)) {
1376 if (-f "$source") {
1377 cp "$source", "$dir/$name" or
1378 die "failed to copy $source";
1379 }
1380 }
1381
1382 doprint "*** Saved info to $dir ***\n";
1383}
1384
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001385sub fail {
1386
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001387 if (defined($post_test)) {
1388 run_command $post_test;
1389 }
1390
Steven Rostedta75fece2010-11-02 14:58:27 -04001391 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001392 dodie @_;
1393 }
1394
Steven Rostedta75fece2010-11-02 14:58:27 -04001395 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001396
Steven Rostedt576f6272010-11-02 14:58:38 -04001397 my $i = $iteration;
1398
Steven Rostedta75fece2010-11-02 14:58:27 -04001399 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001400 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001401 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001402 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001403 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001404
Steven Rostedt9064af52011-06-13 10:38:48 -04001405 my $name = "";
1406
1407 if (defined($test_name)) {
1408 $name = " ($test_name)";
1409 }
1410
Steven Rostedt576f6272010-11-02 14:58:38 -04001411 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1412 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001413 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001414 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1415 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001416
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301417 if (defined($store_failures)) {
1418 save_logs "fail", $store_failures;
1419 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001420
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001421 return 1;
1422}
1423
Steven Rostedt2545eb62010-11-02 15:01:32 -04001424sub run_command {
1425 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001426 my $dolog = 0;
1427 my $dord = 0;
1428 my $pid;
1429
Steven Rostedte48c5292010-11-02 14:35:37 -04001430 $command =~ s/\$SSH_USER/$ssh_user/g;
1431 $command =~ s/\$MACHINE/$machine/g;
1432
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001433 doprint("$command ... ");
1434
1435 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001436 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001437
1438 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001439 open(LOG, ">>$opt{LOG_FILE}") or
1440 dodie "failed to write to log";
1441 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001442 }
1443
1444 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001445 open (RD, ">$redirect") or
1446 dodie "failed to write to redirect $redirect";
1447 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001448 }
1449
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001450 while (<CMD>) {
1451 print LOG if ($dolog);
1452 print RD if ($dord);
1453 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001454
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001455 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001456 my $failed = $?;
1457
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001458 close(CMD);
1459 close(LOG) if ($dolog);
1460 close(RD) if ($dord);
1461
Steven Rostedt2545eb62010-11-02 15:01:32 -04001462 if ($failed) {
1463 doprint "FAILED!\n";
1464 } else {
1465 doprint "SUCCESS\n";
1466 }
1467
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001468 return !$failed;
1469}
1470
Steven Rostedte48c5292010-11-02 14:35:37 -04001471sub run_ssh {
1472 my ($cmd) = @_;
1473 my $cp_exec = $ssh_exec;
1474
1475 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1476 return run_command "$cp_exec";
1477}
1478
1479sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001480 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001481
1482 $cp_scp =~ s/\$SRC_FILE/$src/g;
1483 $cp_scp =~ s/\$DST_FILE/$dst/g;
1484
1485 return run_command "$cp_scp";
1486}
1487
Steven Rostedt02ad2612012-03-21 08:21:24 -04001488sub run_scp_install {
1489 my ($src, $dst) = @_;
1490
1491 my $cp_scp = $scp_to_target_install;
1492
1493 return run_scp($src, $dst, $cp_scp);
1494}
1495
1496sub run_scp_mod {
1497 my ($src, $dst) = @_;
1498
1499 my $cp_scp = $scp_to_target;
1500
1501 return run_scp($src, $dst, $cp_scp);
1502}
1503
Steven Rostedta15ba912012-11-13 14:30:37 -05001504sub get_grub2_index {
1505
1506 return if (defined($grub_number));
1507
1508 doprint "Find grub2 menu ... ";
1509 $grub_number = -1;
1510
1511 my $ssh_grub = $ssh_exec;
1512 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1513
1514 open(IN, "$ssh_grub |")
1515 or die "unable to get $grub_file";
1516
1517 my $found = 0;
1518
1519 while (<IN>) {
1520 if (/^menuentry.*$grub_menu/) {
1521 $grub_number++;
1522 $found = 1;
1523 last;
1524 } elsif (/^menuentry\s/) {
1525 $grub_number++;
1526 }
1527 }
1528 close(IN);
1529
1530 die "Could not find '$grub_menu' in $grub_file on $machine"
1531 if (!$found);
1532 doprint "$grub_number\n";
1533}
1534
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001535sub get_grub_index {
1536
Steven Rostedta15ba912012-11-13 14:30:37 -05001537 if ($reboot_type eq "grub2") {
1538 get_grub2_index;
1539 return;
1540 }
1541
Steven Rostedta75fece2010-11-02 14:58:27 -04001542 if ($reboot_type ne "grub") {
1543 return;
1544 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001545 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001546
1547 doprint "Find grub menu ... ";
1548 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001549
1550 my $ssh_grub = $ssh_exec;
1551 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1552
1553 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001554 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001555
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001556 my $found = 0;
1557
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001558 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001559 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001560 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001561 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001562 last;
1563 } elsif (/^\s*title\s/) {
1564 $grub_number++;
1565 }
1566 }
1567 close(IN);
1568
Steven Rostedta75fece2010-11-02 14:58:27 -04001569 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001570 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001571 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001572}
1573
Steven Rostedt2545eb62010-11-02 15:01:32 -04001574sub wait_for_input
1575{
1576 my ($fp, $time) = @_;
1577 my $rin;
1578 my $ready;
1579 my $line;
1580 my $ch;
1581
1582 if (!defined($time)) {
1583 $time = $timeout;
1584 }
1585
1586 $rin = '';
1587 vec($rin, fileno($fp), 1) = 1;
1588 $ready = select($rin, undef, undef, $time);
1589
1590 $line = "";
1591
1592 # try to read one char at a time
1593 while (sysread $fp, $ch, 1) {
1594 $line .= $ch;
1595 last if ($ch eq "\n");
1596 }
1597
1598 if (!length($line)) {
1599 return undef;
1600 }
1601
1602 return $line;
1603}
1604
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001605sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001606 if (defined($switch_to_test)) {
1607 run_command $switch_to_test;
1608 }
1609
Steven Rostedta75fece2010-11-02 14:58:27 -04001610 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001611 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedta15ba912012-11-13 14:30:37 -05001612 } elsif ($reboot_type eq "grub2") {
1613 run_ssh "$grub_reboot $grub_number";
Steven Rostedt77869542012-12-11 17:37:41 -05001614 } elsif ($reboot_type eq "syslinux") {
1615 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001616 } elsif (defined $reboot_script) {
1617 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001618 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001619 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001620}
1621
Steven Rostedta57419b2010-11-02 15:13:54 -04001622sub get_sha1 {
1623 my ($commit) = @_;
1624
1625 doprint "git rev-list --max-count=1 $commit ... ";
1626 my $sha1 = `git rev-list --max-count=1 $commit`;
1627 my $ret = $?;
1628
1629 logit $sha1;
1630
1631 if ($ret) {
1632 doprint "FAILED\n";
1633 dodie "Failed to get git $commit";
1634 }
1635
1636 print "SUCCESS\n";
1637
1638 chomp $sha1;
1639
1640 return $sha1;
1641}
1642
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001643sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001644 my $booted = 0;
1645 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001646 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001647 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001648 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001649
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001650 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001651
1652 my $line;
1653 my $full_line = "";
1654
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001655 open(DMESG, "> $dmesg") or
1656 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001657
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001658 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001659
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001660 my $success_start;
1661 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001662 my $monitor_start = time;
1663 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001664 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001665
Steven Rostedt2d01b262011-03-08 09:47:54 -05001666 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001667
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001668 if ($bug && defined($stop_after_failure) &&
1669 $stop_after_failure >= 0) {
1670 my $time = $stop_after_failure - (time - $failure_start);
1671 $line = wait_for_input($monitor_fp, $time);
1672 if (!defined($line)) {
1673 doprint "bug timed out after $booted_timeout seconds\n";
1674 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1675 last;
1676 }
1677 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001678 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001679 if (!defined($line)) {
1680 my $s = $booted_timeout == 1 ? "" : "s";
1681 doprint "Successful boot found: break after $booted_timeout second$s\n";
1682 last;
1683 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001684 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001685 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001686 if (!defined($line)) {
1687 my $s = $timeout == 1 ? "" : "s";
1688 doprint "Timed out after $timeout second$s\n";
1689 last;
1690 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001691 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001692
Steven Rostedt2545eb62010-11-02 15:01:32 -04001693 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001694 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001695
1696 # we are not guaranteed to get a full line
1697 $full_line .= $line;
1698
Steven Rostedta75fece2010-11-02 14:58:27 -04001699 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001700 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001701 $success_start = time;
1702 }
1703
1704 if ($booted && defined($stop_after_success) &&
1705 $stop_after_success >= 0) {
1706 my $now = time;
1707 if ($now - $success_start >= $stop_after_success) {
1708 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1709 last;
1710 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001711 }
1712
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001713 if ($full_line =~ /\[ backtrace testing \]/) {
1714 $skip_call_trace = 1;
1715 }
1716
Steven Rostedt2545eb62010-11-02 15:01:32 -04001717 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001718 if (!$bug && !$skip_call_trace) {
1719 if ($ignore_errors) {
1720 $bug_ignored = 1;
1721 } else {
1722 $bug = 1;
1723 $failure_start = time;
1724 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001725 }
1726 }
1727
1728 if ($bug && defined($stop_after_failure) &&
1729 $stop_after_failure >= 0) {
1730 my $now = time;
1731 if ($now - $failure_start >= $stop_after_failure) {
1732 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1733 last;
1734 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001735 }
1736
1737 if ($full_line =~ /\[ end of backtrace testing \]/) {
1738 $skip_call_trace = 0;
1739 }
1740
1741 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001742 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001743 $bug = 1;
1744 }
1745
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001746 # Detect triple faults by testing the banner
1747 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1748 if ($1 eq $version) {
1749 $version_found = 1;
1750 } elsif ($version_found && $detect_triplefault) {
1751 # We already booted into the kernel we are testing,
1752 # but now we booted into another kernel?
1753 # Consider this a triple fault.
1754 doprint "Aleady booted in Linux kernel $version, but now\n";
1755 doprint "we booted into Linux kernel $1.\n";
1756 doprint "Assuming that this is a triple fault.\n";
1757 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1758 last;
1759 }
1760 }
1761
Steven Rostedt2545eb62010-11-02 15:01:32 -04001762 if ($line =~ /\n/) {
1763 $full_line = "";
1764 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001765
1766 if ($stop_test_after > 0 && !$booted && !$bug) {
1767 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001768 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001769 $done = 1;
1770 }
1771 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001772 }
1773
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001774 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001775
Steven Rostedt2545eb62010-11-02 15:01:32 -04001776 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001777 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001778 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001779 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001780
Steven Rostedta75fece2010-11-02 14:58:27 -04001781 if (!$booted) {
1782 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001783 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001784 }
1785
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001786 if ($bug_ignored) {
1787 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1788 }
1789
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001790 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001791}
1792
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001793sub eval_kernel_version {
1794 my ($option) = @_;
1795
1796 $option =~ s/\$KERNEL_VERSION/$version/g;
1797
1798 return $option;
1799}
1800
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001801sub do_post_install {
1802
1803 return if (!defined($post_install));
1804
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001805 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001806 run_command "$cp_post_install" or
1807 dodie "Failed to run post install";
1808}
1809
Steven Rostedt2545eb62010-11-02 15:01:32 -04001810sub install {
1811
Steven Rostedte0a87422011-09-30 17:50:48 -04001812 return if ($no_install);
1813
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001814 if (defined($pre_install)) {
1815 my $cp_pre_install = eval_kernel_version $pre_install;
1816 run_command "$cp_pre_install" or
1817 dodie "Failed to run pre install";
1818 }
1819
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001820 my $cp_target = eval_kernel_version $target_image;
1821
Steven Rostedt02ad2612012-03-21 08:21:24 -04001822 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001823 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001824
1825 my $install_mods = 0;
1826
1827 # should we process modules?
1828 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001829 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001830 while (<IN>) {
1831 if (/CONFIG_MODULES(=y)?/) {
Steven Rostedt8bc5e4e2012-10-26 00:10:32 -04001832 if (defined($1)) {
1833 $install_mods = 1;
1834 last;
1835 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001836 }
1837 }
1838 close(IN);
1839
1840 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001841 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001842 doprint "No modules needed\n";
1843 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001844 }
1845
Steven Rostedt627977d2012-03-21 08:16:15 -04001846 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001847 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001848
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001849 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001850 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001851
Steven Rostedte48c5292010-11-02 14:35:37 -04001852 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001853 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001854
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001855 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001856 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001857 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001858
Steven Rostedt02ad2612012-03-21 08:21:24 -04001859 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001860 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001861
Steven Rostedta75fece2010-11-02 14:58:27 -04001862 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001863
Steven Rostedte7b13442011-06-14 20:44:36 -04001864 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001865 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001866
Steven Rostedte48c5292010-11-02 14:35:37 -04001867 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001868
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001869 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001870}
1871
Steven Rostedtddf607e2011-06-14 20:49:13 -04001872sub get_version {
1873 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04001874 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001875 doprint "$make kernelrelease ... ";
1876 $version = `$make kernelrelease | tail -1`;
1877 chomp($version);
1878 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04001879 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04001880}
1881
1882sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001883 # Make sure the stable kernel has finished booting
1884 start_monitor;
1885 wait_for_monitor 5;
1886 end_monitor;
1887
Steven Rostedtddf607e2011-06-14 20:49:13 -04001888 get_grub_index;
1889 get_version;
1890 install;
1891
1892 start_monitor;
1893 return monitor;
1894}
1895
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001896sub check_buildlog {
1897 my ($patch) = @_;
1898
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001899 my @files = `git show $patch | diffstat -l`;
1900
1901 open(IN, "git show $patch |") or
1902 dodie "failed to show $patch";
1903 while (<IN>) {
1904 if (m,^--- a/(.*),) {
1905 chomp $1;
1906 $files[$#files] = $1;
1907 }
1908 }
1909 close(IN);
1910
1911 open(IN, $buildlog) or dodie "Can't open $buildlog";
1912 while (<IN>) {
1913 if (/^\s*(.*?):.*(warning|error)/) {
1914 my $err = $1;
1915 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001916 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001917 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001918 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001919 }
1920 }
1921 }
1922 }
1923 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001924
1925 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001926}
1927
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001928sub apply_min_config {
1929 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001930
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001931 # Read the config file and remove anything that
1932 # is in the force_config hash (from minconfig and others)
1933 # then add the force config back.
1934
1935 doprint "Applying minimum configurations into $output_config.new\n";
1936
1937 open (OUT, ">$outconfig") or
1938 dodie "Can't create $outconfig";
1939
1940 if (-f $output_config) {
1941 open (IN, $output_config) or
1942 dodie "Failed to open $output_config";
1943 while (<IN>) {
1944 if (/^(# )?(CONFIG_[^\s=]*)/) {
1945 next if (defined($force_config{$2}));
1946 }
1947 print OUT;
1948 }
1949 close IN;
1950 }
1951 foreach my $config (keys %force_config) {
1952 print OUT "$force_config{$config}\n";
1953 }
1954 close OUT;
1955
1956 run_command "mv $outconfig $output_config";
1957}
1958
1959sub make_oldconfig {
1960
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001961 my @force_list = keys %force_config;
1962
1963 if ($#force_list >= 0) {
1964 apply_min_config;
1965 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001966
Adam Leefb16d892012-09-01 01:05:17 +08001967 if (!run_command "$make olddefconfig") {
1968 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt18925172012-12-11 20:16:03 -05001969 # try oldnoconfig
1970 doprint "olddefconfig failed, trying make oldnoconfig\n";
1971 if (!run_command "$make oldnoconfig") {
1972 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1973 # try a yes '' | oldconfig
1974 run_command "yes '' | $make oldconfig" or
1975 dodie "failed make config oldconfig";
1976 }
Steven Rostedt612b9e92011-03-07 13:27:43 -05001977 }
1978}
1979
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001980# read a config file and use this to force new configs.
1981sub load_force_config {
1982 my ($config) = @_;
1983
Steven Rostedtcf79fab2012-07-19 15:29:43 -04001984 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001985 open(IN, $config) or
1986 dodie "failed to read $config";
1987 while (<IN>) {
1988 chomp;
1989 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1990 $force_config{$1} = $_;
1991 } elsif (/^# (CONFIG_\S*) is not set/) {
1992 $force_config{$1} = $_;
1993 }
1994 }
1995 close IN;
1996}
1997
Steven Rostedt2545eb62010-11-02 15:01:32 -04001998sub build {
1999 my ($type) = @_;
2000
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002001 unlink $buildlog;
2002
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002003 # Failed builds should not reboot the target
2004 my $save_no_reboot = $no_reboot;
2005 $no_reboot = 1;
2006
Steven Rostedt683a3e62012-05-18 13:34:35 -04002007 # Calculate a new version from here.
2008 $have_version = 0;
2009
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002010 if (defined($pre_build)) {
2011 my $ret = run_command $pre_build;
2012 if (!$ret && defined($pre_build_die) &&
2013 $pre_build_die) {
2014 dodie "failed to pre_build\n";
2015 }
2016 }
2017
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002018 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002019 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002020 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002021
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002022 $type = "oldconfig";
2023 }
2024
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002025 # old config can ask questions
2026 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08002027 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002028
2029 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002030 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002031
Andrew Jones13488232011-08-12 15:32:04 +02002032 if (!$noclean) {
2033 run_command "mv $output_config $outputdir/config_temp" or
2034 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002035
Andrew Jones13488232011-08-12 15:32:04 +02002036 run_command "$make mrproper" or dodie "make mrproper";
2037
2038 run_command "mv $outputdir/config_temp $output_config" or
2039 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002040 }
2041
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002042 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002043 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002044 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002045 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002046 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002047
2048 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04002049 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2050 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002051 close(OUT);
2052
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002053 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002054 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002055 }
2056
Adam Leefb16d892012-09-01 01:05:17 +08002057 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002058 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05002059 dodie "failed make config";
2060 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002061 # Run old config regardless, to enforce min configurations
2062 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002063
Steven Rostedta75fece2010-11-02 14:58:27 -04002064 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002065 my $build_ret = run_command "$make $build_options";
2066 undef $redirect;
2067
2068 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04002069 # Because a post build may change the kernel version
2070 # do it now.
2071 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002072 my $ret = run_command $post_build;
2073 if (!$ret && defined($post_build_die) &&
2074 $post_build_die) {
2075 dodie "failed to post_build\n";
2076 }
2077 }
2078
2079 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002080 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002081 if ($in_bisect) {
2082 $no_reboot = $save_no_reboot;
2083 return 0;
2084 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002085 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002086 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002087
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002088 $no_reboot = $save_no_reboot;
2089
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002090 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002091}
2092
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002093sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04002094 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002095 if (defined($poweroff_after_halt)) {
2096 sleep $poweroff_after_halt;
2097 run_command "$power_off";
2098 }
2099 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002100 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04002101 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002102 }
2103}
2104
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002105sub success {
2106 my ($i) = @_;
2107
Steven Rostedt921ed4c2012-07-19 15:18:27 -04002108 if (defined($post_test)) {
2109 run_command $post_test;
2110 }
2111
Steven Rostedte48c5292010-11-02 14:35:37 -04002112 $successes++;
2113
Steven Rostedt9064af52011-06-13 10:38:48 -04002114 my $name = "";
2115
2116 if (defined($test_name)) {
2117 $name = " ($test_name)";
2118 }
2119
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002120 doprint "\n\n*******************************************\n";
2121 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04002122 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002123 doprint "*******************************************\n";
2124 doprint "*******************************************\n";
2125
Rabin Vincentde5b6e32011-11-18 17:05:31 +05302126 if (defined($store_successes)) {
2127 save_logs "success", $store_successes;
2128 }
2129
Steven Rostedt576f6272010-11-02 14:58:38 -04002130 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002131 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002132 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002133 }
2134}
2135
Steven Rostedtc960bb92011-03-08 09:22:39 -05002136sub answer_bisect {
2137 for (;;) {
2138 doprint "Pass or fail? [p/f]";
2139 my $ans = <STDIN>;
2140 chomp $ans;
2141 if ($ans eq "p" || $ans eq "P") {
2142 return 1;
2143 } elsif ($ans eq "f" || $ans eq "F") {
2144 return 0;
2145 } else {
2146 print "Please answer 'P' or 'F'\n";
2147 }
2148 }
2149}
2150
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002151sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002152 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002153
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002154 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002155 $reboot_on_error = 0;
2156 $poweroff_on_error = 0;
2157 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002158
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302159 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002160 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302161 undef $redirect;
2162
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002163 exit $failed;
2164}
2165
2166my $child_done;
2167
2168sub child_finished {
2169 $child_done = 1;
2170}
2171
2172sub do_run_test {
2173 my $child_pid;
2174 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002175 my $line;
2176 my $full_line;
2177 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002178 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002179
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002180 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002181
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002182 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002183
2184 $child_done = 0;
2185
2186 $SIG{CHLD} = qw(child_finished);
2187
2188 $child_pid = fork;
2189
2190 child_run_test if (!$child_pid);
2191
2192 $full_line = "";
2193
2194 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002195 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002196 if (defined($line)) {
2197
2198 # we are not guaranteed to get a full line
2199 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002200 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002201
2202 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002203 if ($ignore_errors) {
2204 $bug_ignored = 1;
2205 } else {
2206 $bug = 1;
2207 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002208 }
2209
2210 if ($full_line =~ /Kernel panic -/) {
2211 $bug = 1;
2212 }
2213
2214 if ($line =~ /\n/) {
2215 $full_line = "";
2216 }
2217 }
2218 } while (!$child_done && !$bug);
2219
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002220 if (!$bug && $bug_ignored) {
2221 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2222 }
2223
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002224 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002225 my $failure_start = time;
2226 my $now;
2227 do {
2228 $line = wait_for_input($monitor_fp, 1);
2229 if (defined($line)) {
2230 doprint $line;
2231 }
2232 $now = time;
2233 if ($now - $failure_start >= $stop_after_failure) {
2234 last;
2235 }
2236 } while (defined($line));
2237
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002238 doprint "Detected kernel crash!\n";
2239 # kill the child with extreme prejudice
2240 kill 9, $child_pid;
2241 }
2242
2243 waitpid $child_pid, 0;
2244 $child_exit = $?;
2245
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002246 if (!$bug && $in_bisect) {
2247 if (defined($bisect_ret_good)) {
2248 if ($child_exit == $bisect_ret_good) {
2249 return 1;
2250 }
2251 }
2252 if (defined($bisect_ret_skip)) {
2253 if ($child_exit == $bisect_ret_skip) {
2254 return -1;
2255 }
2256 }
2257 if (defined($bisect_ret_abort)) {
2258 if ($child_exit == $bisect_ret_abort) {
2259 fail "test abort" and return -2;
2260 }
2261 }
2262 if (defined($bisect_ret_bad)) {
2263 if ($child_exit == $bisect_ret_skip) {
2264 return 0;
2265 }
2266 }
2267 if (defined($bisect_ret_default)) {
2268 if ($bisect_ret_default eq "good") {
2269 return 1;
2270 } elsif ($bisect_ret_default eq "bad") {
2271 return 0;
2272 } elsif ($bisect_ret_default eq "skip") {
2273 return -1;
2274 } elsif ($bisect_ret_default eq "abort") {
2275 return -2;
2276 } else {
2277 fail "unknown default action: $bisect_ret_default"
2278 and return -2;
2279 }
2280 }
2281 }
2282
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002283 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002284 return 0 if $in_bisect;
2285 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002286 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002287 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002288}
2289
Steven Rostedta75fece2010-11-02 14:58:27 -04002290sub run_git_bisect {
2291 my ($command) = @_;
2292
2293 doprint "$command ... ";
2294
2295 my $output = `$command 2>&1`;
2296 my $ret = $?;
2297
2298 logit $output;
2299
2300 if ($ret) {
2301 doprint "FAILED\n";
2302 dodie "Failed to git bisect";
2303 }
2304
2305 doprint "SUCCESS\n";
2306 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2307 doprint "$1 [$2]\n";
2308 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002309 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002310 doprint "Found bad commit... $1\n";
2311 return 0;
2312 } else {
2313 # we already logged it, just print it now.
2314 print $output;
2315 }
2316
2317 return 1;
2318}
2319
Steven Rostedtc23dca72011-03-08 09:26:31 -05002320sub bisect_reboot {
2321 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002322 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002323}
2324
2325# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002326sub run_bisect_test {
2327 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002328
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002329 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002330 my $result;
2331 my $output;
2332 my $ret;
2333
Steven Rostedt0a05c762010-11-08 11:14:10 -05002334 $in_bisect = 1;
2335
2336 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002337
2338 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002339 if ($failed && $bisect_skip) {
2340 $in_bisect = 0;
2341 return -1;
2342 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002343 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002344
2345 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002346 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002347
2348 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002349 if ($failed && $bisect_skip) {
2350 end_monitor;
2351 bisect_reboot;
2352 $in_bisect = 0;
2353 return -1;
2354 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002355 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002356
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002357 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002358 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002359 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002360 }
2361
2362 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002363 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002364 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002365 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002366 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002367
2368 # reboot the box to a kernel we can ssh to
2369 if ($type ne "build") {
2370 bisect_reboot;
2371 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002372 $in_bisect = 0;
2373
2374 return $result;
2375}
2376
2377sub run_bisect {
2378 my ($type) = @_;
2379 my $buildtype = "oldconfig";
2380
2381 # We should have a minconfig to use?
2382 if (defined($minconfig)) {
2383 $buildtype = "useconfig:$minconfig";
2384 }
2385
2386 my $ret = run_bisect_test $type, $buildtype;
2387
Steven Rostedtc960bb92011-03-08 09:22:39 -05002388 if ($bisect_manual) {
2389 $ret = answer_bisect;
2390 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002391
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002392 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002393 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002394 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002395 }
2396
Steven Rostedtc23dca72011-03-08 09:26:31 -05002397 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002398 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002399 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002400 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002401 } elsif ($bisect_skip) {
2402 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2403 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002404 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002405}
2406
Steven Rostedtdad98752011-11-22 20:48:57 -05002407sub update_bisect_replay {
2408 my $tmp_log = "$tmpdir/ktest_bisect_log";
2409 run_command "git bisect log > $tmp_log" or
2410 die "can't create bisect log";
2411 return $tmp_log;
2412}
2413
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002414sub bisect {
2415 my ($i) = @_;
2416
2417 my $result;
2418
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002419 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2420 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2421 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002422
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002423 my $good = $bisect_good;
2424 my $bad = $bisect_bad;
2425 my $type = $bisect_type;
2426 my $start = $bisect_start;
2427 my $replay = $bisect_replay;
2428 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002429
2430 if (defined($start_files)) {
2431 $start_files = " -- " . $start_files;
2432 } else {
2433 $start_files = "";
2434 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002435
Steven Rostedta57419b2010-11-02 15:13:54 -04002436 # convert to true sha1's
2437 $good = get_sha1($good);
2438 $bad = get_sha1($bad);
2439
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002440 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002441 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2442 $reverse_bisect = 1;
2443 } else {
2444 $reverse_bisect = 0;
2445 }
2446
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002447 # Can't have a test without having a test to run
2448 if ($type eq "test" && !defined($run_test)) {
2449 $type = "boot";
2450 }
2451
Steven Rostedtdad98752011-11-22 20:48:57 -05002452 # Check if a bisect was running
2453 my $bisect_start_file = "$builddir/.git/BISECT_START";
2454
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002455 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002456 my $do_check = defined($check) && $check ne "0";
2457
2458 if ( -f $bisect_start_file ) {
2459 print "Bisect in progress found\n";
2460 if ($do_check) {
2461 print " If you say yes, then no checks of good or bad will be done\n";
2462 }
2463 if (defined($replay)) {
2464 print "** BISECT_REPLAY is defined in config file **";
2465 print " Ignore config option and perform new git bisect log?\n";
2466 if (read_ync " (yes, no, or cancel) ") {
2467 $replay = update_bisect_replay;
2468 $do_check = 0;
2469 }
2470 } elsif (read_yn "read git log and continue?") {
2471 $replay = update_bisect_replay;
2472 $do_check = 0;
2473 }
2474 }
2475
2476 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002477
2478 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002479 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002480
2481 if ($check ne "good") {
2482 doprint "TESTING BISECT BAD [$bad]\n";
2483 run_command "git checkout $bad" or
2484 die "Failed to checkout $bad";
2485
2486 $result = run_bisect $type;
2487
2488 if ($result ne "bad") {
2489 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2490 }
2491 }
2492
2493 if ($check ne "bad") {
2494 doprint "TESTING BISECT GOOD [$good]\n";
2495 run_command "git checkout $good" or
2496 die "Failed to checkout $good";
2497
2498 $result = run_bisect $type;
2499
2500 if ($result ne "good") {
2501 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2502 }
2503 }
2504
2505 # checkout where we started
2506 run_command "git checkout $head" or
2507 die "Failed to checkout $head";
2508 }
2509
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002510 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002511 dodie "could not start bisect";
2512
2513 run_command "git bisect good $good" or
2514 dodie "could not set bisect good to $good";
2515
2516 run_git_bisect "git bisect bad $bad" or
2517 dodie "could not set bisect bad to $bad";
2518
2519 if (defined($replay)) {
2520 run_command "git bisect replay $replay" or
2521 dodie "failed to run replay";
2522 }
2523
2524 if (defined($start)) {
2525 run_command "git checkout $start" or
2526 dodie "failed to checkout $start";
2527 }
2528
2529 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002530 do {
2531 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002532 $test = run_git_bisect "git bisect $result";
2533 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002534
2535 run_command "git bisect log" or
2536 dodie "could not capture git bisect log";
2537
2538 run_command "git bisect reset" or
2539 dodie "could not reset git bisect";
2540
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002541 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002542
Steven Rostedt0a05c762010-11-08 11:14:10 -05002543 success $i;
2544}
2545
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002546# config_ignore holds the configs that were set (or unset) for
2547# a good config and we will ignore these configs for the rest
2548# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002549my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002550
2551# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002552my %config_set;
2553
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002554# config_off holds the set of configs that the bad config had disabled.
2555# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08002556# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002557my %config_off;
2558
2559# config_off_tmp holds a set of configs to turn off for now
2560my @config_off_tmp;
2561
2562# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002563my %config_list;
2564my %null_config;
2565
2566my %dependency;
2567
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002568sub assign_configs {
2569 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002570
2571 open (IN, $config)
2572 or dodie "Failed to read $config";
2573
2574 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002575 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002576 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002577 }
2578 }
2579
2580 close(IN);
2581}
2582
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002583sub process_config_ignore {
2584 my ($config) = @_;
2585
2586 assign_configs \%config_ignore, $config;
2587}
2588
Steven Rostedt0a05c762010-11-08 11:14:10 -05002589sub read_current_config {
2590 my ($config_ref) = @_;
2591
2592 %{$config_ref} = ();
2593 undef %{$config_ref};
2594
2595 my @key = keys %{$config_ref};
2596 if ($#key >= 0) {
2597 print "did not delete!\n";
2598 exit;
2599 }
2600 open (IN, "$output_config");
2601
2602 while (<IN>) {
2603 if (/^(CONFIG\S+)=(.*)/) {
2604 ${$config_ref}{$1} = $2;
2605 }
2606 }
2607 close(IN);
2608}
2609
2610sub get_dependencies {
2611 my ($config) = @_;
2612
2613 my $arr = $dependency{$config};
2614 if (!defined($arr)) {
2615 return ();
2616 }
2617
2618 my @deps = @{$arr};
2619
2620 foreach my $dep (@{$arr}) {
2621 print "ADD DEP $dep\n";
2622 @deps = (@deps, get_dependencies $dep);
2623 }
2624
2625 return @deps;
2626}
2627
2628sub create_config {
2629 my @configs = @_;
2630
2631 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2632
2633 foreach my $config (@configs) {
2634 print OUT "$config_set{$config}\n";
2635 my @deps = get_dependencies $config;
2636 foreach my $dep (@deps) {
2637 print OUT "$config_set{$dep}\n";
2638 }
2639 }
2640
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002641 # turn off configs to keep off
2642 foreach my $config (keys %config_off) {
2643 print OUT "# $config is not set\n";
2644 }
2645
2646 # turn off configs that should be off for now
2647 foreach my $config (@config_off_tmp) {
2648 print OUT "# $config is not set\n";
2649 }
2650
Steven Rostedt0a05c762010-11-08 11:14:10 -05002651 foreach my $config (keys %config_ignore) {
2652 print OUT "$config_ignore{$config}\n";
2653 }
2654 close(OUT);
2655
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002656 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002657}
2658
2659sub compare_configs {
2660 my (%a, %b) = @_;
2661
2662 foreach my $item (keys %a) {
2663 if (!defined($b{$item})) {
2664 print "diff $item\n";
2665 return 1;
2666 }
2667 delete $b{$item};
2668 }
2669
2670 my @keys = keys %b;
2671 if ($#keys) {
2672 print "diff2 $keys[0]\n";
2673 }
2674 return -1 if ($#keys >= 0);
2675
2676 return 0;
2677}
2678
2679sub run_config_bisect_test {
2680 my ($type) = @_;
2681
2682 return run_bisect_test $type, "oldconfig";
2683}
2684
2685sub process_passed {
2686 my (%configs) = @_;
2687
2688 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2689 # Passed! All these configs are part of a good compile.
2690 # Add them to the min options.
2691 foreach my $config (keys %configs) {
2692 if (defined($config_list{$config})) {
2693 doprint " removing $config\n";
2694 $config_ignore{$config} = $config_list{$config};
2695 delete $config_list{$config};
2696 }
2697 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002698 doprint "config copied to $outputdir/config_good\n";
2699 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002700}
2701
2702sub process_failed {
2703 my ($config) = @_;
2704
2705 doprint "\n\n***************************************\n";
2706 doprint "Found bad config: $config\n";
2707 doprint "***************************************\n\n";
2708}
2709
2710sub run_config_bisect {
2711
2712 my @start_list = keys %config_list;
2713
2714 if ($#start_list < 0) {
2715 doprint "No more configs to test!!!\n";
2716 return -1;
2717 }
2718
2719 doprint "***** RUN TEST ***\n";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002720 my $type = $config_bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002721 my $ret;
2722 my %current_config;
2723
2724 my $count = $#start_list + 1;
2725 doprint " $count configs to test\n";
2726
2727 my $half = int($#start_list / 2);
2728
2729 do {
2730 my @tophalf = @start_list[0 .. $half];
2731
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002732 # keep the bottom half off
2733 if ($half < $#start_list) {
2734 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2735 } else {
2736 @config_off_tmp = ();
2737 }
2738
Steven Rostedt0a05c762010-11-08 11:14:10 -05002739 create_config @tophalf;
2740 read_current_config \%current_config;
2741
2742 $count = $#tophalf + 1;
2743 doprint "Testing $count configs\n";
2744 my $found = 0;
2745 # make sure we test something
2746 foreach my $config (@tophalf) {
2747 if (defined($current_config{$config})) {
2748 logit " $config\n";
2749 $found = 1;
2750 }
2751 }
2752 if (!$found) {
2753 # try the other half
2754 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002755
2756 # keep the top half off
2757 @config_off_tmp = @tophalf;
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002758 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002759
Steven Rostedt0a05c762010-11-08 11:14:10 -05002760 create_config @tophalf;
2761 read_current_config \%current_config;
2762 foreach my $config (@tophalf) {
2763 if (defined($current_config{$config})) {
2764 logit " $config\n";
2765 $found = 1;
2766 }
2767 }
2768 if (!$found) {
2769 doprint "Failed: Can't make new config with current configs\n";
2770 foreach my $config (@start_list) {
2771 doprint " CONFIG: $config\n";
2772 }
2773 return -1;
2774 }
2775 $count = $#tophalf + 1;
2776 doprint "Testing $count configs\n";
2777 }
2778
2779 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002780 if ($bisect_manual) {
2781 $ret = answer_bisect;
2782 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002783 if ($ret) {
2784 process_passed %current_config;
2785 return 0;
2786 }
2787
2788 doprint "This config had a failure.\n";
2789 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002790 doprint "config copied to $outputdir/config_bad\n";
2791 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002792
2793 # A config exists in this group that was bad.
2794 foreach my $config (keys %config_list) {
2795 if (!defined($current_config{$config})) {
2796 doprint " removing $config\n";
2797 delete $config_list{$config};
2798 }
2799 }
2800
2801 @start_list = @tophalf;
2802
2803 if ($#start_list == 0) {
2804 process_failed $start_list[0];
2805 return 1;
2806 }
2807
2808 # remove half the configs we are looking at and see if
2809 # they are good.
2810 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002811 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002812
Steven Rostedtc960bb92011-03-08 09:22:39 -05002813 # we found a single config, try it again unless we are running manually
2814
2815 if ($bisect_manual) {
2816 process_failed $start_list[0];
2817 return 1;
2818 }
2819
Steven Rostedt0a05c762010-11-08 11:14:10 -05002820 my @tophalf = @start_list[0 .. 0];
2821
2822 $ret = run_config_bisect_test $type;
2823 if ($ret) {
2824 process_passed %current_config;
2825 return 0;
2826 }
2827
2828 process_failed $start_list[0];
2829 return 1;
2830}
2831
2832sub config_bisect {
2833 my ($i) = @_;
2834
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002835 my $start_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002836
2837 my $tmpconfig = "$tmpdir/use_config";
2838
Steven Rostedt30f75da2011-06-13 10:35:35 -04002839 if (defined($config_bisect_good)) {
2840 process_config_ignore $config_bisect_good;
2841 }
2842
Steven Rostedt0a05c762010-11-08 11:14:10 -05002843 # Make the file with the bad config and the min config
2844 if (defined($minconfig)) {
2845 # read the min config for things to ignore
2846 run_command "cp $minconfig $tmpconfig" or
2847 dodie "failed to copy $minconfig to $tmpconfig";
2848 } else {
2849 unlink $tmpconfig;
2850 }
2851
Steven Rostedt0a05c762010-11-08 11:14:10 -05002852 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002853 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002854 process_config_ignore $tmpconfig;
2855 }
2856
2857 # now process the start config
2858 run_command "cp $start_config $output_config" or
2859 dodie "failed to copy $start_config to $output_config";
2860
2861 # read directly what we want to check
2862 my %config_check;
2863 open (IN, $output_config)
Masanari Iidaf9dee312012-02-11 21:46:56 +09002864 or dodie "failed to open $output_config";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002865
2866 while (<IN>) {
2867 if (/^((CONFIG\S*)=.*)/) {
2868 $config_check{$2} = $1;
2869 }
2870 }
2871 close(IN);
2872
Steven Rostedt250bae82011-07-15 22:05:59 -04002873 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002874 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002875
2876 # check to see what we lost (or gained)
2877 open (IN, $output_config)
2878 or dodie "Failed to read $start_config";
2879
2880 my %removed_configs;
2881 my %added_configs;
2882
2883 while (<IN>) {
2884 if (/^((CONFIG\S*)=.*)/) {
2885 # save off all options
2886 $config_set{$2} = $1;
2887 if (defined($config_check{$2})) {
2888 if (defined($config_ignore{$2})) {
2889 $removed_configs{$2} = $1;
2890 } else {
2891 $config_list{$2} = $1;
2892 }
2893 } elsif (!defined($config_ignore{$2})) {
2894 $added_configs{$2} = $1;
2895 $config_list{$2} = $1;
2896 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002897 } elsif (/^# ((CONFIG\S*).*)/) {
2898 # Keep these configs disabled
2899 $config_set{$2} = $1;
2900 $config_off{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002901 }
2902 }
2903 close(IN);
2904
2905 my @confs = keys %removed_configs;
2906 if ($#confs >= 0) {
2907 doprint "Configs overridden by default configs and removed from check:\n";
2908 foreach my $config (@confs) {
2909 doprint " $config\n";
2910 }
2911 }
2912 @confs = keys %added_configs;
2913 if ($#confs >= 0) {
2914 doprint "Configs appearing in make oldconfig and added:\n";
2915 foreach my $config (@confs) {
2916 doprint " $config\n";
2917 }
2918 }
2919
2920 my %config_test;
2921 my $once = 0;
2922
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002923 @config_off_tmp = ();
2924
Steven Rostedt0a05c762010-11-08 11:14:10 -05002925 # Sometimes kconfig does weird things. We must make sure
2926 # that the config we autocreate has everything we need
2927 # to test, otherwise we may miss testing configs, or
2928 # may not be able to create a new config.
2929 # Here we create a config with everything set.
2930 create_config (keys %config_list);
2931 read_current_config \%config_test;
2932 foreach my $config (keys %config_list) {
2933 if (!defined($config_test{$config})) {
2934 if (!$once) {
2935 $once = 1;
2936 doprint "Configs not produced by kconfig (will not be checked):\n";
2937 }
2938 doprint " $config\n";
2939 delete $config_list{$config};
2940 }
2941 }
2942 my $ret;
Steven Rostedtb0918612012-07-19 15:26:00 -04002943
2944 if (defined($config_bisect_check) && $config_bisect_check) {
2945 doprint " Checking to make sure bad config with min config fails\n";
2946 create_config keys %config_list;
2947 $ret = run_config_bisect_test $config_bisect_type;
2948 if ($ret) {
2949 doprint " FAILED! Bad config with min config boots fine\n";
2950 return -1;
2951 }
2952 doprint " Bad config with min config fails as expected\n";
2953 }
2954
Steven Rostedt0a05c762010-11-08 11:14:10 -05002955 do {
2956 $ret = run_config_bisect;
2957 } while (!$ret);
2958
2959 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002960
2961 success $i;
2962}
2963
Steven Rostedt27d934b2011-05-20 09:18:18 -04002964sub patchcheck_reboot {
2965 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002966 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002967}
2968
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002969sub patchcheck {
2970 my ($i) = @_;
2971
2972 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002973 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002974 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002975 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002976
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002977 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002978
2979 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002980 if (defined($patchcheck_end)) {
2981 $end = $patchcheck_end;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002982 }
2983
Steven Rostedta57419b2010-11-02 15:13:54 -04002984 # Get the true sha1's since we can use things like HEAD~3
2985 $start = get_sha1($start);
2986 $end = get_sha1($end);
2987
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002988 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002989
2990 # Can't have a test without having a test to run
2991 if ($type eq "test" && !defined($run_test)) {
2992 $type = "boot";
2993 }
2994
2995 open (IN, "git log --pretty=oneline $end|") or
2996 dodie "could not get git list";
2997
2998 my @list;
2999
3000 while (<IN>) {
3001 chomp;
3002 $list[$#list+1] = $_;
3003 last if (/^$start/);
3004 }
3005 close(IN);
3006
3007 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003008 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003009 }
3010
3011 # go backwards in the list
3012 @list = reverse @list;
3013
3014 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003015 my %ignored_warnings;
3016
3017 if (defined($ignore_warnings)) {
3018 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3019 $ignored_warnings{$sha1} = 1;
3020 }
3021 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003022
3023 $in_patchcheck = 1;
3024 foreach my $item (@list) {
3025 my $sha1 = $item;
3026 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3027
3028 doprint "\nProcessing commit $item\n\n";
3029
3030 run_command "git checkout $sha1" or
3031 die "Failed to checkout $sha1";
3032
3033 # only clean on the first and last patch
3034 if ($item eq $list[0] ||
3035 $item eq $list[$#list]) {
3036 $noclean = $save_clean;
3037 } else {
3038 $noclean = 1;
3039 }
3040
3041 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003042 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003043 } else {
3044 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003045 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003046 }
3047
Steven Rostedt19902072011-06-14 20:46:25 -04003048
3049 if (!defined($ignored_warnings{$sha1})) {
3050 check_buildlog $sha1 or return 0;
3051 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003052
3053 next if ($type eq "build");
3054
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003055 my $failed = 0;
3056
Steven Rostedtddf607e2011-06-14 20:49:13 -04003057 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003058
3059 if (!$failed && $type ne "boot"){
3060 do_run_test or $failed = 1;
3061 }
3062 end_monitor;
3063 return 0 if ($failed);
3064
Steven Rostedt27d934b2011-05-20 09:18:18 -04003065 patchcheck_reboot;
3066
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003067 }
3068 $in_patchcheck = 0;
3069 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003070
3071 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003072}
3073
Steven Rostedtb9066f62011-07-15 21:25:24 -04003074my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003075my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003076my $iflevel = 0;
3077my @ifdeps;
3078
3079# prevent recursion
3080my %read_kconfigs;
3081
Steven Rostedtac6974c2011-10-04 09:40:17 -04003082sub add_dep {
3083 # $config depends on $dep
3084 my ($config, $dep) = @_;
3085
3086 if (defined($depends{$config})) {
3087 $depends{$config} .= " " . $dep;
3088 } else {
3089 $depends{$config} = $dep;
3090 }
3091
3092 # record the number of configs depending on $dep
3093 if (defined $depcount{$dep}) {
3094 $depcount{$dep}++;
3095 } else {
3096 $depcount{$dep} = 1;
3097 }
3098}
3099
Steven Rostedtb9066f62011-07-15 21:25:24 -04003100# taken from streamline_config.pl
3101sub read_kconfig {
3102 my ($kconfig) = @_;
3103
3104 my $state = "NONE";
3105 my $config;
3106 my @kconfigs;
3107
3108 my $cont = 0;
3109 my $line;
3110
3111
3112 if (! -f $kconfig) {
3113 doprint "file $kconfig does not exist, skipping\n";
3114 return;
3115 }
3116
3117 open(KIN, "$kconfig")
3118 or die "Can't open $kconfig";
3119 while (<KIN>) {
3120 chomp;
3121
3122 # Make sure that lines ending with \ continue
3123 if ($cont) {
3124 $_ = $line . " " . $_;
3125 }
3126
3127 if (s/\\$//) {
3128 $cont = 1;
3129 $line = $_;
3130 next;
3131 }
3132
3133 $cont = 0;
3134
3135 # collect any Kconfig sources
3136 if (/^source\s*"(.*)"/) {
3137 $kconfigs[$#kconfigs+1] = $1;
3138 }
3139
3140 # configs found
3141 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3142 $state = "NEW";
3143 $config = $2;
3144
3145 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003146 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003147 }
3148
3149 # collect the depends for the config
3150 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3151
Steven Rostedtac6974c2011-10-04 09:40:17 -04003152 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003153
3154 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003155 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3156
3157 # selected by depends on config
3158 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003159
3160 # Check for if statements
3161 } elsif (/^if\s+(.*\S)\s*$/) {
3162 my $deps = $1;
3163 # remove beginning and ending non text
3164 $deps =~ s/^[^a-zA-Z0-9_]*//;
3165 $deps =~ s/[^a-zA-Z0-9_]*$//;
3166
3167 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3168
3169 $ifdeps[$iflevel++] = join ':', @deps;
3170
3171 } elsif (/^endif/) {
3172
3173 $iflevel-- if ($iflevel);
3174
3175 # stop on "help"
3176 } elsif (/^\s*help\s*$/) {
3177 $state = "NONE";
3178 }
3179 }
3180 close(KIN);
3181
3182 # read in any configs that were found.
3183 foreach $kconfig (@kconfigs) {
3184 if (!defined($read_kconfigs{$kconfig})) {
3185 $read_kconfigs{$kconfig} = 1;
3186 read_kconfig("$builddir/$kconfig");
3187 }
3188 }
3189}
3190
3191sub read_depends {
3192 # find out which arch this is by the kconfig file
3193 open (IN, $output_config)
3194 or dodie "Failed to read $output_config";
3195 my $arch;
3196 while (<IN>) {
3197 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3198 $arch = $1;
3199 last;
3200 }
3201 }
3202 close IN;
3203
3204 if (!defined($arch)) {
3205 doprint "Could not find arch from config file\n";
3206 doprint "no dependencies used\n";
3207 return;
3208 }
3209
3210 # arch is really the subarch, we need to know
3211 # what directory to look at.
3212 if ($arch eq "i386" || $arch eq "x86_64") {
3213 $arch = "x86";
3214 } elsif ($arch =~ /^tile/) {
3215 $arch = "tile";
3216 }
3217
3218 my $kconfig = "$builddir/arch/$arch/Kconfig";
3219
3220 if (! -f $kconfig && $arch =~ /\d$/) {
3221 my $orig = $arch;
3222 # some subarchs have numbers, truncate them
3223 $arch =~ s/\d*$//;
3224 $kconfig = "$builddir/arch/$arch/Kconfig";
3225 if (! -f $kconfig) {
3226 doprint "No idea what arch dir $orig is for\n";
3227 doprint "no dependencies used\n";
3228 return;
3229 }
3230 }
3231
3232 read_kconfig($kconfig);
3233}
3234
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003235sub read_config_list {
3236 my ($config) = @_;
3237
3238 open (IN, $config)
3239 or dodie "Failed to read $config";
3240
3241 while (<IN>) {
3242 if (/^((CONFIG\S*)=.*)/) {
3243 if (!defined($config_ignore{$2})) {
3244 $config_list{$2} = $1;
3245 }
3246 }
3247 }
3248
3249 close(IN);
3250}
3251
3252sub read_output_config {
3253 my ($config) = @_;
3254
3255 assign_configs \%config_ignore, $config;
3256}
3257
3258sub make_new_config {
3259 my @configs = @_;
3260
3261 open (OUT, ">$output_config")
3262 or dodie "Failed to write $output_config";
3263
3264 foreach my $config (@configs) {
3265 print OUT "$config\n";
3266 }
3267 close OUT;
3268}
3269
Steven Rostedtac6974c2011-10-04 09:40:17 -04003270sub chomp_config {
3271 my ($config) = @_;
3272
3273 $config =~ s/CONFIG_//;
3274
3275 return $config;
3276}
3277
Steven Rostedtb9066f62011-07-15 21:25:24 -04003278sub get_depends {
3279 my ($dep) = @_;
3280
Steven Rostedtac6974c2011-10-04 09:40:17 -04003281 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003282
3283 $dep = $depends{"$kconfig"};
3284
3285 # the dep string we have saves the dependencies as they
3286 # were found, including expressions like ! && ||. We
3287 # want to split this out into just an array of configs.
3288
3289 my $valid = "A-Za-z_0-9";
3290
3291 my @configs;
3292
3293 while ($dep =~ /[$valid]/) {
3294
3295 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3296 my $conf = "CONFIG_" . $1;
3297
3298 $configs[$#configs + 1] = $conf;
3299
3300 $dep =~ s/^[^$valid]*[$valid]+//;
3301 } else {
3302 die "this should never happen";
3303 }
3304 }
3305
3306 return @configs;
3307}
3308
3309my %min_configs;
3310my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003311my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003312my %processed_configs;
3313my %nochange_config;
3314
3315sub test_this_config {
3316 my ($config) = @_;
3317
3318 my $found;
3319
3320 # if we already processed this config, skip it
3321 if (defined($processed_configs{$config})) {
3322 return undef;
3323 }
3324 $processed_configs{$config} = 1;
3325
3326 # if this config failed during this round, skip it
3327 if (defined($nochange_config{$config})) {
3328 return undef;
3329 }
3330
Steven Rostedtac6974c2011-10-04 09:40:17 -04003331 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003332
3333 # Test dependencies first
3334 if (defined($depends{"$kconfig"})) {
3335 my @parents = get_depends $config;
3336 foreach my $parent (@parents) {
3337 # if the parent is in the min config, check it first
3338 next if (!defined($min_configs{$parent}));
3339 $found = test_this_config($parent);
3340 if (defined($found)) {
3341 return $found;
3342 }
3343 }
3344 }
3345
3346 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003347 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003348 # .config to make sure it is missing the config that
3349 # we had before
3350 my %configs = %min_configs;
3351 delete $configs{$config};
3352 make_new_config ((values %configs), (values %keep_configs));
3353 make_oldconfig;
3354 undef %configs;
3355 assign_configs \%configs, $output_config;
3356
3357 return $config if (!defined($configs{$config}));
3358
3359 doprint "disabling config $config did not change .config\n";
3360
3361 $nochange_config{$config} = 1;
3362
3363 return undef;
3364}
3365
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003366sub make_min_config {
3367 my ($i) = @_;
3368
Steven Rostedtccc513b2012-05-21 17:13:40 -04003369 my $type = $minconfig_type;
3370 if ($type ne "boot" && $type ne "test") {
3371 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3372 " make_min_config works only with 'boot' and 'test'\n" and return;
3373 }
3374
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003375 if (!defined($output_minconfig)) {
3376 fail "OUTPUT_MIN_CONFIG not defined" and return;
3377 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003378
3379 # If output_minconfig exists, and the start_minconfig
3380 # came from min_config, than ask if we should use
3381 # that instead.
3382 if (-f $output_minconfig && !$start_minconfig_defined) {
3383 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003384 if (!defined($use_output_minconfig)) {
3385 if (read_yn " Use it as minconfig?") {
3386 $start_minconfig = $output_minconfig;
3387 }
3388 } elsif ($use_output_minconfig > 0) {
3389 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003390 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003391 } else {
3392 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003393 }
3394 }
3395
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003396 if (!defined($start_minconfig)) {
3397 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3398 }
3399
Steven Rostedt35ce5952011-07-15 21:57:25 -04003400 my $temp_config = "$tmpdir/temp_config";
3401
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003402 # First things first. We build an allnoconfig to find
3403 # out what the defaults are that we can't touch.
3404 # Some are selections, but we really can't handle selections.
3405
3406 my $save_minconfig = $minconfig;
3407 undef $minconfig;
3408
3409 run_command "$make allnoconfig" or return 0;
3410
Steven Rostedtb9066f62011-07-15 21:25:24 -04003411 read_depends;
3412
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003413 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003414
Steven Rostedt43d1b652011-07-15 22:01:56 -04003415 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003416 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003417
3418 if (defined($ignore_config)) {
3419 # make sure the file exists
3420 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003421 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003422 }
3423
Steven Rostedt43d1b652011-07-15 22:01:56 -04003424 %keep_configs = %save_configs;
3425
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003426 doprint "Load initial configs from $start_minconfig\n";
3427
3428 # Look at the current min configs, and save off all the
3429 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003430 assign_configs \%min_configs, $start_minconfig;
3431
3432 my @config_keys = keys %min_configs;
3433
Steven Rostedtac6974c2011-10-04 09:40:17 -04003434 # All configs need a depcount
3435 foreach my $config (@config_keys) {
3436 my $kconfig = chomp_config $config;
3437 if (!defined $depcount{$kconfig}) {
3438 $depcount{$kconfig} = 0;
3439 }
3440 }
3441
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003442 # Remove anything that was set by the make allnoconfig
3443 # we shouldn't need them as they get set for us anyway.
3444 foreach my $config (@config_keys) {
3445 # Remove anything in the ignore_config
3446 if (defined($keep_configs{$config})) {
3447 my $file = $ignore_config;
3448 $file =~ s,.*/(.*?)$,$1,;
3449 doprint "$config set by $file ... ignored\n";
3450 delete $min_configs{$config};
3451 next;
3452 }
3453 # But make sure the settings are the same. If a min config
3454 # sets a selection, we do not want to get rid of it if
3455 # it is not the same as what we have. Just move it into
3456 # the keep configs.
3457 if (defined($config_ignore{$config})) {
3458 if ($config_ignore{$config} ne $min_configs{$config}) {
3459 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3460 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3461 $keep_configs{$config} = $min_configs{$config};
3462 } else {
3463 doprint "$config set by allnoconfig ... ignored\n";
3464 }
3465 delete $min_configs{$config};
3466 }
3467 }
3468
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003469 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003470 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003471
3472 while (!$done) {
3473
3474 my $config;
3475 my $found;
3476
3477 # Now disable each config one by one and do a make oldconfig
3478 # till we find a config that changes our list.
3479
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003480 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003481
3482 # Sort keys by who is most dependent on
3483 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3484 @test_configs ;
3485
3486 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003487 my $reset = 1;
3488 for (my $i = 0; $i < $#test_configs; $i++) {
3489 if (!defined($nochange_config{$test_configs[0]})) {
3490 $reset = 0;
3491 last;
3492 }
3493 # This config didn't change the .config last time.
3494 # Place it at the end
3495 my $config = shift @test_configs;
3496 push @test_configs, $config;
3497 }
3498
3499 # if every test config has failed to modify the .config file
3500 # in the past, then reset and start over.
3501 if ($reset) {
3502 undef %nochange_config;
3503 }
3504
Steven Rostedtb9066f62011-07-15 21:25:24 -04003505 undef %processed_configs;
3506
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003507 foreach my $config (@test_configs) {
3508
Steven Rostedtb9066f62011-07-15 21:25:24 -04003509 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003510
Steven Rostedtb9066f62011-07-15 21:25:24 -04003511 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003512
3513 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003514 }
3515
3516 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003517 # we could have failed due to the nochange_config hash
3518 # reset and try again
3519 if (!$take_two) {
3520 undef %nochange_config;
3521 $take_two = 1;
3522 next;
3523 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003524 doprint "No more configs found that we can disable\n";
3525 $done = 1;
3526 last;
3527 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003528 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003529
3530 $config = $found;
3531
3532 doprint "Test with $config disabled\n";
3533
3534 # set in_bisect to keep build and monitor from dieing
3535 $in_bisect = 1;
3536
3537 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003538 build "oldconfig" or $failed = 1;
3539 if (!$failed) {
3540 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003541
3542 if ($type eq "test" && !$failed) {
3543 do_run_test or $failed = 1;
3544 }
3545
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003546 end_monitor;
3547 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003548
3549 $in_bisect = 0;
3550
3551 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003552 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003553 # this config is needed, add it to the ignore list.
3554 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003555 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003556 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003557
3558 # update new ignore configs
3559 if (defined($ignore_config)) {
3560 open (OUT, ">$temp_config")
3561 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003562 foreach my $config (keys %save_configs) {
3563 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003564 }
3565 close OUT;
3566 run_command "mv $temp_config $ignore_config" or
3567 dodie "failed to copy update to $ignore_config";
3568 }
3569
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003570 } else {
3571 # We booted without this config, remove it from the minconfigs.
3572 doprint "$config is not needed, disabling\n";
3573
3574 delete $min_configs{$config};
3575
3576 # Also disable anything that is not enabled in this config
3577 my %configs;
3578 assign_configs \%configs, $output_config;
3579 my @config_keys = keys %min_configs;
3580 foreach my $config (@config_keys) {
3581 if (!defined($configs{$config})) {
3582 doprint "$config is not set, disabling\n";
3583 delete $min_configs{$config};
3584 }
3585 }
3586
3587 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003588 open (OUT, ">$temp_config")
3589 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003590 foreach my $config (keys %keep_configs) {
3591 print OUT "$keep_configs{$config}\n";
3592 }
3593 foreach my $config (keys %min_configs) {
3594 print OUT "$min_configs{$config}\n";
3595 }
3596 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003597
3598 run_command "mv $temp_config $output_minconfig" or
3599 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003600 }
3601
3602 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003603 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003604 }
3605
3606 success $i;
3607 return 1;
3608}
3609
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003610$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003611
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003612if ($#ARGV == 0) {
3613 $ktest_config = $ARGV[0];
3614 if (! -f $ktest_config) {
3615 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003616 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003617 exit 0;
3618 }
3619 }
3620} else {
3621 $ktest_config = "ktest.conf";
3622}
3623
3624if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003625 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003626 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003627 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3628 print OUT << "EOF"
3629# Generated by ktest.pl
3630#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003631
3632# PWD is a ktest.pl variable that will result in the process working
3633# directory that ktest.pl is executed in.
3634
3635# THIS_DIR is automatically assigned the PWD of the path that generated
3636# the config file. It is best to use this variable when assigning other
3637# directory paths within this directory. This allows you to easily
3638# move the test cases to other locations or to other machines.
3639#
3640THIS_DIR := $variable{"PWD"}
3641
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003642# Define each test with TEST_START
3643# The config options below it will override the defaults
3644TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003645TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003646
3647DEFAULTS
3648EOF
3649;
3650 close(OUT);
3651}
3652read_config $ktest_config;
3653
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003654if (defined($opt{"LOG_FILE"})) {
3655 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3656}
3657
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003658# Append any configs entered in manually to the config file.
3659my @new_configs = keys %entered_configs;
3660if ($#new_configs >= 0) {
3661 print "\nAppending entered in configs to $ktest_config\n";
3662 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3663 foreach my $config (@new_configs) {
3664 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003665 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003666 }
3667}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003668
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003669if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3670 unlink $opt{"LOG_FILE"};
3671}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003672
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003673doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3674
Steven Rostedta57419b2010-11-02 15:13:54 -04003675for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3676
3677 if (!$i) {
3678 doprint "DEFAULT OPTIONS:\n";
3679 } else {
3680 doprint "\nTEST $i OPTIONS";
3681 if (defined($repeat_tests{$i})) {
3682 $repeat = $repeat_tests{$i};
3683 doprint " ITERATE $repeat";
3684 }
3685 doprint "\n";
3686 }
3687
3688 foreach my $option (sort keys %opt) {
3689
3690 if ($option =~ /\[(\d+)\]$/) {
3691 next if ($i != $1);
3692 } else {
3693 next if ($i);
3694 }
3695
3696 doprint "$option = $opt{$option}\n";
3697 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003698}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003699
Steven Rostedt2a625122011-05-20 15:48:59 -04003700sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003701 my ($name, $i) = @_;
3702
3703 my $option = "$name\[$i\]";
3704
3705 if (defined($opt{$option})) {
3706 return $opt{$option};
3707 }
3708
Steven Rostedta57419b2010-11-02 15:13:54 -04003709 foreach my $test (keys %repeat_tests) {
3710 if ($i >= $test &&
3711 $i < $test + $repeat_tests{$test}) {
3712 $option = "$name\[$test\]";
3713 if (defined($opt{$option})) {
3714 return $opt{$option};
3715 }
3716 }
3717 }
3718
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003719 if (defined($opt{$name})) {
3720 return $opt{$name};
3721 }
3722
3723 return undef;
3724}
3725
Steven Rostedt2a625122011-05-20 15:48:59 -04003726sub set_test_option {
3727 my ($name, $i) = @_;
3728
3729 my $option = __set_test_option($name, $i);
3730 return $option if (!defined($option));
3731
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003732 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003733}
3734
Steven Rostedt2545eb62010-11-02 15:01:32 -04003735# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003736for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003737
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003738 # Do not reboot on failing test options
3739 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003740 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003741
Steven Rostedt683a3e62012-05-18 13:34:35 -04003742 $have_version = 0;
3743
Steven Rostedt576f6272010-11-02 14:58:38 -04003744 $iteration = $i;
3745
Steven Rostedtc1434dc2012-07-20 22:39:16 -04003746 undef %force_config;
3747
Steven Rostedta75fece2010-11-02 14:58:27 -04003748 my $makecmd = set_test_option("MAKE_CMD", $i);
3749
Steven Rostedt9cc9e092011-12-22 21:37:22 -05003750 # Load all the options into their mapped variable names
3751 foreach my $opt (keys %option_map) {
3752 ${$option_map{$opt}} = set_test_option($opt, $i);
3753 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003754
Steven Rostedt35ce5952011-07-15 21:57:25 -04003755 $start_minconfig_defined = 1;
3756
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003757 # The first test may override the PRE_KTEST option
3758 if (defined($pre_ktest) && $i == 1) {
3759 doprint "\n";
3760 run_command $pre_ktest;
3761 }
3762
3763 # Any test can override the POST_KTEST option
3764 # The last test takes precedence.
3765 if (defined($post_ktest)) {
3766 $final_post_ktest = $post_ktest;
3767 }
3768
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003769 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003770 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003771 $start_minconfig = $minconfig;
3772 }
3773
Steven Rostedta75fece2010-11-02 14:58:27 -04003774 chdir $builddir || die "can't change directory to $builddir";
3775
Andrew Jonesa908a662011-08-12 15:32:03 +02003776 foreach my $dir ($tmpdir, $outputdir) {
3777 if (!-d $dir) {
3778 mkpath($dir) or
3779 die "can't create $dir";
3780 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003781 }
3782
Steven Rostedte48c5292010-11-02 14:35:37 -04003783 $ENV{"SSH_USER"} = $ssh_user;
3784 $ENV{"MACHINE"} = $machine;
3785
Steven Rostedta75fece2010-11-02 14:58:27 -04003786 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303787 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003788 $dmesg = "$tmpdir/dmesg-$machine";
3789 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003790 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003791
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003792 if (!$buildonly) {
3793 $target = "$ssh_user\@$machine";
3794 if ($reboot_type eq "grub") {
3795 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05003796 } elsif ($reboot_type eq "grub2") {
3797 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3798 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05003799 } elsif ($reboot_type eq "syslinux") {
3800 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003801 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003802 }
3803
3804 my $run_type = $build_type;
3805 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003806 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003807 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003808 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003809 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003810 $run_type = $config_bisect_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003811 }
3812
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003813 if ($test_type eq "make_min_config") {
3814 $run_type = "";
3815 }
3816
Steven Rostedta75fece2010-11-02 14:58:27 -04003817 # mistake in config file?
3818 if (!defined($run_type)) {
3819 $run_type = "ERROR";
3820 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003821
Steven Rostedte0a87422011-09-30 17:50:48 -04003822 my $installme = "";
3823 $installme = " no_install" if ($no_install);
3824
Steven Rostedt2545eb62010-11-02 15:01:32 -04003825 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003826 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003827
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003828 if (defined($pre_test)) {
3829 run_command $pre_test;
3830 }
3831
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003832 unlink $dmesg;
3833 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303834 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003835
Steven Rostedt250bae82011-07-15 22:05:59 -04003836 if (defined($addconfig)) {
3837 my $min = $minconfig;
3838 if (!defined($minconfig)) {
3839 $min = "";
3840 }
3841 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003842 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003843 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003844 }
3845
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003846 if (defined($checkout)) {
3847 run_command "git checkout $checkout" or
3848 die "failed to checkout $checkout";
3849 }
3850
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003851 $no_reboot = 0;
3852
Steven Rostedt648a1822012-03-21 11:18:27 -04003853 # A test may opt to not reboot the box
3854 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003855 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04003856 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003857
Steven Rostedta75fece2010-11-02 14:58:27 -04003858 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003859 bisect $i;
3860 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003861 } elsif ($test_type eq "config_bisect") {
3862 config_bisect $i;
3863 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003864 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003865 patchcheck $i;
3866 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003867 } elsif ($test_type eq "make_min_config") {
3868 make_min_config $i;
3869 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003870 }
3871
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003872 if ($build_type ne "nobuild") {
3873 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003874 }
3875
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003876 if ($test_type eq "install") {
3877 get_version;
3878 install;
3879 success $i;
3880 next;
3881 }
3882
Steven Rostedta75fece2010-11-02 14:58:27 -04003883 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003884 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003885 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003886
3887 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3888 do_run_test or $failed = 1;
3889 }
3890 end_monitor;
3891 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003892 }
3893
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003894 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003895}
3896
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003897if (defined($final_post_ktest)) {
3898 run_command $final_post_ktest;
3899}
3900
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003901if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003902 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003903} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003904 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04003905} elsif (defined($switch_to_good)) {
3906 # still need to get to the good kernel
3907 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003908}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003909
Steven Rostedt648a1822012-03-21 11:18:27 -04003910
Steven Rostedte48c5292010-11-02 14:35:37 -04003911doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3912
Steven Rostedt2545eb62010-11-02 15:01:32 -04003913exit 0;