blob: cc9925a68f2ac909589da3b0dc868a90eb5537cb [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 Rostedt (Red Hat)319ab142013-01-30 12:25:38 -0500622 # for bisect, we need to check BISECT_TYPE
623 if ($prvalue ne "bisect") {
624 $buildonly = 0;
625 }
626 } else {
627 # install still limits some manditory options.
628 $buildonly = 2;
629 }
630 }
631
632 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
633 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500634 $buildonly = 0;
635 } else {
636 # install still limits some manditory options.
637 $buildonly = 2;
638 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500639 }
640
Steven Rostedta57419b2010-11-02 15:13:54 -0400641 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400642 if (!$override || defined(${$overrides}{$lvalue})) {
643 my $extra = "";
644 if ($override) {
645 $extra = "In the same override section!\n";
646 }
647 die "$name: $.: Option $lvalue defined more than once!\n$extra";
648 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500649 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400650 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500651 if ($rvalue =~ /^\s*$/) {
652 delete $opt{$lvalue};
653 } else {
Steven Rostedtcad96662011-12-22 11:32:52 -0500654 $opt{$lvalue} = $prvalue;
Steven Rostedt21a96792010-11-08 16:45:50 -0500655 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400656}
657
Steven Rostedt77d942c2011-05-20 13:36:58 -0400658sub set_variable {
659 my ($lvalue, $rvalue) = @_;
660
661 if ($rvalue =~ /^\s*$/) {
662 delete $variable{$lvalue};
663 } else {
664 $rvalue = process_variables($rvalue);
665 $variable{$lvalue} = $rvalue;
666 }
667}
668
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400669sub process_compare {
670 my ($lval, $cmp, $rval) = @_;
671
672 # remove whitespace
673
674 $lval =~ s/^\s*//;
675 $lval =~ s/\s*$//;
676
677 $rval =~ s/^\s*//;
678 $rval =~ s/\s*$//;
679
680 if ($cmp eq "==") {
681 return $lval eq $rval;
682 } elsif ($cmp eq "!=") {
683 return $lval ne $rval;
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400684 } elsif ($cmp eq "=~") {
685 return $lval =~ m/$rval/;
686 } elsif ($cmp eq "!~") {
687 return $lval !~ m/$rval/;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400688 }
689
690 my $statement = "$lval $cmp $rval";
691 my $ret = eval $statement;
692
693 # $@ stores error of eval
694 if ($@) {
695 return -1;
696 }
697
698 return $ret;
699}
700
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400701sub value_defined {
702 my ($val) = @_;
703
704 return defined($variable{$2}) ||
705 defined($opt{$2});
706}
707
Steven Rostedt8d735212011-10-17 11:36:44 -0400708my $d = 0;
709sub process_expression {
710 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400711
Steven Rostedt8d735212011-10-17 11:36:44 -0400712 my $c = $d++;
713
714 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
715 my $express = $1;
716
717 if (process_expression($name, $express)) {
718 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
719 } else {
720 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
721 }
722 }
723
724 $d--;
725 my $OR = "\\|\\|";
726 my $AND = "\\&\\&";
727
728 while ($val =~ s/^(.*?)($OR|$AND)//) {
729 my $express = $1;
730 my $op = $2;
731
732 if (process_expression($name, $express)) {
733 if ($op eq "||") {
734 return 1;
735 }
736 } else {
737 if ($op eq "&&") {
738 return 0;
739 }
740 }
741 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400742
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400743 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400744 my $ret = process_compare($1, $2, $3);
745 if ($ret < 0) {
746 die "$name: $.: Unable to process comparison\n";
747 }
748 return $ret;
749 }
750
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400751 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
752 if (defined $1) {
753 return !value_defined($2);
754 } else {
755 return value_defined($2);
756 }
757 }
758
Steven Rostedt45d73a52011-09-30 19:44:53 -0400759 if ($val =~ /^\s*0\s*$/) {
760 return 0;
761 } elsif ($val =~ /^\s*\d+\s*$/) {
762 return 1;
763 }
764
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400765 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400766}
767
768sub process_if {
769 my ($name, $value) = @_;
770
771 # Convert variables and replace undefined ones with 0
772 my $val = process_variables($value, 1);
773 my $ret = process_expression $name, $val;
774
775 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400776}
777
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400778sub __read_config {
779 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400780
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400781 my $in;
782 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400783
Steven Rostedta57419b2010-11-02 15:13:54 -0400784 my $name = $config;
785 $name =~ s,.*/(.*),$1,;
786
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400787 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400788 my $default = 1;
789 my $repeat = 1;
790 my $num_tests_set = 0;
791 my $skip = 0;
792 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400793 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400794 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400795 my $if = 0;
796 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400797 my $override = 0;
798
799 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400800
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400801 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400802
803 # ignore blank lines and comments
804 next if (/^\s*$/ || /\s*\#/);
805
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400806 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400807
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400808 my $type = $1;
809 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400810 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400811
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400812 my $old_test_num;
813 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400814 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400815
816 if ($type eq "TEST_START") {
817
818 if ($num_tests_set) {
819 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
820 }
821
822 $old_test_num = $test_num;
823 $old_repeat = $repeat;
824
825 $test_num += $repeat;
826 $default = 0;
827 $repeat = 1;
828 } else {
829 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400830 }
831
Steven Rostedta9f84422011-10-17 11:06:29 -0400832 # If SKIP is anywhere in the line, the command will be skipped
833 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400834 $skip = 1;
835 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400836 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400837 $skip = 0;
838 }
839
Steven Rostedta9f84422011-10-17 11:06:29 -0400840 if ($rest =~ s/\sELSE\b//) {
841 if (!$if) {
842 die "$name: $.: ELSE found with out matching IF section\n$_";
843 }
844 $if = 0;
845
846 if ($if_set) {
847 $skip = 1;
848 } else {
849 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400850 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400851 }
852
Steven Rostedta9f84422011-10-17 11:06:29 -0400853 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400854 if (process_if($name, $1)) {
855 $if_set = 1;
856 } else {
857 $skip = 1;
858 }
859 $if = 1;
860 } else {
861 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400862 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400863 }
864
Steven Rostedta9f84422011-10-17 11:06:29 -0400865 if (!$skip) {
866 if ($type eq "TEST_START") {
867 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
868 $repeat = $1;
869 $repeat_tests{"$test_num"} = $repeat;
870 }
871 } elsif ($rest =~ s/\sOVERRIDE\b//) {
872 # DEFAULT only
873 $override = 1;
874 # Clear previous overrides
875 %overrides = ();
876 }
877 }
878
879 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400880 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400881 }
882
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400883 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400884 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400885 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400886 }
887
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400888 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400889 if (!$if) {
890 die "$name: $.: ELSE found with out matching IF section\n$_";
891 }
892 $rest = $1;
893 if ($if_set) {
894 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400895 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400896 } else {
897 $skip = 0;
898
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400899 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400900 # May be a ELSE IF section.
Steven Rostedt95f57832012-09-26 14:48:17 -0400901 if (process_if($name, $1)) {
902 $if_set = 1;
903 } else {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400904 $skip = 1;
905 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400906 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400907 } else {
908 $if = 0;
909 }
910 }
911
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400912 if ($rest !~ /^\s*$/) {
913 die "$name: $.: Gargbage found after DEFAULTS\n$_";
914 }
915
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400916 } elsif (/^\s*INCLUDE\s+(\S+)/) {
917
918 next if ($skip);
919
920 if (!$default) {
921 die "$name: $.: INCLUDE can only be done in default sections\n$_";
922 }
923
924 my $file = process_variables($1);
925
926 if ($file !~ m,^/,) {
927 # check the path of the config file first
928 if ($config =~ m,(.*)/,) {
929 if (-f "$1/$file") {
930 $file = "$1/$file";
931 }
932 }
933 }
934
935 if ( ! -r $file ) {
936 die "$name: $.: Can't read file $file\n$_";
937 }
938
939 if (__read_config($file, \$test_num)) {
940 $test_case = 1;
941 }
942
Steven Rostedta57419b2010-11-02 15:13:54 -0400943 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
944
945 next if ($skip);
946
Steven Rostedt2545eb62010-11-02 15:01:32 -0400947 my $lvalue = $1;
948 my $rvalue = $2;
949
Steven Rostedta57419b2010-11-02 15:13:54 -0400950 if (!$default &&
951 ($lvalue eq "NUM_TESTS" ||
952 $lvalue eq "LOG_FILE" ||
953 $lvalue eq "CLEAR_LOG")) {
954 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400955 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400956
957 if ($lvalue eq "NUM_TESTS") {
958 if ($test_num) {
959 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
960 }
961 if (!$default) {
962 die "$name: $.: NUM_TESTS must be set in default section\n";
963 }
964 $num_tests_set = 1;
965 }
966
967 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400968 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400969 } else {
970 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400971 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400972
973 if ($repeat > 1) {
974 $repeats{$val} = $repeat;
975 }
976 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400977 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
978 next if ($skip);
979
980 my $lvalue = $1;
981 my $rvalue = $2;
982
983 # process config variables.
984 # Config variables are only active while reading the
985 # config and can be defined anywhere. They also ignore
986 # TEST_START and DEFAULTS, but are skipped if they are in
987 # on of these sections that have SKIP defined.
988 # The save variable can be
989 # defined multiple times and the new one simply overrides
990 # the prevous one.
991 set_variable($lvalue, $rvalue);
992
Steven Rostedta57419b2010-11-02 15:13:54 -0400993 } else {
994 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400995 }
996 }
997
Steven Rostedta57419b2010-11-02 15:13:54 -0400998 if ($test_num) {
999 $test_num += $repeat - 1;
1000 $opt{"NUM_TESTS"} = $test_num;
1001 }
1002
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001003 close($in);
1004
1005 $$current_test_num = $test_num;
1006
1007 return $test_case;
1008}
1009
Steven Rostedtc4261d02011-11-23 13:41:18 -05001010sub get_test_case {
1011 print "What test case would you like to run?\n";
1012 print " (build, install or boot)\n";
1013 print " Other tests are available but require editing the config file\n";
1014 my $ans = <STDIN>;
1015 chomp $ans;
1016 $default{"TEST_TYPE"} = $ans;
1017}
1018
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001019sub read_config {
1020 my ($config) = @_;
1021
1022 my $test_case;
1023 my $test_num = 0;
1024
1025 $test_case = __read_config $config, \$test_num;
1026
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001027 # make sure we have all mandatory configs
1028 get_ktest_configs;
1029
Steven Rostedt0df213c2011-06-14 20:51:37 -04001030 # was a test specified?
1031 if (!$test_case) {
1032 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -05001033 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -04001034 }
1035
Steven Rostedta75fece2010-11-02 14:58:27 -04001036 # set any defaults
1037
1038 foreach my $default (keys %default) {
1039 if (!defined($opt{$default})) {
1040 $opt{$default} = $default{$default};
1041 }
1042 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -05001043
1044 if ($opt{"IGNORE_UNUSED"} == 1) {
1045 return;
1046 }
1047
1048 my %not_used;
1049
1050 # check if there are any stragglers (typos?)
1051 foreach my $option (keys %opt) {
1052 my $op = $option;
1053 # remove per test labels.
1054 $op =~ s/\[.*\]//;
1055 if (!exists($option_map{$op}) &&
1056 !exists($default{$op}) &&
1057 !exists($used_options{$op})) {
1058 $not_used{$op} = 1;
1059 }
1060 }
1061
1062 if (%not_used) {
1063 my $s = "s are";
1064 $s = " is" if (keys %not_used == 1);
1065 print "The following option$s not used; could be a typo:\n";
1066 foreach my $option (keys %not_used) {
1067 print "$option\n";
1068 }
1069 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1070 if (!read_yn "Do you want to continue?") {
1071 exit -1;
1072 }
1073 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001074}
1075
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001076sub __eval_option {
1077 my ($option, $i) = @_;
1078
1079 # Add space to evaluate the character before $
1080 $option = " $option";
1081 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301082 my $repeated = 0;
1083 my $parent = 0;
1084
1085 foreach my $test (keys %repeat_tests) {
1086 if ($i >= $test &&
1087 $i < $test + $repeat_tests{$test}) {
1088
1089 $repeated = 1;
1090 $parent = $test;
1091 last;
1092 }
1093 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001094
1095 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1096 my $start = $1;
1097 my $var = $2;
1098 my $end = $3;
1099
1100 # Append beginning of line
1101 $retval = "$retval$start";
1102
1103 # If the iteration option OPT[$i] exists, then use that.
1104 # otherwise see if the default OPT (without [$i]) exists.
1105
1106 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301107 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001108
1109 if (defined($opt{$o})) {
1110 $o = $opt{$o};
1111 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301112 } elsif ($repeated && defined($opt{$parento})) {
1113 $o = $opt{$parento};
1114 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001115 } elsif (defined($opt{$var})) {
1116 $o = $opt{$var};
1117 $retval = "$retval$o";
1118 } else {
1119 $retval = "$retval\$\{$var\}";
1120 }
1121
1122 $option = $end;
1123 }
1124
1125 $retval = "$retval$option";
1126
1127 $retval =~ s/^ //;
1128
1129 return $retval;
1130}
1131
1132sub eval_option {
1133 my ($option, $i) = @_;
1134
1135 my $prev = "";
1136
1137 # Since an option can evaluate to another option,
1138 # keep iterating until we do not evaluate any more
1139 # options.
1140 my $r = 0;
1141 while ($prev ne $option) {
1142 # Check for recursive evaluations.
1143 # 100 deep should be more than enough.
1144 if ($r++ > 100) {
1145 die "Over 100 evaluations accurred with $option\n" .
1146 "Check for recursive variables\n";
1147 }
1148 $prev = $option;
1149 $option = __eval_option($option, $i);
1150 }
1151
1152 return $option;
1153}
1154
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001155sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001156 if (defined($opt{"LOG_FILE"})) {
1157 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1158 print OUT @_;
1159 close(OUT);
1160 }
1161}
1162
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001163sub logit {
1164 if (defined($opt{"LOG_FILE"})) {
1165 _logit @_;
1166 } else {
1167 print @_;
1168 }
1169}
1170
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001171sub doprint {
1172 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001173 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001174}
1175
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001176sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001177sub start_monitor;
1178sub end_monitor;
1179sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001180
1181sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001182 my ($time) = @_;
1183
Steven Rostedta4968722012-12-11 14:59:05 -05001184 # Make sure everything has been written to disk
1185 run_ssh("sync");
1186
Steven Rostedt2b803362011-09-30 18:00:23 -04001187 if (defined($time)) {
1188 start_monitor;
1189 # flush out current monitor
1190 # May contain the reboot success line
1191 wait_for_monitor 1;
1192 }
1193
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001194 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001195 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001196 if (defined($powercycle_after_reboot)) {
1197 sleep $powercycle_after_reboot;
1198 run_command "$power_cycle";
1199 }
1200 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001201 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001202 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001203 }
Andrew Jones2728be42011-08-12 15:32:05 +02001204
1205 if (defined($time)) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001206 if (wait_for_monitor($time, $reboot_success_line)) {
1207 # reboot got stuck?
Steven Rostedt8a80c722012-07-19 16:08:33 -04001208 doprint "Reboot did not finish. Forcing power cycle\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001209 run_command "$power_cycle";
1210 }
Andrew Jones2728be42011-08-12 15:32:05 +02001211 end_monitor;
1212 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001213}
1214
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001215sub reboot_to_good {
1216 my ($time) = @_;
1217
1218 if (defined($switch_to_good)) {
1219 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001220 }
1221
1222 reboot $time;
1223}
1224
Steven Rostedt576f6272010-11-02 14:58:38 -04001225sub do_not_reboot {
1226 my $i = $iteration;
1227
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001228 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001229 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1230 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1231}
1232
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001233sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001234 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001235
Steven Rostedt576f6272010-11-02 14:58:38 -04001236 my $i = $iteration;
1237
1238 if ($reboot_on_error && !do_not_reboot) {
1239
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001240 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001241 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001242
Steven Rostedta75fece2010-11-02 14:58:27 -04001243 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001244 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001245 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001246 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001247
Steven Rostedtf80802c2011-03-07 13:18:47 -05001248 if (defined($opt{"LOG_FILE"})) {
1249 print " See $opt{LOG_FILE} for more info.\n";
1250 }
1251
Steven Rostedt576f6272010-11-02 14:58:38 -04001252 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001253}
1254
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001255sub open_console {
1256 my ($fp) = @_;
1257
1258 my $flags;
1259
Steven Rostedta75fece2010-11-02 14:58:27 -04001260 my $pid = open($fp, "$console|") or
1261 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001262
1263 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001264 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001265 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001266 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001267
1268 return $pid;
1269}
1270
1271sub close_console {
1272 my ($fp, $pid) = @_;
1273
1274 doprint "kill child process $pid\n";
1275 kill 2, $pid;
1276
1277 print "closing!\n";
1278 close($fp);
1279}
1280
1281sub start_monitor {
1282 if ($monitor_cnt++) {
1283 return;
1284 }
1285 $monitor_fp = \*MONFD;
1286 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001287
1288 return;
1289
1290 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001291}
1292
1293sub end_monitor {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001294 return if (!defined $console);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001295 if (--$monitor_cnt) {
1296 return;
1297 }
1298 close_console($monitor_fp, $monitor_pid);
1299}
1300
1301sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001302 my ($time, $stop) = @_;
1303 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001304 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001305 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001306 my $start_time = time;
Steven Rostedt8a80c722012-07-19 16:08:33 -04001307 my $skip_call_trace = 0;
1308 my $bug = 0;
1309 my $bug_ignored = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001310 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001311
Steven Rostedta75fece2010-11-02 14:58:27 -04001312 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001313
1314 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001315 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001316 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001317 last if (!defined($line));
1318 print "$line";
1319 $full_line .= $line;
1320
1321 if (defined($stop) && $full_line =~ /$stop/) {
1322 doprint "wait for monitor detected $stop\n";
1323 $booted = 1;
1324 }
1325
Steven Rostedt8a80c722012-07-19 16:08:33 -04001326 if ($full_line =~ /\[ backtrace testing \]/) {
1327 $skip_call_trace = 1;
1328 }
1329
1330 if ($full_line =~ /call trace:/i) {
1331 if (!$bug && !$skip_call_trace) {
1332 if ($ignore_errors) {
1333 $bug_ignored = 1;
1334 } else {
1335 $bug = 1;
1336 }
1337 }
1338 }
1339
1340 if ($full_line =~ /\[ end of backtrace testing \]/) {
1341 $skip_call_trace = 0;
1342 }
1343
1344 if ($full_line =~ /Kernel panic -/) {
1345 $bug = 1;
1346 }
1347
Steven Rostedt2b803362011-09-30 18:00:23 -04001348 if ($line =~ /\n/) {
1349 $full_line = "";
1350 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001351 $now = time;
1352 if ($now - $start_time >= $max_monitor_wait) {
1353 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1354 return 1;
1355 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001356 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001357 print "** Monitor flushed **\n";
Steven Rostedt8a80c722012-07-19 16:08:33 -04001358 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001359}
1360
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301361sub save_logs {
1362 my ($result, $basedir) = @_;
1363 my @t = localtime;
1364 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1365 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1366
1367 my $type = $build_type;
1368 if ($type =~ /useconfig/) {
1369 $type = "useconfig";
1370 }
1371
1372 my $dir = "$machine-$test_type-$type-$result-$date";
1373
1374 $dir = "$basedir/$dir";
1375
1376 if (!-d $dir) {
1377 mkpath($dir) or
1378 die "can't create $dir";
1379 }
1380
1381 my %files = (
1382 "config" => $output_config,
1383 "buildlog" => $buildlog,
1384 "dmesg" => $dmesg,
1385 "testlog" => $testlog,
1386 );
1387
1388 while (my ($name, $source) = each(%files)) {
1389 if (-f "$source") {
1390 cp "$source", "$dir/$name" or
1391 die "failed to copy $source";
1392 }
1393 }
1394
1395 doprint "*** Saved info to $dir ***\n";
1396}
1397
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001398sub fail {
1399
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001400 if (defined($post_test)) {
1401 run_command $post_test;
1402 }
1403
Steven Rostedta75fece2010-11-02 14:58:27 -04001404 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001405 dodie @_;
1406 }
1407
Steven Rostedta75fece2010-11-02 14:58:27 -04001408 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001409
Steven Rostedt576f6272010-11-02 14:58:38 -04001410 my $i = $iteration;
1411
Steven Rostedta75fece2010-11-02 14:58:27 -04001412 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001413 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001414 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001415 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001416 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001417
Steven Rostedt9064af52011-06-13 10:38:48 -04001418 my $name = "";
1419
1420 if (defined($test_name)) {
1421 $name = " ($test_name)";
1422 }
1423
Steven Rostedt576f6272010-11-02 14:58:38 -04001424 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1425 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001426 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001427 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1428 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001429
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301430 if (defined($store_failures)) {
1431 save_logs "fail", $store_failures;
1432 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001433
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001434 return 1;
1435}
1436
Steven Rostedt2545eb62010-11-02 15:01:32 -04001437sub run_command {
1438 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001439 my $dolog = 0;
1440 my $dord = 0;
1441 my $pid;
1442
Steven Rostedte48c5292010-11-02 14:35:37 -04001443 $command =~ s/\$SSH_USER/$ssh_user/g;
1444 $command =~ s/\$MACHINE/$machine/g;
1445
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001446 doprint("$command ... ");
1447
1448 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001449 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001450
1451 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001452 open(LOG, ">>$opt{LOG_FILE}") or
1453 dodie "failed to write to log";
1454 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001455 }
1456
1457 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001458 open (RD, ">$redirect") or
1459 dodie "failed to write to redirect $redirect";
1460 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001461 }
1462
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001463 while (<CMD>) {
1464 print LOG if ($dolog);
1465 print RD if ($dord);
1466 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001467
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001468 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001469 my $failed = $?;
1470
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001471 close(CMD);
1472 close(LOG) if ($dolog);
1473 close(RD) if ($dord);
1474
Steven Rostedt2545eb62010-11-02 15:01:32 -04001475 if ($failed) {
1476 doprint "FAILED!\n";
1477 } else {
1478 doprint "SUCCESS\n";
1479 }
1480
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001481 return !$failed;
1482}
1483
Steven Rostedte48c5292010-11-02 14:35:37 -04001484sub run_ssh {
1485 my ($cmd) = @_;
1486 my $cp_exec = $ssh_exec;
1487
1488 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1489 return run_command "$cp_exec";
1490}
1491
1492sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001493 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001494
1495 $cp_scp =~ s/\$SRC_FILE/$src/g;
1496 $cp_scp =~ s/\$DST_FILE/$dst/g;
1497
1498 return run_command "$cp_scp";
1499}
1500
Steven Rostedt02ad2612012-03-21 08:21:24 -04001501sub run_scp_install {
1502 my ($src, $dst) = @_;
1503
1504 my $cp_scp = $scp_to_target_install;
1505
1506 return run_scp($src, $dst, $cp_scp);
1507}
1508
1509sub run_scp_mod {
1510 my ($src, $dst) = @_;
1511
1512 my $cp_scp = $scp_to_target;
1513
1514 return run_scp($src, $dst, $cp_scp);
1515}
1516
Steven Rostedta15ba912012-11-13 14:30:37 -05001517sub get_grub2_index {
1518
1519 return if (defined($grub_number));
1520
1521 doprint "Find grub2 menu ... ";
1522 $grub_number = -1;
1523
1524 my $ssh_grub = $ssh_exec;
1525 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1526
1527 open(IN, "$ssh_grub |")
1528 or die "unable to get $grub_file";
1529
1530 my $found = 0;
1531
1532 while (<IN>) {
1533 if (/^menuentry.*$grub_menu/) {
1534 $grub_number++;
1535 $found = 1;
1536 last;
1537 } elsif (/^menuentry\s/) {
1538 $grub_number++;
1539 }
1540 }
1541 close(IN);
1542
1543 die "Could not find '$grub_menu' in $grub_file on $machine"
1544 if (!$found);
1545 doprint "$grub_number\n";
1546}
1547
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001548sub get_grub_index {
1549
Steven Rostedta15ba912012-11-13 14:30:37 -05001550 if ($reboot_type eq "grub2") {
1551 get_grub2_index;
1552 return;
1553 }
1554
Steven Rostedta75fece2010-11-02 14:58:27 -04001555 if ($reboot_type ne "grub") {
1556 return;
1557 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001558 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001559
1560 doprint "Find grub menu ... ";
1561 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001562
1563 my $ssh_grub = $ssh_exec;
1564 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1565
1566 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001567 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001568
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001569 my $found = 0;
1570
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001571 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001572 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001573 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001574 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001575 last;
1576 } elsif (/^\s*title\s/) {
1577 $grub_number++;
1578 }
1579 }
1580 close(IN);
1581
Steven Rostedta75fece2010-11-02 14:58:27 -04001582 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001583 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001584 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001585}
1586
Steven Rostedt2545eb62010-11-02 15:01:32 -04001587sub wait_for_input
1588{
1589 my ($fp, $time) = @_;
1590 my $rin;
1591 my $ready;
1592 my $line;
1593 my $ch;
1594
1595 if (!defined($time)) {
1596 $time = $timeout;
1597 }
1598
1599 $rin = '';
1600 vec($rin, fileno($fp), 1) = 1;
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001601 ($ready, $time) = select($rin, undef, undef, $time);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001602
1603 $line = "";
1604
1605 # try to read one char at a time
1606 while (sysread $fp, $ch, 1) {
1607 $line .= $ch;
1608 last if ($ch eq "\n");
1609 }
1610
1611 if (!length($line)) {
1612 return undef;
1613 }
1614
1615 return $line;
1616}
1617
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001618sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001619 if (defined($switch_to_test)) {
1620 run_command $switch_to_test;
1621 }
1622
Steven Rostedta75fece2010-11-02 14:58:27 -04001623 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001624 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedta15ba912012-11-13 14:30:37 -05001625 } elsif ($reboot_type eq "grub2") {
1626 run_ssh "$grub_reboot $grub_number";
Steven Rostedt77869542012-12-11 17:37:41 -05001627 } elsif ($reboot_type eq "syslinux") {
1628 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001629 } elsif (defined $reboot_script) {
1630 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001631 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001632 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001633}
1634
Steven Rostedta57419b2010-11-02 15:13:54 -04001635sub get_sha1 {
1636 my ($commit) = @_;
1637
1638 doprint "git rev-list --max-count=1 $commit ... ";
1639 my $sha1 = `git rev-list --max-count=1 $commit`;
1640 my $ret = $?;
1641
1642 logit $sha1;
1643
1644 if ($ret) {
1645 doprint "FAILED\n";
1646 dodie "Failed to get git $commit";
1647 }
1648
1649 print "SUCCESS\n";
1650
1651 chomp $sha1;
1652
1653 return $sha1;
1654}
1655
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001656sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001657 my $booted = 0;
1658 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001659 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001660 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001661 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001662
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001663 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001664
1665 my $line;
1666 my $full_line = "";
1667
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001668 open(DMESG, "> $dmesg") or
1669 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001670
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001671 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001672
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001673 my $success_start;
1674 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001675 my $monitor_start = time;
1676 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001677 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001678
Steven Rostedt2d01b262011-03-08 09:47:54 -05001679 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001680
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001681 if ($bug && defined($stop_after_failure) &&
1682 $stop_after_failure >= 0) {
1683 my $time = $stop_after_failure - (time - $failure_start);
1684 $line = wait_for_input($monitor_fp, $time);
1685 if (!defined($line)) {
1686 doprint "bug timed out after $booted_timeout seconds\n";
1687 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1688 last;
1689 }
1690 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001691 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001692 if (!defined($line)) {
1693 my $s = $booted_timeout == 1 ? "" : "s";
1694 doprint "Successful boot found: break after $booted_timeout second$s\n";
1695 last;
1696 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001697 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001698 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001699 if (!defined($line)) {
1700 my $s = $timeout == 1 ? "" : "s";
1701 doprint "Timed out after $timeout second$s\n";
1702 last;
1703 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001704 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001705
Steven Rostedt2545eb62010-11-02 15:01:32 -04001706 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001707 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001708
1709 # we are not guaranteed to get a full line
1710 $full_line .= $line;
1711
Steven Rostedta75fece2010-11-02 14:58:27 -04001712 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001713 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001714 $success_start = time;
1715 }
1716
1717 if ($booted && defined($stop_after_success) &&
1718 $stop_after_success >= 0) {
1719 my $now = time;
1720 if ($now - $success_start >= $stop_after_success) {
1721 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1722 last;
1723 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001724 }
1725
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001726 if ($full_line =~ /\[ backtrace testing \]/) {
1727 $skip_call_trace = 1;
1728 }
1729
Steven Rostedt2545eb62010-11-02 15:01:32 -04001730 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001731 if (!$bug && !$skip_call_trace) {
1732 if ($ignore_errors) {
1733 $bug_ignored = 1;
1734 } else {
1735 $bug = 1;
1736 $failure_start = time;
1737 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001738 }
1739 }
1740
1741 if ($bug && defined($stop_after_failure) &&
1742 $stop_after_failure >= 0) {
1743 my $now = time;
1744 if ($now - $failure_start >= $stop_after_failure) {
1745 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1746 last;
1747 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001748 }
1749
1750 if ($full_line =~ /\[ end of backtrace testing \]/) {
1751 $skip_call_trace = 0;
1752 }
1753
1754 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001755 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001756 $bug = 1;
1757 }
1758
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001759 # Detect triple faults by testing the banner
1760 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1761 if ($1 eq $version) {
1762 $version_found = 1;
1763 } elsif ($version_found && $detect_triplefault) {
1764 # We already booted into the kernel we are testing,
1765 # but now we booted into another kernel?
1766 # Consider this a triple fault.
1767 doprint "Aleady booted in Linux kernel $version, but now\n";
1768 doprint "we booted into Linux kernel $1.\n";
1769 doprint "Assuming that this is a triple fault.\n";
1770 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1771 last;
1772 }
1773 }
1774
Steven Rostedt2545eb62010-11-02 15:01:32 -04001775 if ($line =~ /\n/) {
1776 $full_line = "";
1777 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001778
1779 if ($stop_test_after > 0 && !$booted && !$bug) {
1780 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001781 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001782 $done = 1;
1783 }
1784 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001785 }
1786
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001787 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001788
Steven Rostedt2545eb62010-11-02 15:01:32 -04001789 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001790 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001791 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001792 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001793
Steven Rostedta75fece2010-11-02 14:58:27 -04001794 if (!$booted) {
1795 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001796 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001797 }
1798
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001799 if ($bug_ignored) {
1800 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1801 }
1802
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001803 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001804}
1805
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001806sub eval_kernel_version {
1807 my ($option) = @_;
1808
1809 $option =~ s/\$KERNEL_VERSION/$version/g;
1810
1811 return $option;
1812}
1813
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001814sub do_post_install {
1815
1816 return if (!defined($post_install));
1817
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001818 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001819 run_command "$cp_post_install" or
1820 dodie "Failed to run post install";
1821}
1822
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001823# Sometimes the reboot fails, and will hang. We try to ssh to the box
1824# and if we fail, we force another reboot, that should powercycle it.
1825sub test_booted {
1826 if (!run_ssh "echo testing connection") {
1827 reboot $sleep_time;
1828 }
1829}
1830
Steven Rostedt2545eb62010-11-02 15:01:32 -04001831sub install {
1832
Steven Rostedte0a87422011-09-30 17:50:48 -04001833 return if ($no_install);
1834
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001835 if (defined($pre_install)) {
1836 my $cp_pre_install = eval_kernel_version $pre_install;
1837 run_command "$cp_pre_install" or
1838 dodie "Failed to run pre install";
1839 }
1840
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001841 my $cp_target = eval_kernel_version $target_image;
1842
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001843 test_booted;
1844
Steven Rostedt02ad2612012-03-21 08:21:24 -04001845 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001846 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001847
1848 my $install_mods = 0;
1849
1850 # should we process modules?
1851 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001852 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001853 while (<IN>) {
1854 if (/CONFIG_MODULES(=y)?/) {
Steven Rostedt8bc5e4e2012-10-26 00:10:32 -04001855 if (defined($1)) {
1856 $install_mods = 1;
1857 last;
1858 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001859 }
1860 }
1861 close(IN);
1862
1863 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001864 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001865 doprint "No modules needed\n";
1866 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001867 }
1868
Steven Rostedt627977d2012-03-21 08:16:15 -04001869 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001870 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001871
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001872 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001873 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001874
Steven Rostedte48c5292010-11-02 14:35:37 -04001875 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001876 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001877
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001878 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001879 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001880 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001881
Steven Rostedt02ad2612012-03-21 08:21:24 -04001882 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001883 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001884
Steven Rostedta75fece2010-11-02 14:58:27 -04001885 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001886
Steven Rostedte7b13442011-06-14 20:44:36 -04001887 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001888 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001889
Steven Rostedte48c5292010-11-02 14:35:37 -04001890 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001891
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001892 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001893}
1894
Steven Rostedtddf607e2011-06-14 20:49:13 -04001895sub get_version {
1896 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04001897 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001898 doprint "$make kernelrelease ... ";
1899 $version = `$make kernelrelease | tail -1`;
1900 chomp($version);
1901 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04001902 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04001903}
1904
1905sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001906 # Make sure the stable kernel has finished booting
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001907
1908 # Install bisects, don't need console
1909 if (defined $console) {
1910 start_monitor;
1911 wait_for_monitor 5;
1912 end_monitor;
1913 }
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001914
Steven Rostedtddf607e2011-06-14 20:49:13 -04001915 get_grub_index;
1916 get_version;
1917 install;
1918
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001919 start_monitor if (defined $console);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001920 return monitor;
1921}
1922
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001923sub check_buildlog {
1924 my ($patch) = @_;
1925
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001926 my @files = `git show $patch | diffstat -l`;
1927
Steven Rostedt (Red Hat)35275682013-01-30 12:28:15 -05001928 foreach my $file (@files) {
1929 chomp $file;
1930 }
1931
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001932 open(IN, "git show $patch |") or
1933 dodie "failed to show $patch";
1934 while (<IN>) {
1935 if (m,^--- a/(.*),) {
1936 chomp $1;
1937 $files[$#files] = $1;
1938 }
1939 }
1940 close(IN);
1941
1942 open(IN, $buildlog) or dodie "Can't open $buildlog";
1943 while (<IN>) {
1944 if (/^\s*(.*?):.*(warning|error)/) {
1945 my $err = $1;
1946 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001947 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001948 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001949 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001950 }
1951 }
1952 }
1953 }
1954 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001955
1956 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001957}
1958
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001959sub apply_min_config {
1960 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001961
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001962 # Read the config file and remove anything that
1963 # is in the force_config hash (from minconfig and others)
1964 # then add the force config back.
1965
1966 doprint "Applying minimum configurations into $output_config.new\n";
1967
1968 open (OUT, ">$outconfig") or
1969 dodie "Can't create $outconfig";
1970
1971 if (-f $output_config) {
1972 open (IN, $output_config) or
1973 dodie "Failed to open $output_config";
1974 while (<IN>) {
1975 if (/^(# )?(CONFIG_[^\s=]*)/) {
1976 next if (defined($force_config{$2}));
1977 }
1978 print OUT;
1979 }
1980 close IN;
1981 }
1982 foreach my $config (keys %force_config) {
1983 print OUT "$force_config{$config}\n";
1984 }
1985 close OUT;
1986
1987 run_command "mv $outconfig $output_config";
1988}
1989
1990sub make_oldconfig {
1991
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001992 my @force_list = keys %force_config;
1993
1994 if ($#force_list >= 0) {
1995 apply_min_config;
1996 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001997
Adam Leefb16d892012-09-01 01:05:17 +08001998 if (!run_command "$make olddefconfig") {
1999 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt18925172012-12-11 20:16:03 -05002000 # try oldnoconfig
2001 doprint "olddefconfig failed, trying make oldnoconfig\n";
2002 if (!run_command "$make oldnoconfig") {
2003 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2004 # try a yes '' | oldconfig
2005 run_command "yes '' | $make oldconfig" or
2006 dodie "failed make config oldconfig";
2007 }
Steven Rostedt612b9e92011-03-07 13:27:43 -05002008 }
2009}
2010
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002011# read a config file and use this to force new configs.
2012sub load_force_config {
2013 my ($config) = @_;
2014
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002015 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002016 open(IN, $config) or
2017 dodie "failed to read $config";
2018 while (<IN>) {
2019 chomp;
2020 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2021 $force_config{$1} = $_;
2022 } elsif (/^# (CONFIG_\S*) is not set/) {
2023 $force_config{$1} = $_;
2024 }
2025 }
2026 close IN;
2027}
2028
Steven Rostedt2545eb62010-11-02 15:01:32 -04002029sub build {
2030 my ($type) = @_;
2031
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002032 unlink $buildlog;
2033
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002034 # Failed builds should not reboot the target
2035 my $save_no_reboot = $no_reboot;
2036 $no_reboot = 1;
2037
Steven Rostedt683a3e62012-05-18 13:34:35 -04002038 # Calculate a new version from here.
2039 $have_version = 0;
2040
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002041 if (defined($pre_build)) {
2042 my $ret = run_command $pre_build;
2043 if (!$ret && defined($pre_build_die) &&
2044 $pre_build_die) {
2045 dodie "failed to pre_build\n";
2046 }
2047 }
2048
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002049 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002050 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002051 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002052
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002053 $type = "oldconfig";
2054 }
2055
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002056 # old config can ask questions
2057 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08002058 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002059
2060 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002061 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002062
Andrew Jones13488232011-08-12 15:32:04 +02002063 if (!$noclean) {
2064 run_command "mv $output_config $outputdir/config_temp" or
2065 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002066
Andrew Jones13488232011-08-12 15:32:04 +02002067 run_command "$make mrproper" or dodie "make mrproper";
2068
2069 run_command "mv $outputdir/config_temp $output_config" or
2070 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002071 }
2072
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002073 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002074 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002075 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002076 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002077 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002078
2079 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04002080 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2081 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002082 close(OUT);
2083
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002084 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002085 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002086 }
2087
Adam Leefb16d892012-09-01 01:05:17 +08002088 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002089 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05002090 dodie "failed make config";
2091 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002092 # Run old config regardless, to enforce min configurations
2093 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002094
Steven Rostedta75fece2010-11-02 14:58:27 -04002095 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002096 my $build_ret = run_command "$make $build_options";
2097 undef $redirect;
2098
2099 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04002100 # Because a post build may change the kernel version
2101 # do it now.
2102 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002103 my $ret = run_command $post_build;
2104 if (!$ret && defined($post_build_die) &&
2105 $post_build_die) {
2106 dodie "failed to post_build\n";
2107 }
2108 }
2109
2110 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002111 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002112 if ($in_bisect) {
2113 $no_reboot = $save_no_reboot;
2114 return 0;
2115 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002116 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002117 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002118
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002119 $no_reboot = $save_no_reboot;
2120
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002121 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002122}
2123
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002124sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04002125 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002126 if (defined($poweroff_after_halt)) {
2127 sleep $poweroff_after_halt;
2128 run_command "$power_off";
2129 }
2130 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002131 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04002132 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002133 }
2134}
2135
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002136sub success {
2137 my ($i) = @_;
2138
Steven Rostedt921ed4c2012-07-19 15:18:27 -04002139 if (defined($post_test)) {
2140 run_command $post_test;
2141 }
2142
Steven Rostedte48c5292010-11-02 14:35:37 -04002143 $successes++;
2144
Steven Rostedt9064af52011-06-13 10:38:48 -04002145 my $name = "";
2146
2147 if (defined($test_name)) {
2148 $name = " ($test_name)";
2149 }
2150
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002151 doprint "\n\n*******************************************\n";
2152 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04002153 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002154 doprint "*******************************************\n";
2155 doprint "*******************************************\n";
2156
Rabin Vincentde5b6e32011-11-18 17:05:31 +05302157 if (defined($store_successes)) {
2158 save_logs "success", $store_successes;
2159 }
2160
Steven Rostedt576f6272010-11-02 14:58:38 -04002161 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002162 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002163 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002164 }
2165}
2166
Steven Rostedtc960bb92011-03-08 09:22:39 -05002167sub answer_bisect {
2168 for (;;) {
2169 doprint "Pass or fail? [p/f]";
2170 my $ans = <STDIN>;
2171 chomp $ans;
2172 if ($ans eq "p" || $ans eq "P") {
2173 return 1;
2174 } elsif ($ans eq "f" || $ans eq "F") {
2175 return 0;
2176 } else {
2177 print "Please answer 'P' or 'F'\n";
2178 }
2179 }
2180}
2181
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002182sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002183 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002184
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002185 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002186 $reboot_on_error = 0;
2187 $poweroff_on_error = 0;
2188 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002189
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302190 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002191 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302192 undef $redirect;
2193
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002194 exit $failed;
2195}
2196
2197my $child_done;
2198
2199sub child_finished {
2200 $child_done = 1;
2201}
2202
2203sub do_run_test {
2204 my $child_pid;
2205 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002206 my $line;
2207 my $full_line;
2208 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002209 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002210
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002211 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002212
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002213 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002214
2215 $child_done = 0;
2216
2217 $SIG{CHLD} = qw(child_finished);
2218
2219 $child_pid = fork;
2220
2221 child_run_test if (!$child_pid);
2222
2223 $full_line = "";
2224
2225 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002226 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002227 if (defined($line)) {
2228
2229 # we are not guaranteed to get a full line
2230 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002231 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002232
2233 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002234 if ($ignore_errors) {
2235 $bug_ignored = 1;
2236 } else {
2237 $bug = 1;
2238 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002239 }
2240
2241 if ($full_line =~ /Kernel panic -/) {
2242 $bug = 1;
2243 }
2244
2245 if ($line =~ /\n/) {
2246 $full_line = "";
2247 }
2248 }
2249 } while (!$child_done && !$bug);
2250
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002251 if (!$bug && $bug_ignored) {
2252 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2253 }
2254
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002255 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002256 my $failure_start = time;
2257 my $now;
2258 do {
2259 $line = wait_for_input($monitor_fp, 1);
2260 if (defined($line)) {
2261 doprint $line;
2262 }
2263 $now = time;
2264 if ($now - $failure_start >= $stop_after_failure) {
2265 last;
2266 }
2267 } while (defined($line));
2268
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002269 doprint "Detected kernel crash!\n";
2270 # kill the child with extreme prejudice
2271 kill 9, $child_pid;
2272 }
2273
2274 waitpid $child_pid, 0;
2275 $child_exit = $?;
2276
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002277 if (!$bug && $in_bisect) {
2278 if (defined($bisect_ret_good)) {
2279 if ($child_exit == $bisect_ret_good) {
2280 return 1;
2281 }
2282 }
2283 if (defined($bisect_ret_skip)) {
2284 if ($child_exit == $bisect_ret_skip) {
2285 return -1;
2286 }
2287 }
2288 if (defined($bisect_ret_abort)) {
2289 if ($child_exit == $bisect_ret_abort) {
2290 fail "test abort" and return -2;
2291 }
2292 }
2293 if (defined($bisect_ret_bad)) {
2294 if ($child_exit == $bisect_ret_skip) {
2295 return 0;
2296 }
2297 }
2298 if (defined($bisect_ret_default)) {
2299 if ($bisect_ret_default eq "good") {
2300 return 1;
2301 } elsif ($bisect_ret_default eq "bad") {
2302 return 0;
2303 } elsif ($bisect_ret_default eq "skip") {
2304 return -1;
2305 } elsif ($bisect_ret_default eq "abort") {
2306 return -2;
2307 } else {
2308 fail "unknown default action: $bisect_ret_default"
2309 and return -2;
2310 }
2311 }
2312 }
2313
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002314 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002315 return 0 if $in_bisect;
2316 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002317 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002318 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002319}
2320
Steven Rostedta75fece2010-11-02 14:58:27 -04002321sub run_git_bisect {
2322 my ($command) = @_;
2323
2324 doprint "$command ... ";
2325
2326 my $output = `$command 2>&1`;
2327 my $ret = $?;
2328
2329 logit $output;
2330
2331 if ($ret) {
2332 doprint "FAILED\n";
2333 dodie "Failed to git bisect";
2334 }
2335
2336 doprint "SUCCESS\n";
2337 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2338 doprint "$1 [$2]\n";
2339 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002340 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002341 doprint "Found bad commit... $1\n";
2342 return 0;
2343 } else {
2344 # we already logged it, just print it now.
2345 print $output;
2346 }
2347
2348 return 1;
2349}
2350
Steven Rostedtc23dca72011-03-08 09:26:31 -05002351sub bisect_reboot {
2352 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002353 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002354}
2355
2356# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002357sub run_bisect_test {
2358 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002359
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002360 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002361 my $result;
2362 my $output;
2363 my $ret;
2364
Steven Rostedt0a05c762010-11-08 11:14:10 -05002365 $in_bisect = 1;
2366
2367 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002368
2369 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002370 if ($failed && $bisect_skip) {
2371 $in_bisect = 0;
2372 return -1;
2373 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002374 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002375
2376 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002377 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002378
2379 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002380 if ($failed && $bisect_skip) {
2381 end_monitor;
2382 bisect_reboot;
2383 $in_bisect = 0;
2384 return -1;
2385 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002386 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002387
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002388 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002389 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002390 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002391 }
2392
2393 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002394 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002395 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002396 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002397 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002398
2399 # reboot the box to a kernel we can ssh to
2400 if ($type ne "build") {
2401 bisect_reboot;
2402 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002403 $in_bisect = 0;
2404
2405 return $result;
2406}
2407
2408sub run_bisect {
2409 my ($type) = @_;
2410 my $buildtype = "oldconfig";
2411
2412 # We should have a minconfig to use?
2413 if (defined($minconfig)) {
2414 $buildtype = "useconfig:$minconfig";
2415 }
2416
2417 my $ret = run_bisect_test $type, $buildtype;
2418
Steven Rostedtc960bb92011-03-08 09:22:39 -05002419 if ($bisect_manual) {
2420 $ret = answer_bisect;
2421 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002422
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002423 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002424 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002425 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002426 }
2427
Steven Rostedtc23dca72011-03-08 09:26:31 -05002428 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002429 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002430 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002431 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002432 } elsif ($bisect_skip) {
2433 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2434 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002435 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002436}
2437
Steven Rostedtdad98752011-11-22 20:48:57 -05002438sub update_bisect_replay {
2439 my $tmp_log = "$tmpdir/ktest_bisect_log";
2440 run_command "git bisect log > $tmp_log" or
2441 die "can't create bisect log";
2442 return $tmp_log;
2443}
2444
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002445sub bisect {
2446 my ($i) = @_;
2447
2448 my $result;
2449
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002450 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2451 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2452 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002453
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002454 my $good = $bisect_good;
2455 my $bad = $bisect_bad;
2456 my $type = $bisect_type;
2457 my $start = $bisect_start;
2458 my $replay = $bisect_replay;
2459 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002460
2461 if (defined($start_files)) {
2462 $start_files = " -- " . $start_files;
2463 } else {
2464 $start_files = "";
2465 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002466
Steven Rostedta57419b2010-11-02 15:13:54 -04002467 # convert to true sha1's
2468 $good = get_sha1($good);
2469 $bad = get_sha1($bad);
2470
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002471 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002472 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2473 $reverse_bisect = 1;
2474 } else {
2475 $reverse_bisect = 0;
2476 }
2477
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002478 # Can't have a test without having a test to run
2479 if ($type eq "test" && !defined($run_test)) {
2480 $type = "boot";
2481 }
2482
Steven Rostedtdad98752011-11-22 20:48:57 -05002483 # Check if a bisect was running
2484 my $bisect_start_file = "$builddir/.git/BISECT_START";
2485
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002486 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002487 my $do_check = defined($check) && $check ne "0";
2488
2489 if ( -f $bisect_start_file ) {
2490 print "Bisect in progress found\n";
2491 if ($do_check) {
2492 print " If you say yes, then no checks of good or bad will be done\n";
2493 }
2494 if (defined($replay)) {
2495 print "** BISECT_REPLAY is defined in config file **";
2496 print " Ignore config option and perform new git bisect log?\n";
2497 if (read_ync " (yes, no, or cancel) ") {
2498 $replay = update_bisect_replay;
2499 $do_check = 0;
2500 }
2501 } elsif (read_yn "read git log and continue?") {
2502 $replay = update_bisect_replay;
2503 $do_check = 0;
2504 }
2505 }
2506
2507 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002508
2509 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002510 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002511
2512 if ($check ne "good") {
2513 doprint "TESTING BISECT BAD [$bad]\n";
2514 run_command "git checkout $bad" or
2515 die "Failed to checkout $bad";
2516
2517 $result = run_bisect $type;
2518
2519 if ($result ne "bad") {
2520 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2521 }
2522 }
2523
2524 if ($check ne "bad") {
2525 doprint "TESTING BISECT GOOD [$good]\n";
2526 run_command "git checkout $good" or
2527 die "Failed to checkout $good";
2528
2529 $result = run_bisect $type;
2530
2531 if ($result ne "good") {
2532 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2533 }
2534 }
2535
2536 # checkout where we started
2537 run_command "git checkout $head" or
2538 die "Failed to checkout $head";
2539 }
2540
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002541 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002542 dodie "could not start bisect";
2543
2544 run_command "git bisect good $good" or
2545 dodie "could not set bisect good to $good";
2546
2547 run_git_bisect "git bisect bad $bad" or
2548 dodie "could not set bisect bad to $bad";
2549
2550 if (defined($replay)) {
2551 run_command "git bisect replay $replay" or
2552 dodie "failed to run replay";
2553 }
2554
2555 if (defined($start)) {
2556 run_command "git checkout $start" or
2557 dodie "failed to checkout $start";
2558 }
2559
2560 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002561 do {
2562 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002563 $test = run_git_bisect "git bisect $result";
2564 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002565
2566 run_command "git bisect log" or
2567 dodie "could not capture git bisect log";
2568
2569 run_command "git bisect reset" or
2570 dodie "could not reset git bisect";
2571
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002572 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002573
Steven Rostedt0a05c762010-11-08 11:14:10 -05002574 success $i;
2575}
2576
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002577# config_ignore holds the configs that were set (or unset) for
2578# a good config and we will ignore these configs for the rest
2579# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002580my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002581
2582# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002583my %config_set;
2584
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002585# config_off holds the set of configs that the bad config had disabled.
2586# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08002587# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002588my %config_off;
2589
2590# config_off_tmp holds a set of configs to turn off for now
2591my @config_off_tmp;
2592
2593# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002594my %config_list;
2595my %null_config;
2596
2597my %dependency;
2598
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002599sub assign_configs {
2600 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002601
2602 open (IN, $config)
2603 or dodie "Failed to read $config";
2604
2605 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002606 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002607 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002608 }
2609 }
2610
2611 close(IN);
2612}
2613
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002614sub process_config_ignore {
2615 my ($config) = @_;
2616
2617 assign_configs \%config_ignore, $config;
2618}
2619
Steven Rostedt0a05c762010-11-08 11:14:10 -05002620sub read_current_config {
2621 my ($config_ref) = @_;
2622
2623 %{$config_ref} = ();
2624 undef %{$config_ref};
2625
2626 my @key = keys %{$config_ref};
2627 if ($#key >= 0) {
2628 print "did not delete!\n";
2629 exit;
2630 }
2631 open (IN, "$output_config");
2632
2633 while (<IN>) {
2634 if (/^(CONFIG\S+)=(.*)/) {
2635 ${$config_ref}{$1} = $2;
2636 }
2637 }
2638 close(IN);
2639}
2640
2641sub get_dependencies {
2642 my ($config) = @_;
2643
2644 my $arr = $dependency{$config};
2645 if (!defined($arr)) {
2646 return ();
2647 }
2648
2649 my @deps = @{$arr};
2650
2651 foreach my $dep (@{$arr}) {
2652 print "ADD DEP $dep\n";
2653 @deps = (@deps, get_dependencies $dep);
2654 }
2655
2656 return @deps;
2657}
2658
2659sub create_config {
2660 my @configs = @_;
2661
2662 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2663
2664 foreach my $config (@configs) {
2665 print OUT "$config_set{$config}\n";
2666 my @deps = get_dependencies $config;
2667 foreach my $dep (@deps) {
2668 print OUT "$config_set{$dep}\n";
2669 }
2670 }
2671
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002672 # turn off configs to keep off
2673 foreach my $config (keys %config_off) {
2674 print OUT "# $config is not set\n";
2675 }
2676
2677 # turn off configs that should be off for now
2678 foreach my $config (@config_off_tmp) {
2679 print OUT "# $config is not set\n";
2680 }
2681
Steven Rostedt0a05c762010-11-08 11:14:10 -05002682 foreach my $config (keys %config_ignore) {
2683 print OUT "$config_ignore{$config}\n";
2684 }
2685 close(OUT);
2686
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002687 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002688}
2689
2690sub compare_configs {
2691 my (%a, %b) = @_;
2692
2693 foreach my $item (keys %a) {
2694 if (!defined($b{$item})) {
2695 print "diff $item\n";
2696 return 1;
2697 }
2698 delete $b{$item};
2699 }
2700
2701 my @keys = keys %b;
2702 if ($#keys) {
2703 print "diff2 $keys[0]\n";
2704 }
2705 return -1 if ($#keys >= 0);
2706
2707 return 0;
2708}
2709
2710sub run_config_bisect_test {
2711 my ($type) = @_;
2712
2713 return run_bisect_test $type, "oldconfig";
2714}
2715
2716sub process_passed {
2717 my (%configs) = @_;
2718
2719 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2720 # Passed! All these configs are part of a good compile.
2721 # Add them to the min options.
2722 foreach my $config (keys %configs) {
2723 if (defined($config_list{$config})) {
2724 doprint " removing $config\n";
2725 $config_ignore{$config} = $config_list{$config};
2726 delete $config_list{$config};
2727 }
2728 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002729 doprint "config copied to $outputdir/config_good\n";
2730 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002731}
2732
2733sub process_failed {
2734 my ($config) = @_;
2735
2736 doprint "\n\n***************************************\n";
2737 doprint "Found bad config: $config\n";
2738 doprint "***************************************\n\n";
2739}
2740
2741sub run_config_bisect {
2742
2743 my @start_list = keys %config_list;
2744
2745 if ($#start_list < 0) {
2746 doprint "No more configs to test!!!\n";
2747 return -1;
2748 }
2749
2750 doprint "***** RUN TEST ***\n";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002751 my $type = $config_bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002752 my $ret;
2753 my %current_config;
2754
2755 my $count = $#start_list + 1;
2756 doprint " $count configs to test\n";
2757
2758 my $half = int($#start_list / 2);
2759
2760 do {
2761 my @tophalf = @start_list[0 .. $half];
2762
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002763 # keep the bottom half off
2764 if ($half < $#start_list) {
2765 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2766 } else {
2767 @config_off_tmp = ();
2768 }
2769
Steven Rostedt0a05c762010-11-08 11:14:10 -05002770 create_config @tophalf;
2771 read_current_config \%current_config;
2772
2773 $count = $#tophalf + 1;
2774 doprint "Testing $count configs\n";
2775 my $found = 0;
2776 # make sure we test something
2777 foreach my $config (@tophalf) {
2778 if (defined($current_config{$config})) {
2779 logit " $config\n";
2780 $found = 1;
2781 }
2782 }
2783 if (!$found) {
2784 # try the other half
2785 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002786
2787 # keep the top half off
2788 @config_off_tmp = @tophalf;
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002789 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002790
Steven Rostedt0a05c762010-11-08 11:14:10 -05002791 create_config @tophalf;
2792 read_current_config \%current_config;
2793 foreach my $config (@tophalf) {
2794 if (defined($current_config{$config})) {
2795 logit " $config\n";
2796 $found = 1;
2797 }
2798 }
2799 if (!$found) {
2800 doprint "Failed: Can't make new config with current configs\n";
2801 foreach my $config (@start_list) {
2802 doprint " CONFIG: $config\n";
2803 }
2804 return -1;
2805 }
2806 $count = $#tophalf + 1;
2807 doprint "Testing $count configs\n";
2808 }
2809
2810 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002811 if ($bisect_manual) {
2812 $ret = answer_bisect;
2813 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002814 if ($ret) {
2815 process_passed %current_config;
2816 return 0;
2817 }
2818
2819 doprint "This config had a failure.\n";
2820 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002821 doprint "config copied to $outputdir/config_bad\n";
2822 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002823
2824 # A config exists in this group that was bad.
2825 foreach my $config (keys %config_list) {
2826 if (!defined($current_config{$config})) {
2827 doprint " removing $config\n";
2828 delete $config_list{$config};
2829 }
2830 }
2831
2832 @start_list = @tophalf;
2833
2834 if ($#start_list == 0) {
2835 process_failed $start_list[0];
2836 return 1;
2837 }
2838
2839 # remove half the configs we are looking at and see if
2840 # they are good.
2841 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002842 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002843
Steven Rostedtc960bb92011-03-08 09:22:39 -05002844 # we found a single config, try it again unless we are running manually
2845
2846 if ($bisect_manual) {
2847 process_failed $start_list[0];
2848 return 1;
2849 }
2850
Steven Rostedt0a05c762010-11-08 11:14:10 -05002851 my @tophalf = @start_list[0 .. 0];
2852
2853 $ret = run_config_bisect_test $type;
2854 if ($ret) {
2855 process_passed %current_config;
2856 return 0;
2857 }
2858
2859 process_failed $start_list[0];
2860 return 1;
2861}
2862
2863sub config_bisect {
2864 my ($i) = @_;
2865
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002866 my $start_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002867
2868 my $tmpconfig = "$tmpdir/use_config";
2869
Steven Rostedt30f75da2011-06-13 10:35:35 -04002870 if (defined($config_bisect_good)) {
2871 process_config_ignore $config_bisect_good;
2872 }
2873
Steven Rostedt0a05c762010-11-08 11:14:10 -05002874 # Make the file with the bad config and the min config
2875 if (defined($minconfig)) {
2876 # read the min config for things to ignore
2877 run_command "cp $minconfig $tmpconfig" or
2878 dodie "failed to copy $minconfig to $tmpconfig";
2879 } else {
2880 unlink $tmpconfig;
2881 }
2882
Steven Rostedt0a05c762010-11-08 11:14:10 -05002883 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002884 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002885 process_config_ignore $tmpconfig;
2886 }
2887
2888 # now process the start config
2889 run_command "cp $start_config $output_config" or
2890 dodie "failed to copy $start_config to $output_config";
2891
2892 # read directly what we want to check
2893 my %config_check;
2894 open (IN, $output_config)
Masanari Iidaf9dee312012-02-11 21:46:56 +09002895 or dodie "failed to open $output_config";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002896
2897 while (<IN>) {
2898 if (/^((CONFIG\S*)=.*)/) {
2899 $config_check{$2} = $1;
2900 }
2901 }
2902 close(IN);
2903
Steven Rostedt250bae82011-07-15 22:05:59 -04002904 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002905 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002906
2907 # check to see what we lost (or gained)
2908 open (IN, $output_config)
2909 or dodie "Failed to read $start_config";
2910
2911 my %removed_configs;
2912 my %added_configs;
2913
2914 while (<IN>) {
2915 if (/^((CONFIG\S*)=.*)/) {
2916 # save off all options
2917 $config_set{$2} = $1;
2918 if (defined($config_check{$2})) {
2919 if (defined($config_ignore{$2})) {
2920 $removed_configs{$2} = $1;
2921 } else {
2922 $config_list{$2} = $1;
2923 }
2924 } elsif (!defined($config_ignore{$2})) {
2925 $added_configs{$2} = $1;
2926 $config_list{$2} = $1;
2927 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002928 } elsif (/^# ((CONFIG\S*).*)/) {
2929 # Keep these configs disabled
2930 $config_set{$2} = $1;
2931 $config_off{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002932 }
2933 }
2934 close(IN);
2935
2936 my @confs = keys %removed_configs;
2937 if ($#confs >= 0) {
2938 doprint "Configs overridden by default configs and removed from check:\n";
2939 foreach my $config (@confs) {
2940 doprint " $config\n";
2941 }
2942 }
2943 @confs = keys %added_configs;
2944 if ($#confs >= 0) {
2945 doprint "Configs appearing in make oldconfig and added:\n";
2946 foreach my $config (@confs) {
2947 doprint " $config\n";
2948 }
2949 }
2950
2951 my %config_test;
2952 my $once = 0;
2953
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002954 @config_off_tmp = ();
2955
Steven Rostedt0a05c762010-11-08 11:14:10 -05002956 # Sometimes kconfig does weird things. We must make sure
2957 # that the config we autocreate has everything we need
2958 # to test, otherwise we may miss testing configs, or
2959 # may not be able to create a new config.
2960 # Here we create a config with everything set.
2961 create_config (keys %config_list);
2962 read_current_config \%config_test;
2963 foreach my $config (keys %config_list) {
2964 if (!defined($config_test{$config})) {
2965 if (!$once) {
2966 $once = 1;
2967 doprint "Configs not produced by kconfig (will not be checked):\n";
2968 }
2969 doprint " $config\n";
2970 delete $config_list{$config};
2971 }
2972 }
2973 my $ret;
Steven Rostedtb0918612012-07-19 15:26:00 -04002974
2975 if (defined($config_bisect_check) && $config_bisect_check) {
2976 doprint " Checking to make sure bad config with min config fails\n";
2977 create_config keys %config_list;
2978 $ret = run_config_bisect_test $config_bisect_type;
2979 if ($ret) {
2980 doprint " FAILED! Bad config with min config boots fine\n";
2981 return -1;
2982 }
2983 doprint " Bad config with min config fails as expected\n";
2984 }
2985
Steven Rostedt0a05c762010-11-08 11:14:10 -05002986 do {
2987 $ret = run_config_bisect;
2988 } while (!$ret);
2989
2990 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002991
2992 success $i;
2993}
2994
Steven Rostedt27d934b2011-05-20 09:18:18 -04002995sub patchcheck_reboot {
2996 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002997 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002998}
2999
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003000sub patchcheck {
3001 my ($i) = @_;
3002
3003 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003004 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003005 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003006 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003007
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003008 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003009
3010 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003011 if (defined($patchcheck_end)) {
3012 $end = $patchcheck_end;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003013 }
3014
Steven Rostedta57419b2010-11-02 15:13:54 -04003015 # Get the true sha1's since we can use things like HEAD~3
3016 $start = get_sha1($start);
3017 $end = get_sha1($end);
3018
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003019 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003020
3021 # Can't have a test without having a test to run
3022 if ($type eq "test" && !defined($run_test)) {
3023 $type = "boot";
3024 }
3025
3026 open (IN, "git log --pretty=oneline $end|") or
3027 dodie "could not get git list";
3028
3029 my @list;
3030
3031 while (<IN>) {
3032 chomp;
3033 $list[$#list+1] = $_;
3034 last if (/^$start/);
3035 }
3036 close(IN);
3037
3038 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003039 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003040 }
3041
3042 # go backwards in the list
3043 @list = reverse @list;
3044
3045 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003046 my %ignored_warnings;
3047
3048 if (defined($ignore_warnings)) {
3049 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3050 $ignored_warnings{$sha1} = 1;
3051 }
3052 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003053
3054 $in_patchcheck = 1;
3055 foreach my $item (@list) {
3056 my $sha1 = $item;
3057 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3058
3059 doprint "\nProcessing commit $item\n\n";
3060
3061 run_command "git checkout $sha1" or
3062 die "Failed to checkout $sha1";
3063
3064 # only clean on the first and last patch
3065 if ($item eq $list[0] ||
3066 $item eq $list[$#list]) {
3067 $noclean = $save_clean;
3068 } else {
3069 $noclean = 1;
3070 }
3071
3072 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003073 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003074 } else {
3075 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003076 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003077 }
3078
Steven Rostedt19902072011-06-14 20:46:25 -04003079
3080 if (!defined($ignored_warnings{$sha1})) {
3081 check_buildlog $sha1 or return 0;
3082 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003083
3084 next if ($type eq "build");
3085
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003086 my $failed = 0;
3087
Steven Rostedtddf607e2011-06-14 20:49:13 -04003088 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003089
3090 if (!$failed && $type ne "boot"){
3091 do_run_test or $failed = 1;
3092 }
3093 end_monitor;
3094 return 0 if ($failed);
3095
Steven Rostedt27d934b2011-05-20 09:18:18 -04003096 patchcheck_reboot;
3097
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003098 }
3099 $in_patchcheck = 0;
3100 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003101
3102 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003103}
3104
Steven Rostedtb9066f62011-07-15 21:25:24 -04003105my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003106my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003107my $iflevel = 0;
3108my @ifdeps;
3109
3110# prevent recursion
3111my %read_kconfigs;
3112
Steven Rostedtac6974c2011-10-04 09:40:17 -04003113sub add_dep {
3114 # $config depends on $dep
3115 my ($config, $dep) = @_;
3116
3117 if (defined($depends{$config})) {
3118 $depends{$config} .= " " . $dep;
3119 } else {
3120 $depends{$config} = $dep;
3121 }
3122
3123 # record the number of configs depending on $dep
3124 if (defined $depcount{$dep}) {
3125 $depcount{$dep}++;
3126 } else {
3127 $depcount{$dep} = 1;
3128 }
3129}
3130
Steven Rostedtb9066f62011-07-15 21:25:24 -04003131# taken from streamline_config.pl
3132sub read_kconfig {
3133 my ($kconfig) = @_;
3134
3135 my $state = "NONE";
3136 my $config;
3137 my @kconfigs;
3138
3139 my $cont = 0;
3140 my $line;
3141
3142
3143 if (! -f $kconfig) {
3144 doprint "file $kconfig does not exist, skipping\n";
3145 return;
3146 }
3147
3148 open(KIN, "$kconfig")
3149 or die "Can't open $kconfig";
3150 while (<KIN>) {
3151 chomp;
3152
3153 # Make sure that lines ending with \ continue
3154 if ($cont) {
3155 $_ = $line . " " . $_;
3156 }
3157
3158 if (s/\\$//) {
3159 $cont = 1;
3160 $line = $_;
3161 next;
3162 }
3163
3164 $cont = 0;
3165
3166 # collect any Kconfig sources
3167 if (/^source\s*"(.*)"/) {
3168 $kconfigs[$#kconfigs+1] = $1;
3169 }
3170
3171 # configs found
3172 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3173 $state = "NEW";
3174 $config = $2;
3175
3176 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003177 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003178 }
3179
3180 # collect the depends for the config
3181 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3182
Steven Rostedtac6974c2011-10-04 09:40:17 -04003183 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003184
3185 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003186 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3187
3188 # selected by depends on config
3189 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003190
3191 # Check for if statements
3192 } elsif (/^if\s+(.*\S)\s*$/) {
3193 my $deps = $1;
3194 # remove beginning and ending non text
3195 $deps =~ s/^[^a-zA-Z0-9_]*//;
3196 $deps =~ s/[^a-zA-Z0-9_]*$//;
3197
3198 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3199
3200 $ifdeps[$iflevel++] = join ':', @deps;
3201
3202 } elsif (/^endif/) {
3203
3204 $iflevel-- if ($iflevel);
3205
3206 # stop on "help"
3207 } elsif (/^\s*help\s*$/) {
3208 $state = "NONE";
3209 }
3210 }
3211 close(KIN);
3212
3213 # read in any configs that were found.
3214 foreach $kconfig (@kconfigs) {
3215 if (!defined($read_kconfigs{$kconfig})) {
3216 $read_kconfigs{$kconfig} = 1;
3217 read_kconfig("$builddir/$kconfig");
3218 }
3219 }
3220}
3221
3222sub read_depends {
3223 # find out which arch this is by the kconfig file
3224 open (IN, $output_config)
3225 or dodie "Failed to read $output_config";
3226 my $arch;
3227 while (<IN>) {
3228 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3229 $arch = $1;
3230 last;
3231 }
3232 }
3233 close IN;
3234
3235 if (!defined($arch)) {
3236 doprint "Could not find arch from config file\n";
3237 doprint "no dependencies used\n";
3238 return;
3239 }
3240
3241 # arch is really the subarch, we need to know
3242 # what directory to look at.
3243 if ($arch eq "i386" || $arch eq "x86_64") {
3244 $arch = "x86";
3245 } elsif ($arch =~ /^tile/) {
3246 $arch = "tile";
3247 }
3248
3249 my $kconfig = "$builddir/arch/$arch/Kconfig";
3250
3251 if (! -f $kconfig && $arch =~ /\d$/) {
3252 my $orig = $arch;
3253 # some subarchs have numbers, truncate them
3254 $arch =~ s/\d*$//;
3255 $kconfig = "$builddir/arch/$arch/Kconfig";
3256 if (! -f $kconfig) {
3257 doprint "No idea what arch dir $orig is for\n";
3258 doprint "no dependencies used\n";
3259 return;
3260 }
3261 }
3262
3263 read_kconfig($kconfig);
3264}
3265
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003266sub read_config_list {
3267 my ($config) = @_;
3268
3269 open (IN, $config)
3270 or dodie "Failed to read $config";
3271
3272 while (<IN>) {
3273 if (/^((CONFIG\S*)=.*)/) {
3274 if (!defined($config_ignore{$2})) {
3275 $config_list{$2} = $1;
3276 }
3277 }
3278 }
3279
3280 close(IN);
3281}
3282
3283sub read_output_config {
3284 my ($config) = @_;
3285
3286 assign_configs \%config_ignore, $config;
3287}
3288
3289sub make_new_config {
3290 my @configs = @_;
3291
3292 open (OUT, ">$output_config")
3293 or dodie "Failed to write $output_config";
3294
3295 foreach my $config (@configs) {
3296 print OUT "$config\n";
3297 }
3298 close OUT;
3299}
3300
Steven Rostedtac6974c2011-10-04 09:40:17 -04003301sub chomp_config {
3302 my ($config) = @_;
3303
3304 $config =~ s/CONFIG_//;
3305
3306 return $config;
3307}
3308
Steven Rostedtb9066f62011-07-15 21:25:24 -04003309sub get_depends {
3310 my ($dep) = @_;
3311
Steven Rostedtac6974c2011-10-04 09:40:17 -04003312 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003313
3314 $dep = $depends{"$kconfig"};
3315
3316 # the dep string we have saves the dependencies as they
3317 # were found, including expressions like ! && ||. We
3318 # want to split this out into just an array of configs.
3319
3320 my $valid = "A-Za-z_0-9";
3321
3322 my @configs;
3323
3324 while ($dep =~ /[$valid]/) {
3325
3326 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3327 my $conf = "CONFIG_" . $1;
3328
3329 $configs[$#configs + 1] = $conf;
3330
3331 $dep =~ s/^[^$valid]*[$valid]+//;
3332 } else {
3333 die "this should never happen";
3334 }
3335 }
3336
3337 return @configs;
3338}
3339
3340my %min_configs;
3341my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003342my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003343my %processed_configs;
3344my %nochange_config;
3345
3346sub test_this_config {
3347 my ($config) = @_;
3348
3349 my $found;
3350
3351 # if we already processed this config, skip it
3352 if (defined($processed_configs{$config})) {
3353 return undef;
3354 }
3355 $processed_configs{$config} = 1;
3356
3357 # if this config failed during this round, skip it
3358 if (defined($nochange_config{$config})) {
3359 return undef;
3360 }
3361
Steven Rostedtac6974c2011-10-04 09:40:17 -04003362 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003363
3364 # Test dependencies first
3365 if (defined($depends{"$kconfig"})) {
3366 my @parents = get_depends $config;
3367 foreach my $parent (@parents) {
3368 # if the parent is in the min config, check it first
3369 next if (!defined($min_configs{$parent}));
3370 $found = test_this_config($parent);
3371 if (defined($found)) {
3372 return $found;
3373 }
3374 }
3375 }
3376
3377 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003378 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003379 # .config to make sure it is missing the config that
3380 # we had before
3381 my %configs = %min_configs;
3382 delete $configs{$config};
3383 make_new_config ((values %configs), (values %keep_configs));
3384 make_oldconfig;
3385 undef %configs;
3386 assign_configs \%configs, $output_config;
3387
3388 return $config if (!defined($configs{$config}));
3389
3390 doprint "disabling config $config did not change .config\n";
3391
3392 $nochange_config{$config} = 1;
3393
3394 return undef;
3395}
3396
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003397sub make_min_config {
3398 my ($i) = @_;
3399
Steven Rostedtccc513b2012-05-21 17:13:40 -04003400 my $type = $minconfig_type;
3401 if ($type ne "boot" && $type ne "test") {
3402 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3403 " make_min_config works only with 'boot' and 'test'\n" and return;
3404 }
3405
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003406 if (!defined($output_minconfig)) {
3407 fail "OUTPUT_MIN_CONFIG not defined" and return;
3408 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003409
3410 # If output_minconfig exists, and the start_minconfig
3411 # came from min_config, than ask if we should use
3412 # that instead.
3413 if (-f $output_minconfig && !$start_minconfig_defined) {
3414 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003415 if (!defined($use_output_minconfig)) {
3416 if (read_yn " Use it as minconfig?") {
3417 $start_minconfig = $output_minconfig;
3418 }
3419 } elsif ($use_output_minconfig > 0) {
3420 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003421 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003422 } else {
3423 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003424 }
3425 }
3426
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003427 if (!defined($start_minconfig)) {
3428 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3429 }
3430
Steven Rostedt35ce5952011-07-15 21:57:25 -04003431 my $temp_config = "$tmpdir/temp_config";
3432
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003433 # First things first. We build an allnoconfig to find
3434 # out what the defaults are that we can't touch.
3435 # Some are selections, but we really can't handle selections.
3436
3437 my $save_minconfig = $minconfig;
3438 undef $minconfig;
3439
3440 run_command "$make allnoconfig" or return 0;
3441
Steven Rostedtb9066f62011-07-15 21:25:24 -04003442 read_depends;
3443
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003444 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003445
Steven Rostedt43d1b652011-07-15 22:01:56 -04003446 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003447 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003448
3449 if (defined($ignore_config)) {
3450 # make sure the file exists
3451 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003452 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003453 }
3454
Steven Rostedt43d1b652011-07-15 22:01:56 -04003455 %keep_configs = %save_configs;
3456
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003457 doprint "Load initial configs from $start_minconfig\n";
3458
3459 # Look at the current min configs, and save off all the
3460 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003461 assign_configs \%min_configs, $start_minconfig;
3462
3463 my @config_keys = keys %min_configs;
3464
Steven Rostedtac6974c2011-10-04 09:40:17 -04003465 # All configs need a depcount
3466 foreach my $config (@config_keys) {
3467 my $kconfig = chomp_config $config;
3468 if (!defined $depcount{$kconfig}) {
3469 $depcount{$kconfig} = 0;
3470 }
3471 }
3472
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003473 # Remove anything that was set by the make allnoconfig
3474 # we shouldn't need them as they get set for us anyway.
3475 foreach my $config (@config_keys) {
3476 # Remove anything in the ignore_config
3477 if (defined($keep_configs{$config})) {
3478 my $file = $ignore_config;
3479 $file =~ s,.*/(.*?)$,$1,;
3480 doprint "$config set by $file ... ignored\n";
3481 delete $min_configs{$config};
3482 next;
3483 }
3484 # But make sure the settings are the same. If a min config
3485 # sets a selection, we do not want to get rid of it if
3486 # it is not the same as what we have. Just move it into
3487 # the keep configs.
3488 if (defined($config_ignore{$config})) {
3489 if ($config_ignore{$config} ne $min_configs{$config}) {
3490 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3491 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3492 $keep_configs{$config} = $min_configs{$config};
3493 } else {
3494 doprint "$config set by allnoconfig ... ignored\n";
3495 }
3496 delete $min_configs{$config};
3497 }
3498 }
3499
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003500 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003501 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003502
3503 while (!$done) {
3504
3505 my $config;
3506 my $found;
3507
3508 # Now disable each config one by one and do a make oldconfig
3509 # till we find a config that changes our list.
3510
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003511 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003512
3513 # Sort keys by who is most dependent on
3514 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3515 @test_configs ;
3516
3517 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003518 my $reset = 1;
3519 for (my $i = 0; $i < $#test_configs; $i++) {
3520 if (!defined($nochange_config{$test_configs[0]})) {
3521 $reset = 0;
3522 last;
3523 }
3524 # This config didn't change the .config last time.
3525 # Place it at the end
3526 my $config = shift @test_configs;
3527 push @test_configs, $config;
3528 }
3529
3530 # if every test config has failed to modify the .config file
3531 # in the past, then reset and start over.
3532 if ($reset) {
3533 undef %nochange_config;
3534 }
3535
Steven Rostedtb9066f62011-07-15 21:25:24 -04003536 undef %processed_configs;
3537
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003538 foreach my $config (@test_configs) {
3539
Steven Rostedtb9066f62011-07-15 21:25:24 -04003540 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003541
Steven Rostedtb9066f62011-07-15 21:25:24 -04003542 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003543
3544 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003545 }
3546
3547 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003548 # we could have failed due to the nochange_config hash
3549 # reset and try again
3550 if (!$take_two) {
3551 undef %nochange_config;
3552 $take_two = 1;
3553 next;
3554 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003555 doprint "No more configs found that we can disable\n";
3556 $done = 1;
3557 last;
3558 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003559 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003560
3561 $config = $found;
3562
3563 doprint "Test with $config disabled\n";
3564
3565 # set in_bisect to keep build and monitor from dieing
3566 $in_bisect = 1;
3567
3568 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003569 build "oldconfig" or $failed = 1;
3570 if (!$failed) {
3571 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003572
3573 if ($type eq "test" && !$failed) {
3574 do_run_test or $failed = 1;
3575 }
3576
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003577 end_monitor;
3578 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003579
3580 $in_bisect = 0;
3581
3582 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003583 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003584 # this config is needed, add it to the ignore list.
3585 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003586 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003587 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003588
3589 # update new ignore configs
3590 if (defined($ignore_config)) {
3591 open (OUT, ">$temp_config")
3592 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003593 foreach my $config (keys %save_configs) {
3594 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003595 }
3596 close OUT;
3597 run_command "mv $temp_config $ignore_config" or
3598 dodie "failed to copy update to $ignore_config";
3599 }
3600
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003601 } else {
3602 # We booted without this config, remove it from the minconfigs.
3603 doprint "$config is not needed, disabling\n";
3604
3605 delete $min_configs{$config};
3606
3607 # Also disable anything that is not enabled in this config
3608 my %configs;
3609 assign_configs \%configs, $output_config;
3610 my @config_keys = keys %min_configs;
3611 foreach my $config (@config_keys) {
3612 if (!defined($configs{$config})) {
3613 doprint "$config is not set, disabling\n";
3614 delete $min_configs{$config};
3615 }
3616 }
3617
3618 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003619 open (OUT, ">$temp_config")
3620 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003621 foreach my $config (keys %keep_configs) {
3622 print OUT "$keep_configs{$config}\n";
3623 }
3624 foreach my $config (keys %min_configs) {
3625 print OUT "$min_configs{$config}\n";
3626 }
3627 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003628
3629 run_command "mv $temp_config $output_minconfig" or
3630 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003631 }
3632
3633 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003634 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003635 }
3636
3637 success $i;
3638 return 1;
3639}
3640
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003641$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003642
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003643if ($#ARGV == 0) {
3644 $ktest_config = $ARGV[0];
3645 if (! -f $ktest_config) {
3646 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003647 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003648 exit 0;
3649 }
3650 }
3651} else {
3652 $ktest_config = "ktest.conf";
3653}
3654
3655if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003656 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003657 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003658 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3659 print OUT << "EOF"
3660# Generated by ktest.pl
3661#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003662
3663# PWD is a ktest.pl variable that will result in the process working
3664# directory that ktest.pl is executed in.
3665
3666# THIS_DIR is automatically assigned the PWD of the path that generated
3667# the config file. It is best to use this variable when assigning other
3668# directory paths within this directory. This allows you to easily
3669# move the test cases to other locations or to other machines.
3670#
3671THIS_DIR := $variable{"PWD"}
3672
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003673# Define each test with TEST_START
3674# The config options below it will override the defaults
3675TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003676TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003677
3678DEFAULTS
3679EOF
3680;
3681 close(OUT);
3682}
3683read_config $ktest_config;
3684
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003685if (defined($opt{"LOG_FILE"})) {
3686 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3687}
3688
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003689# Append any configs entered in manually to the config file.
3690my @new_configs = keys %entered_configs;
3691if ($#new_configs >= 0) {
3692 print "\nAppending entered in configs to $ktest_config\n";
3693 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3694 foreach my $config (@new_configs) {
3695 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003696 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003697 }
3698}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003699
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003700if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3701 unlink $opt{"LOG_FILE"};
3702}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003703
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003704doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3705
Steven Rostedta57419b2010-11-02 15:13:54 -04003706for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3707
3708 if (!$i) {
3709 doprint "DEFAULT OPTIONS:\n";
3710 } else {
3711 doprint "\nTEST $i OPTIONS";
3712 if (defined($repeat_tests{$i})) {
3713 $repeat = $repeat_tests{$i};
3714 doprint " ITERATE $repeat";
3715 }
3716 doprint "\n";
3717 }
3718
3719 foreach my $option (sort keys %opt) {
3720
3721 if ($option =~ /\[(\d+)\]$/) {
3722 next if ($i != $1);
3723 } else {
3724 next if ($i);
3725 }
3726
3727 doprint "$option = $opt{$option}\n";
3728 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003729}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003730
Steven Rostedt2a625122011-05-20 15:48:59 -04003731sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003732 my ($name, $i) = @_;
3733
3734 my $option = "$name\[$i\]";
3735
3736 if (defined($opt{$option})) {
3737 return $opt{$option};
3738 }
3739
Steven Rostedta57419b2010-11-02 15:13:54 -04003740 foreach my $test (keys %repeat_tests) {
3741 if ($i >= $test &&
3742 $i < $test + $repeat_tests{$test}) {
3743 $option = "$name\[$test\]";
3744 if (defined($opt{$option})) {
3745 return $opt{$option};
3746 }
3747 }
3748 }
3749
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003750 if (defined($opt{$name})) {
3751 return $opt{$name};
3752 }
3753
3754 return undef;
3755}
3756
Steven Rostedt2a625122011-05-20 15:48:59 -04003757sub set_test_option {
3758 my ($name, $i) = @_;
3759
3760 my $option = __set_test_option($name, $i);
3761 return $option if (!defined($option));
3762
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003763 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003764}
3765
Steven Rostedt2545eb62010-11-02 15:01:32 -04003766# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003767for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003768
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003769 # Do not reboot on failing test options
3770 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003771 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003772
Steven Rostedt683a3e62012-05-18 13:34:35 -04003773 $have_version = 0;
3774
Steven Rostedt576f6272010-11-02 14:58:38 -04003775 $iteration = $i;
3776
Steven Rostedtc1434dc2012-07-20 22:39:16 -04003777 undef %force_config;
3778
Steven Rostedta75fece2010-11-02 14:58:27 -04003779 my $makecmd = set_test_option("MAKE_CMD", $i);
3780
Steven Rostedt9cc9e092011-12-22 21:37:22 -05003781 # Load all the options into their mapped variable names
3782 foreach my $opt (keys %option_map) {
3783 ${$option_map{$opt}} = set_test_option($opt, $i);
3784 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003785
Steven Rostedt35ce5952011-07-15 21:57:25 -04003786 $start_minconfig_defined = 1;
3787
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003788 # The first test may override the PRE_KTEST option
3789 if (defined($pre_ktest) && $i == 1) {
3790 doprint "\n";
3791 run_command $pre_ktest;
3792 }
3793
3794 # Any test can override the POST_KTEST option
3795 # The last test takes precedence.
3796 if (defined($post_ktest)) {
3797 $final_post_ktest = $post_ktest;
3798 }
3799
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003800 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003801 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003802 $start_minconfig = $minconfig;
3803 }
3804
Steven Rostedta75fece2010-11-02 14:58:27 -04003805 chdir $builddir || die "can't change directory to $builddir";
3806
Andrew Jonesa908a662011-08-12 15:32:03 +02003807 foreach my $dir ($tmpdir, $outputdir) {
3808 if (!-d $dir) {
3809 mkpath($dir) or
3810 die "can't create $dir";
3811 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003812 }
3813
Steven Rostedte48c5292010-11-02 14:35:37 -04003814 $ENV{"SSH_USER"} = $ssh_user;
3815 $ENV{"MACHINE"} = $machine;
3816
Steven Rostedta75fece2010-11-02 14:58:27 -04003817 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303818 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003819 $dmesg = "$tmpdir/dmesg-$machine";
3820 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003821 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003822
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003823 if (!$buildonly) {
3824 $target = "$ssh_user\@$machine";
3825 if ($reboot_type eq "grub") {
3826 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05003827 } elsif ($reboot_type eq "grub2") {
3828 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3829 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05003830 } elsif ($reboot_type eq "syslinux") {
3831 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003832 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003833 }
3834
3835 my $run_type = $build_type;
3836 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003837 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003838 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003839 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003840 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003841 $run_type = $config_bisect_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003842 }
3843
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003844 if ($test_type eq "make_min_config") {
3845 $run_type = "";
3846 }
3847
Steven Rostedta75fece2010-11-02 14:58:27 -04003848 # mistake in config file?
3849 if (!defined($run_type)) {
3850 $run_type = "ERROR";
3851 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003852
Steven Rostedte0a87422011-09-30 17:50:48 -04003853 my $installme = "";
3854 $installme = " no_install" if ($no_install);
3855
Steven Rostedt2545eb62010-11-02 15:01:32 -04003856 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003857 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003858
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003859 if (defined($pre_test)) {
3860 run_command $pre_test;
3861 }
3862
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003863 unlink $dmesg;
3864 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303865 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003866
Steven Rostedt250bae82011-07-15 22:05:59 -04003867 if (defined($addconfig)) {
3868 my $min = $minconfig;
3869 if (!defined($minconfig)) {
3870 $min = "";
3871 }
3872 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003873 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003874 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003875 }
3876
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003877 if (defined($checkout)) {
3878 run_command "git checkout $checkout" or
3879 die "failed to checkout $checkout";
3880 }
3881
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003882 $no_reboot = 0;
3883
Steven Rostedt648a1822012-03-21 11:18:27 -04003884 # A test may opt to not reboot the box
3885 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003886 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04003887 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003888
Steven Rostedta75fece2010-11-02 14:58:27 -04003889 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003890 bisect $i;
3891 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003892 } elsif ($test_type eq "config_bisect") {
3893 config_bisect $i;
3894 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003895 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003896 patchcheck $i;
3897 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003898 } elsif ($test_type eq "make_min_config") {
3899 make_min_config $i;
3900 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003901 }
3902
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003903 if ($build_type ne "nobuild") {
3904 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003905 }
3906
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003907 if ($test_type eq "install") {
3908 get_version;
3909 install;
3910 success $i;
3911 next;
3912 }
3913
Steven Rostedta75fece2010-11-02 14:58:27 -04003914 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003915 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003916 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003917
3918 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3919 do_run_test or $failed = 1;
3920 }
3921 end_monitor;
3922 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003923 }
3924
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003925 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003926}
3927
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003928if (defined($final_post_ktest)) {
3929 run_command $final_post_ktest;
3930}
3931
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003932if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003933 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003934} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003935 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04003936} elsif (defined($switch_to_good)) {
3937 # still need to get to the good kernel
3938 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003939}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003940
Steven Rostedt648a1822012-03-21 11:18:27 -04003941
Steven Rostedte48c5292010-11-02 14:35:37 -04003942doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3943
Steven Rostedt2545eb62010-11-02 15:01:32 -04003944exit 0;