xref: /openbmc/linux/tools/testing/ktest/ktest.pl (revision f7c6401ff84ab8ffffc281a29aa0a787f7eb346e)
12545eb61SSteven Rostedt#!/usr/bin/perl -w
2d6ce2a0bSSteven Rostedt#
3cce1dac8SUwe Kleine-König# Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
4d6ce2a0bSSteven Rostedt# Licensed under the terms of the GNU GPL License version 2
5d6ce2a0bSSteven Rostedt#
62545eb61SSteven Rostedt
72545eb61SSteven Rostedtuse strict;
82545eb61SSteven Rostedtuse IPC::Open2;
92545eb61SSteven Rostedtuse Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
107faafbd6SSteven Rostedtuse File::Path qw(mkpath);
117faafbd6SSteven Rostedtuse File::Copy qw(cp);
122545eb61SSteven Rostedtuse FileHandle;
132545eb61SSteven Rostedt
14e48c5293SSteven Rostedtmy $VERSION = "0.2";
15e48c5293SSteven Rostedt
162545eb61SSteven Rostedt$| = 1;
172545eb61SSteven Rostedt
182545eb61SSteven Rostedtmy %opt;
19a57419b3SSteven Rostedtmy %repeat_tests;
20a57419b3SSteven Rostedtmy %repeats;
21c75d22d9SSteven Rostedt (Red Hat)my %evals;
222545eb61SSteven Rostedt
232545eb61SSteven Rostedt#default opts
244f43e0dcSSteven Rostedtmy %default = (
254f43e0dcSSteven Rostedt    "NUM_TESTS"			=> 1,
264f43e0dcSSteven Rostedt    "TEST_TYPE"			=> "build",
274f43e0dcSSteven Rostedt    "BUILD_TYPE"		=> "randconfig",
284f43e0dcSSteven Rostedt    "MAKE_CMD"			=> "make",
295a5d8e48SSatoru Takeuchi    "CLOSE_CONSOLE_SIGNAL"	=> "INT",
304f43e0dcSSteven Rostedt    "TIMEOUT"			=> 120,
314f43e0dcSSteven Rostedt    "TMP_DIR"			=> "/tmp/ktest/\${MACHINE}",
324f43e0dcSSteven Rostedt    "SLEEP_TIME"		=> 60,	# sleep time between tests
334f43e0dcSSteven Rostedt    "BUILD_NOCLEAN"		=> 0,
344f43e0dcSSteven Rostedt    "REBOOT_ON_ERROR"		=> 0,
354f43e0dcSSteven Rostedt    "POWEROFF_ON_ERROR"		=> 0,
364f43e0dcSSteven Rostedt    "REBOOT_ON_SUCCESS"		=> 1,
374f43e0dcSSteven Rostedt    "POWEROFF_ON_SUCCESS"	=> 0,
384f43e0dcSSteven Rostedt    "BUILD_OPTIONS"		=> "",
394f43e0dcSSteven Rostedt    "BISECT_SLEEP_TIME"		=> 60,   # sleep time between bisects
404f43e0dcSSteven Rostedt    "PATCHCHECK_SLEEP_TIME"	=> 60, # sleep time between patch checks
414f43e0dcSSteven Rostedt    "CLEAR_LOG"			=> 0,
424f43e0dcSSteven Rostedt    "BISECT_MANUAL"		=> 0,
434f43e0dcSSteven Rostedt    "BISECT_SKIP"		=> 1,
44961d9cacSSteven Rostedt (Red Hat)    "BISECT_TRIES"		=> 1,
45ccc513b6SSteven Rostedt    "MIN_CONFIG_TYPE"		=> "boot",
464f43e0dcSSteven Rostedt    "SUCCESS_LINE"		=> "login:",
474f43e0dcSSteven Rostedt    "DETECT_TRIPLE_FAULT"	=> 1,
484f43e0dcSSteven Rostedt    "NO_INSTALL"		=> 0,
494f43e0dcSSteven Rostedt    "BOOTED_TIMEOUT"		=> 1,
504f43e0dcSSteven Rostedt    "DIE_ON_FAILURE"		=> 1,
514f43e0dcSSteven Rostedt    "SSH_EXEC"			=> "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
524f43e0dcSSteven Rostedt    "SCP_TO_TARGET"		=> "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
5302ad2617SSteven Rostedt    "SCP_TO_TARGET_INSTALL"	=> "\${SCP_TO_TARGET}",
544f43e0dcSSteven Rostedt    "REBOOT"			=> "ssh \$SSH_USER\@\$MACHINE reboot",
554f43e0dcSSteven Rostedt    "STOP_AFTER_SUCCESS"	=> 10,
564f43e0dcSSteven Rostedt    "STOP_AFTER_FAILURE"	=> 60,
574f43e0dcSSteven Rostedt    "STOP_TEST_AFTER"		=> 600,
58407b95b7SSteven Rostedt    "MAX_MONITOR_WAIT"		=> 1800,
59a15ba913SSteven Rostedt    "GRUB_REBOOT"		=> "grub2-reboot",
607786954cSSteven Rostedt    "SYSLINUX"			=> "extlinux",
617786954cSSteven Rostedt    "SYSLINUX_PATH"		=> "/boot/extlinux",
62600bbf0aSSteven Rostedt
63600bbf0aSSteven Rostedt# required, and we will ask users if they don't have them but we keep the default
64600bbf0aSSteven Rostedt# value something that is common.
654f43e0dcSSteven Rostedt    "REBOOT_TYPE"		=> "grub",
664f43e0dcSSteven Rostedt    "LOCALVERSION"		=> "-test",
674f43e0dcSSteven Rostedt    "SSH_USER"			=> "root",
684f43e0dcSSteven Rostedt    "BUILD_TARGET"	 	=> "arch/x86/boot/bzImage",
694f43e0dcSSteven Rostedt    "TARGET_IMAGE"		=> "/boot/vmlinuz-test",
709cc9e091SSteven Rostedt
719cc9e091SSteven Rostedt    "LOG_FILE"			=> undef,
729cc9e091SSteven Rostedt    "IGNORE_UNUSED"		=> 0,
734f43e0dcSSteven Rostedt);
742545eb61SSteven Rostedt
755269faadSSatoru Takeuchimy $ktest_config = "ktest.conf";
762545eb61SSteven Rostedtmy $version;
77683a3e64SSteven Rostedtmy $have_version = 0;
78a75fececSSteven Rostedtmy $machine;
79df5f7c66SSteven Rostedt (Red Hat)my $last_machine;
80e48c5293SSteven Rostedtmy $ssh_user;
81a75fececSSteven Rostedtmy $tmpdir;
82a75fececSSteven Rostedtmy $builddir;
83a75fececSSteven Rostedtmy $outputdir;
8451ad1dd1SSteven Rostedtmy $output_config;
85a75fececSSteven Rostedtmy $test_type;
867faafbd6SSteven Rostedtmy $build_type;
87a75fececSSteven Rostedtmy $build_options;
88921ed4c7SSteven Rostedtmy $final_post_ktest;
89921ed4c7SSteven Rostedtmy $pre_ktest;
90921ed4c7SSteven Rostedtmy $post_ktest;
91921ed4c7SSteven Rostedtmy $pre_test;
92921ed4c7SSteven Rostedtmy $post_test;
930bd6c1a3SSteven Rostedtmy $pre_build;
940bd6c1a3SSteven Rostedtmy $post_build;
950bd6c1a3SSteven Rostedtmy $pre_build_die;
960bd6c1a3SSteven Rostedtmy $post_build_die;
97a75fececSSteven Rostedtmy $reboot_type;
98a75fececSSteven Rostedtmy $reboot_script;
99a75fececSSteven Rostedtmy $power_cycle;
100e48c5293SSteven Rostedtmy $reboot;
101a75fececSSteven Rostedtmy $reboot_on_error;
102bc7c5803SSteven Rostedtmy $switch_to_good;
103bc7c5803SSteven Rostedtmy $switch_to_test;
104a75fececSSteven Rostedtmy $poweroff_on_error;
105648a182cSSteven Rostedtmy $reboot_on_success;
106a75fececSSteven Rostedtmy $die_on_failure;
107576f627cSSteven Rostedtmy $powercycle_after_reboot;
108576f627cSSteven Rostedtmy $poweroff_after_halt;
109407b95b7SSteven Rostedtmy $max_monitor_wait;
110e48c5293SSteven Rostedtmy $ssh_exec;
111e48c5293SSteven Rostedtmy $scp_to_target;
11202ad2617SSteven Rostedtmy $scp_to_target_install;
113a75fececSSteven Rostedtmy $power_off;
114a75fececSSteven Rostedtmy $grub_menu;
115752d9665SSteven Rostedt (Red Hat)my $last_grub_menu;
116a15ba913SSteven Rostedtmy $grub_file;
1172545eb61SSteven Rostedtmy $grub_number;
118a15ba913SSteven Rostedtmy $grub_reboot;
1197786954cSSteven Rostedtmy $syslinux;
1207786954cSSteven Rostedtmy $syslinux_path;
1217786954cSSteven Rostedtmy $syslinux_label;
1222545eb61SSteven Rostedtmy $target;
1232545eb61SSteven Rostedtmy $make;
124e5c2ec11SSteven Rostedtmy $pre_install;
1258b37ca8cSSteven Rostedtmy $post_install;
126e0a8742eSSteven Rostedtmy $no_install;
1275c42fc5bSSteven Rostedtmy $noclean;
1285f9b6cedSSteven Rostedtmy $minconfig;
1294c4ab120SSteven Rostedtmy $start_minconfig;
13035ce5952SSteven Rostedtmy $start_minconfig_defined;
1314c4ab120SSteven Rostedtmy $output_minconfig;
132ccc513b6SSteven Rostedtmy $minconfig_type;
13343de3316SSteven Rostedtmy $use_output_minconfig;
1344283b169SSteven Rostedt (Red Hat)my $warnings_file;
1354c4ab120SSteven Rostedtmy $ignore_config;
136be405f95SSteven Rostedtmy $ignore_errors;
1372b7d9b21SSteven Rostedtmy $addconfig;
1385f9b6cedSSteven Rostedtmy $in_bisect = 0;
139b5f4aea6SSteven Rostedtmy $bisect_bad_commit = "";
140d6ce2a0bSSteven Rostedtmy $reverse_bisect;
141c960bb9fSSteven Rostedtmy $bisect_manual;
142c23dca7cSSteven Rostedtmy $bisect_skip;
143961d9cacSSteven Rostedt (Red Hat)my $bisect_tries;
14430f75da5SSteven Rostedtmy $config_bisect_good;
145c5dacb88SSteven Rostedtmy $bisect_ret_good;
146c5dacb88SSteven Rostedtmy $bisect_ret_bad;
147c5dacb88SSteven Rostedtmy $bisect_ret_skip;
148c5dacb88SSteven Rostedtmy $bisect_ret_abort;
149c5dacb88SSteven Rostedtmy $bisect_ret_default;
1506c5ee0beSSteven Rostedtmy $in_patchcheck = 0;
1515a391fbfSSteven Rostedtmy $run_test;
1527faafbd6SSteven Rostedtmy $buildlog;
153a9dd5d63SRabin Vincentmy $testlog;
1547faafbd6SSteven Rostedtmy $dmesg;
1557faafbd6SSteven Rostedtmy $monitor_fp;
1567faafbd6SSteven Rostedtmy $monitor_pid;
1577faafbd6SSteven Rostedtmy $monitor_cnt = 0;
158a75fececSSteven Rostedtmy $sleep_time;
159a75fececSSteven Rostedtmy $bisect_sleep_time;
16027d934b2SSteven Rostedtmy $patchcheck_sleep_time;
1611990207dSSteven Rostedtmy $ignore_warnings;
162a75fececSSteven Rostedtmy $store_failures;
163de5b6e3bSRabin Vincentmy $store_successes;
1649064af52SSteven Rostedtmy $test_name;
165a75fececSSteven Rostedtmy $timeout;
166a75fececSSteven Rostedtmy $booted_timeout;
167f1a5b962SSteven Rostedtmy $detect_triplefault;
168a75fececSSteven Rostedtmy $console;
1695a5d8e48SSatoru Takeuchimy $close_console_signal;
1702b803365SSteven Rostedtmy $reboot_success_line;
171a75fececSSteven Rostedtmy $success_line;
1721c8a617aSSteven Rostedtmy $stop_after_success;
1731c8a617aSSteven Rostedtmy $stop_after_failure;
1742d01b26aSSteven Rostedtmy $stop_test_after;
175a75fececSSteven Rostedtmy $build_target;
176a75fececSSteven Rostedtmy $target_image;
177b5f4aea6SSteven Rostedtmy $checkout;
178a75fececSSteven Rostedtmy $localversion;
179576f627cSSteven Rostedtmy $iteration = 0;
180e48c5293SSteven Rostedtmy $successes = 0;
1819d2f7f05SJosh Poimboeufmy $stty_orig;
1825739438bSSteven Rostedt (VMware)my $run_command_status = 0;
1832545eb61SSteven Rostedt
184b5f4aea6SSteven Rostedtmy $bisect_good;
185b5f4aea6SSteven Rostedtmy $bisect_bad;
186b5f4aea6SSteven Rostedtmy $bisect_type;
187b5f4aea6SSteven Rostedtmy $bisect_start;
188b5f4aea6SSteven Rostedtmy $bisect_replay;
189b5f4aea6SSteven Rostedtmy $bisect_files;
190b5f4aea6SSteven Rostedtmy $bisect_reverse;
191b5f4aea6SSteven Rostedtmy $bisect_check;
192b5f4aea6SSteven Rostedt
193b5f4aea6SSteven Rostedtmy $config_bisect;
194b5f4aea6SSteven Rostedtmy $config_bisect_type;
195b0918612SSteven Rostedtmy $config_bisect_check;
196b5f4aea6SSteven Rostedt
197b5f4aea6SSteven Rostedtmy $patchcheck_type;
198b5f4aea6SSteven Rostedtmy $patchcheck_start;
19923a0e161SSteven Rostedt (Red Hat)my $patchcheck_cherry;
200b5f4aea6SSteven Rostedtmy $patchcheck_end;
201b5f4aea6SSteven Rostedt
20238fa3dc1SSteven Rostedt (Red Hat)my $build_time;
20338fa3dc1SSteven Rostedt (Red Hat)my $install_time;
20438fa3dc1SSteven Rostedt (Red Hat)my $reboot_time;
20538fa3dc1SSteven Rostedt (Red Hat)my $test_time;
20638fa3dc1SSteven Rostedt (Red Hat)
207165708b2SSteven Rostedt# set when a test is something other that just building or install
208bb8474b1SSteven Rostedt# which would require more options.
209bb8474b1SSteven Rostedtmy $buildonly = 1;
210bb8474b1SSteven Rostedt
2114283b169SSteven Rostedt (Red Hat)# tell build not to worry about warnings, even when WARNINGS_FILE is set
2124283b169SSteven Rostedt (Red Hat)my $warnings_ok = 0;
2134283b169SSteven Rostedt (Red Hat)
214dbd3783bSSteven Rostedt# set when creating a new config
215dbd3783bSSteven Rostedtmy $newconfig = 0;
216dbd3783bSSteven Rostedt
2178d1491baSSteven Rostedtmy %entered_configs;
2188d1491baSSteven Rostedtmy %config_help;
21977d942ceSSteven Rostedtmy %variable;
220cf79fab6SSteven Rostedt
221cf79fab6SSteven Rostedt# force_config is the list of configs that we force enabled (or disabled)
222cf79fab6SSteven Rostedt# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
223fcb3f16aSSteven Rostedtmy %force_config;
2248d1491baSSteven Rostedt
2254ab1cce5SSteven Rostedt# do not force reboots on config problems
2264ab1cce5SSteven Rostedtmy $no_reboot = 1;
2274ab1cce5SSteven Rostedt
228759a3cc6SSteven Rostedt# reboot on success
229759a3cc6SSteven Rostedtmy $reboot_success = 0;
230759a3cc6SSteven Rostedt
2319cc9e091SSteven Rostedtmy %option_map = (
2329cc9e091SSteven Rostedt    "MACHINE"			=> \$machine,
2339cc9e091SSteven Rostedt    "SSH_USER"			=> \$ssh_user,
2349cc9e091SSteven Rostedt    "TMP_DIR"			=> \$tmpdir,
2359cc9e091SSteven Rostedt    "OUTPUT_DIR"		=> \$outputdir,
2369cc9e091SSteven Rostedt    "BUILD_DIR"			=> \$builddir,
2379cc9e091SSteven Rostedt    "TEST_TYPE"			=> \$test_type,
238921ed4c7SSteven Rostedt    "PRE_KTEST"			=> \$pre_ktest,
239921ed4c7SSteven Rostedt    "POST_KTEST"		=> \$post_ktest,
240921ed4c7SSteven Rostedt    "PRE_TEST"			=> \$pre_test,
241921ed4c7SSteven Rostedt    "POST_TEST"			=> \$post_test,
2429cc9e091SSteven Rostedt    "BUILD_TYPE"		=> \$build_type,
2439cc9e091SSteven Rostedt    "BUILD_OPTIONS"		=> \$build_options,
2449cc9e091SSteven Rostedt    "PRE_BUILD"			=> \$pre_build,
2459cc9e091SSteven Rostedt    "POST_BUILD"		=> \$post_build,
2469cc9e091SSteven Rostedt    "PRE_BUILD_DIE"		=> \$pre_build_die,
2479cc9e091SSteven Rostedt    "POST_BUILD_DIE"		=> \$post_build_die,
2489cc9e091SSteven Rostedt    "POWER_CYCLE"		=> \$power_cycle,
2499cc9e091SSteven Rostedt    "REBOOT"			=> \$reboot,
2509cc9e091SSteven Rostedt    "BUILD_NOCLEAN"		=> \$noclean,
2519cc9e091SSteven Rostedt    "MIN_CONFIG"		=> \$minconfig,
2529cc9e091SSteven Rostedt    "OUTPUT_MIN_CONFIG"		=> \$output_minconfig,
2539cc9e091SSteven Rostedt    "START_MIN_CONFIG"		=> \$start_minconfig,
254ccc513b6SSteven Rostedt    "MIN_CONFIG_TYPE"		=> \$minconfig_type,
25543de3316SSteven Rostedt    "USE_OUTPUT_MIN_CONFIG"	=> \$use_output_minconfig,
2564283b169SSteven Rostedt (Red Hat)    "WARNINGS_FILE"		=> \$warnings_file,
2579cc9e091SSteven Rostedt    "IGNORE_CONFIG"		=> \$ignore_config,
2589cc9e091SSteven Rostedt    "TEST"			=> \$run_test,
2599cc9e091SSteven Rostedt    "ADD_CONFIG"		=> \$addconfig,
2609cc9e091SSteven Rostedt    "REBOOT_TYPE"		=> \$reboot_type,
2619cc9e091SSteven Rostedt    "GRUB_MENU"			=> \$grub_menu,
262a15ba913SSteven Rostedt    "GRUB_FILE"			=> \$grub_file,
263a15ba913SSteven Rostedt    "GRUB_REBOOT"		=> \$grub_reboot,
2647786954cSSteven Rostedt    "SYSLINUX"			=> \$syslinux,
2657786954cSSteven Rostedt    "SYSLINUX_PATH"		=> \$syslinux_path,
2667786954cSSteven Rostedt    "SYSLINUX_LABEL"		=> \$syslinux_label,
267e5c2ec11SSteven Rostedt    "PRE_INSTALL"		=> \$pre_install,
2689cc9e091SSteven Rostedt    "POST_INSTALL"		=> \$post_install,
2699cc9e091SSteven Rostedt    "NO_INSTALL"		=> \$no_install,
2709cc9e091SSteven Rostedt    "REBOOT_SCRIPT"		=> \$reboot_script,
2719cc9e091SSteven Rostedt    "REBOOT_ON_ERROR"		=> \$reboot_on_error,
2729cc9e091SSteven Rostedt    "SWITCH_TO_GOOD"		=> \$switch_to_good,
2739cc9e091SSteven Rostedt    "SWITCH_TO_TEST"		=> \$switch_to_test,
2749cc9e091SSteven Rostedt    "POWEROFF_ON_ERROR"		=> \$poweroff_on_error,
275648a182cSSteven Rostedt    "REBOOT_ON_SUCCESS"		=> \$reboot_on_success,
2769cc9e091SSteven Rostedt    "DIE_ON_FAILURE"		=> \$die_on_failure,
2779cc9e091SSteven Rostedt    "POWER_OFF"			=> \$power_off,
2789cc9e091SSteven Rostedt    "POWERCYCLE_AFTER_REBOOT"	=> \$powercycle_after_reboot,
2799cc9e091SSteven Rostedt    "POWEROFF_AFTER_HALT"	=> \$poweroff_after_halt,
280407b95b7SSteven Rostedt    "MAX_MONITOR_WAIT"		=> \$max_monitor_wait,
2819cc9e091SSteven Rostedt    "SLEEP_TIME"		=> \$sleep_time,
2829cc9e091SSteven Rostedt    "BISECT_SLEEP_TIME"		=> \$bisect_sleep_time,
2839cc9e091SSteven Rostedt    "PATCHCHECK_SLEEP_TIME"	=> \$patchcheck_sleep_time,
2849cc9e091SSteven Rostedt    "IGNORE_WARNINGS"		=> \$ignore_warnings,
285be405f95SSteven Rostedt    "IGNORE_ERRORS"		=> \$ignore_errors,
2869cc9e091SSteven Rostedt    "BISECT_MANUAL"		=> \$bisect_manual,
2879cc9e091SSteven Rostedt    "BISECT_SKIP"		=> \$bisect_skip,
288961d9cacSSteven Rostedt (Red Hat)    "BISECT_TRIES"		=> \$bisect_tries,
2899cc9e091SSteven Rostedt    "CONFIG_BISECT_GOOD"	=> \$config_bisect_good,
2909cc9e091SSteven Rostedt    "BISECT_RET_GOOD"		=> \$bisect_ret_good,
2919cc9e091SSteven Rostedt    "BISECT_RET_BAD"		=> \$bisect_ret_bad,
2929cc9e091SSteven Rostedt    "BISECT_RET_SKIP"		=> \$bisect_ret_skip,
2939cc9e091SSteven Rostedt    "BISECT_RET_ABORT"		=> \$bisect_ret_abort,
2949cc9e091SSteven Rostedt    "BISECT_RET_DEFAULT"	=> \$bisect_ret_default,
2959cc9e091SSteven Rostedt    "STORE_FAILURES"		=> \$store_failures,
2969cc9e091SSteven Rostedt    "STORE_SUCCESSES"		=> \$store_successes,
2979cc9e091SSteven Rostedt    "TEST_NAME"			=> \$test_name,
2989cc9e091SSteven Rostedt    "TIMEOUT"			=> \$timeout,
2999cc9e091SSteven Rostedt    "BOOTED_TIMEOUT"		=> \$booted_timeout,
3009cc9e091SSteven Rostedt    "CONSOLE"			=> \$console,
3015a5d8e48SSatoru Takeuchi    "CLOSE_CONSOLE_SIGNAL"	=> \$close_console_signal,
3029cc9e091SSteven Rostedt    "DETECT_TRIPLE_FAULT"	=> \$detect_triplefault,
3039cc9e091SSteven Rostedt    "SUCCESS_LINE"		=> \$success_line,
3049cc9e091SSteven Rostedt    "REBOOT_SUCCESS_LINE"	=> \$reboot_success_line,
3059cc9e091SSteven Rostedt    "STOP_AFTER_SUCCESS"	=> \$stop_after_success,
3069cc9e091SSteven Rostedt    "STOP_AFTER_FAILURE"	=> \$stop_after_failure,
3079cc9e091SSteven Rostedt    "STOP_TEST_AFTER"		=> \$stop_test_after,
3089cc9e091SSteven Rostedt    "BUILD_TARGET"		=> \$build_target,
3099cc9e091SSteven Rostedt    "SSH_EXEC"			=> \$ssh_exec,
3109cc9e091SSteven Rostedt    "SCP_TO_TARGET"		=> \$scp_to_target,
31102ad2617SSteven Rostedt    "SCP_TO_TARGET_INSTALL"	=> \$scp_to_target_install,
3129cc9e091SSteven Rostedt    "CHECKOUT"			=> \$checkout,
3139cc9e091SSteven Rostedt    "TARGET_IMAGE"		=> \$target_image,
3149cc9e091SSteven Rostedt    "LOCALVERSION"		=> \$localversion,
3159cc9e091SSteven Rostedt
3169cc9e091SSteven Rostedt    "BISECT_GOOD"		=> \$bisect_good,
3179cc9e091SSteven Rostedt    "BISECT_BAD"		=> \$bisect_bad,
3189cc9e091SSteven Rostedt    "BISECT_TYPE"		=> \$bisect_type,
3199cc9e091SSteven Rostedt    "BISECT_START"		=> \$bisect_start,
3209cc9e091SSteven Rostedt    "BISECT_REPLAY"		=> \$bisect_replay,
3219cc9e091SSteven Rostedt    "BISECT_FILES"		=> \$bisect_files,
3229cc9e091SSteven Rostedt    "BISECT_REVERSE"		=> \$bisect_reverse,
3239cc9e091SSteven Rostedt    "BISECT_CHECK"		=> \$bisect_check,
3249cc9e091SSteven Rostedt
3259cc9e091SSteven Rostedt    "CONFIG_BISECT"		=> \$config_bisect,
3269cc9e091SSteven Rostedt    "CONFIG_BISECT_TYPE"	=> \$config_bisect_type,
327b0918612SSteven Rostedt    "CONFIG_BISECT_CHECK"	=> \$config_bisect_check,
3289cc9e091SSteven Rostedt
3299cc9e091SSteven Rostedt    "PATCHCHECK_TYPE"		=> \$patchcheck_type,
3309cc9e091SSteven Rostedt    "PATCHCHECK_START"		=> \$patchcheck_start,
33123a0e161SSteven Rostedt (Red Hat)    "PATCHCHECK_CHERRY"		=> \$patchcheck_cherry,
3329cc9e091SSteven Rostedt    "PATCHCHECK_END"		=> \$patchcheck_end,
3339cc9e091SSteven Rostedt);
3349cc9e091SSteven Rostedt
3359cc9e091SSteven Rostedt# Options may be used by other options, record them.
3369cc9e091SSteven Rostedtmy %used_options;
3379cc9e091SSteven Rostedt
3387bf51073SSteven Rostedt# default variables that can be used
3397bf51073SSteven Rostedtchomp ($variable{"PWD"} = `pwd`);
3407bf51073SSteven Rostedt
3418d1491baSSteven Rostedt$config_help{"MACHINE"} = << "EOF"
3428d1491baSSteven Rostedt The machine hostname that you will test.
343bb8474b1SSteven Rostedt For build only tests, it is still needed to differentiate log files.
3448d1491baSSteven RostedtEOF
3458d1491baSSteven Rostedt    ;
3468d1491baSSteven Rostedt$config_help{"SSH_USER"} = << "EOF"
3478d1491baSSteven Rostedt The box is expected to have ssh on normal bootup, provide the user
3488d1491baSSteven Rostedt  (most likely root, since you need privileged operations)
3498d1491baSSteven RostedtEOF
3508d1491baSSteven Rostedt    ;
3518d1491baSSteven Rostedt$config_help{"BUILD_DIR"} = << "EOF"
3528d1491baSSteven Rostedt The directory that contains the Linux source code (full path).
3530e7a22deSSteven Rostedt You can use \${PWD} that will be the path where ktest.pl is run, or use
3540e7a22deSSteven Rostedt \${THIS_DIR} which is assigned \${PWD} but may be changed later.
3558d1491baSSteven RostedtEOF
3568d1491baSSteven Rostedt    ;
3578d1491baSSteven Rostedt$config_help{"OUTPUT_DIR"} = << "EOF"
3588d1491baSSteven Rostedt The directory that the objects will be built (full path).
3598d1491baSSteven Rostedt (can not be same as BUILD_DIR)
3600e7a22deSSteven Rostedt You can use \${PWD} that will be the path where ktest.pl is run, or use
3610e7a22deSSteven Rostedt \${THIS_DIR} which is assigned \${PWD} but may be changed later.
3628d1491baSSteven RostedtEOF
3638d1491baSSteven Rostedt    ;
3648d1491baSSteven Rostedt$config_help{"BUILD_TARGET"} = << "EOF"
3658d1491baSSteven Rostedt The location of the compiled file to copy to the target.
3668d1491baSSteven Rostedt (relative to OUTPUT_DIR)
3678d1491baSSteven RostedtEOF
3688d1491baSSteven Rostedt    ;
369dbd3783bSSteven Rostedt$config_help{"BUILD_OPTIONS"} = << "EOF"
370dbd3783bSSteven Rostedt Options to add to \"make\" when building.
371dbd3783bSSteven Rostedt i.e.  -j20
372dbd3783bSSteven RostedtEOF
373dbd3783bSSteven Rostedt    ;
3748d1491baSSteven Rostedt$config_help{"TARGET_IMAGE"} = << "EOF"
3758d1491baSSteven Rostedt The place to put your image on the test machine.
3768d1491baSSteven RostedtEOF
3778d1491baSSteven Rostedt    ;
3788d1491baSSteven Rostedt$config_help{"POWER_CYCLE"} = << "EOF"
3798d1491baSSteven Rostedt A script or command to reboot the box.
3808d1491baSSteven Rostedt
3818d1491baSSteven Rostedt Here is a digital loggers power switch example
3828d1491baSSteven Rostedt POWER_CYCLE = wget --no-proxy -O /dev/null -q  --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
3838d1491baSSteven Rostedt
3848d1491baSSteven Rostedt Here is an example to reboot a virtual box on the current host
3858d1491baSSteven Rostedt with the name "Guest".
3868d1491baSSteven Rostedt POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
3878d1491baSSteven RostedtEOF
3888d1491baSSteven Rostedt    ;
3898d1491baSSteven Rostedt$config_help{"CONSOLE"} = << "EOF"
3908d1491baSSteven Rostedt The script or command that reads the console
3918d1491baSSteven Rostedt
3928d1491baSSteven Rostedt  If you use ttywatch server, something like the following would work.
3938d1491baSSteven RostedtCONSOLE = nc -d localhost 3001
3948d1491baSSteven Rostedt
3958d1491baSSteven Rostedt For a virtual machine with guest name "Guest".
3968d1491baSSteven RostedtCONSOLE =  virsh console Guest
3978d1491baSSteven RostedtEOF
3988d1491baSSteven Rostedt    ;
3998d1491baSSteven Rostedt$config_help{"LOCALVERSION"} = << "EOF"
4008d1491baSSteven Rostedt Required version ending to differentiate the test
4018d1491baSSteven Rostedt from other linux builds on the system.
4028d1491baSSteven RostedtEOF
4038d1491baSSteven Rostedt    ;
4048d1491baSSteven Rostedt$config_help{"REBOOT_TYPE"} = << "EOF"
4058d1491baSSteven Rostedt Way to reboot the box to the test kernel.
4067786954cSSteven Rostedt Only valid options so far are "grub", "grub2", "syslinux", and "script".
4078d1491baSSteven Rostedt
4088d1491baSSteven Rostedt If you specify grub, it will assume grub version 1
4098d1491baSSteven Rostedt and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
4108d1491baSSteven Rostedt and select that target to reboot to the kernel. If this is not
4118d1491baSSteven Rostedt your setup, then specify "script" and have a command or script
4128d1491baSSteven Rostedt specified in REBOOT_SCRIPT to boot to the target.
4138d1491baSSteven Rostedt
4148d1491baSSteven Rostedt The entry in /boot/grub/menu.lst must be entered in manually.
4158d1491baSSteven Rostedt The test will not modify that file.
416a15ba913SSteven Rostedt
417a15ba913SSteven Rostedt If you specify grub2, then you also need to specify both \$GRUB_MENU
418a15ba913SSteven Rostedt and \$GRUB_FILE.
4197786954cSSteven Rostedt
4207786954cSSteven Rostedt If you specify syslinux, then you may use SYSLINUX to define the syslinux
4217786954cSSteven Rostedt command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
4227786954cSSteven Rostedt the syslinux install (defaults to /boot/extlinux). But you have to specify
4237786954cSSteven Rostedt SYSLINUX_LABEL to define the label to boot to for the test kernel.
4248d1491baSSteven RostedtEOF
4258d1491baSSteven Rostedt    ;
4268d1491baSSteven Rostedt$config_help{"GRUB_MENU"} = << "EOF"
4278d1491baSSteven Rostedt The grub title name for the test kernel to boot
428a15ba913SSteven Rostedt (Only mandatory if REBOOT_TYPE = grub or grub2)
4298d1491baSSteven Rostedt
4308d1491baSSteven Rostedt Note, ktest.pl will not update the grub menu.lst, you need to
4318d1491baSSteven Rostedt manually add an option for the test. ktest.pl will search
4328d1491baSSteven Rostedt the grub menu.lst for this option to find what kernel to
4338d1491baSSteven Rostedt reboot into.
4348d1491baSSteven Rostedt
4358d1491baSSteven Rostedt For example, if in the /boot/grub/menu.lst the test kernel title has:
4368d1491baSSteven Rostedt title Test Kernel
4378d1491baSSteven Rostedt kernel vmlinuz-test
4388d1491baSSteven Rostedt GRUB_MENU = Test Kernel
439a15ba913SSteven Rostedt
440a15ba913SSteven Rostedt For grub2, a search of \$GRUB_FILE is performed for the lines
441a15ba913SSteven Rostedt that begin with "menuentry". It will not detect submenus. The
442a15ba913SSteven Rostedt menu must be a non-nested menu. Add the quotes used in the menu
443a15ba913SSteven Rostedt to guarantee your selection, as the first menuentry with the content
444a15ba913SSteven Rostedt of \$GRUB_MENU that is found will be used.
445a15ba913SSteven RostedtEOF
446a15ba913SSteven Rostedt    ;
447a15ba913SSteven Rostedt$config_help{"GRUB_FILE"} = << "EOF"
448a15ba913SSteven Rostedt If grub2 is used, the full path for the grub.cfg file is placed
449a15ba913SSteven Rostedt here. Use something like /boot/grub2/grub.cfg to search.
4508d1491baSSteven RostedtEOF
4518d1491baSSteven Rostedt    ;
4527786954cSSteven Rostedt$config_help{"SYSLINUX_LABEL"} = << "EOF"
4537786954cSSteven Rostedt If syslinux is used, the label that boots the target kernel must
4547786954cSSteven Rostedt be specified with SYSLINUX_LABEL.
4557786954cSSteven RostedtEOF
4567786954cSSteven Rostedt    ;
4578d1491baSSteven Rostedt$config_help{"REBOOT_SCRIPT"} = << "EOF"
4588d1491baSSteven Rostedt A script to reboot the target into the test kernel
4598d1491baSSteven Rostedt (Only mandatory if REBOOT_TYPE = script)
4608d1491baSSteven RostedtEOF
4618d1491baSSteven Rostedt    ;
4628d1491baSSteven Rostedt
463c75d22d9SSteven Rostedt (Red Hat)sub _logit {
464c75d22d9SSteven Rostedt (Red Hat)    if (defined($opt{"LOG_FILE"})) {
465c75d22d9SSteven Rostedt (Red Hat)	open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
466c75d22d9SSteven Rostedt (Red Hat)	print OUT @_;
467c75d22d9SSteven Rostedt (Red Hat)	close(OUT);
468c75d22d9SSteven Rostedt (Red Hat)    }
469c75d22d9SSteven Rostedt (Red Hat)}
470c75d22d9SSteven Rostedt (Red Hat)
471c75d22d9SSteven Rostedt (Red Hat)sub logit {
472c75d22d9SSteven Rostedt (Red Hat)    if (defined($opt{"LOG_FILE"})) {
473c75d22d9SSteven Rostedt (Red Hat)	_logit @_;
474c75d22d9SSteven Rostedt (Red Hat)    } else {
475c75d22d9SSteven Rostedt (Red Hat)	print @_;
476c75d22d9SSteven Rostedt (Red Hat)    }
477c75d22d9SSteven Rostedt (Red Hat)}
478c75d22d9SSteven Rostedt (Red Hat)
479c75d22d9SSteven Rostedt (Red Hat)sub doprint {
480c75d22d9SSteven Rostedt (Red Hat)    print @_;
481c75d22d9SSteven Rostedt (Red Hat)    _logit @_;
482c75d22d9SSteven Rostedt (Red Hat)}
483c75d22d9SSteven Rostedt (Red Hat)
484dad98754SSteven Rostedtsub read_prompt {
485dad98754SSteven Rostedt    my ($cancel, $prompt) = @_;
48635ce5952SSteven Rostedt
48735ce5952SSteven Rostedt    my $ans;
48835ce5952SSteven Rostedt
48935ce5952SSteven Rostedt    for (;;) {
490dad98754SSteven Rostedt	if ($cancel) {
491dad98754SSteven Rostedt	    print "$prompt [y/n/C] ";
492dad98754SSteven Rostedt	} else {
49335ce5952SSteven Rostedt	    print "$prompt [Y/n] ";
494dad98754SSteven Rostedt	}
49535ce5952SSteven Rostedt	$ans = <STDIN>;
49635ce5952SSteven Rostedt	chomp $ans;
49735ce5952SSteven Rostedt	if ($ans =~ /^\s*$/) {
498dad98754SSteven Rostedt	    if ($cancel) {
499dad98754SSteven Rostedt		$ans = "c";
500dad98754SSteven Rostedt	    } else {
50135ce5952SSteven Rostedt		$ans = "y";
50235ce5952SSteven Rostedt	    }
503dad98754SSteven Rostedt	}
50435ce5952SSteven Rostedt	last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
505dad98754SSteven Rostedt	if ($cancel) {
506dad98754SSteven Rostedt	    last if ($ans =~ /^c$/i);
507dad98754SSteven Rostedt	    print "Please answer either 'y', 'n' or 'c'.\n";
508dad98754SSteven Rostedt	} else {
50935ce5952SSteven Rostedt	    print "Please answer either 'y' or 'n'.\n";
51035ce5952SSteven Rostedt	}
511dad98754SSteven Rostedt    }
512dad98754SSteven Rostedt    if ($ans =~ /^c/i) {
513dad98754SSteven Rostedt	exit;
514dad98754SSteven Rostedt    }
51535ce5952SSteven Rostedt    if ($ans !~ /^y$/i) {
51635ce5952SSteven Rostedt	return 0;
51735ce5952SSteven Rostedt    }
51835ce5952SSteven Rostedt    return 1;
51935ce5952SSteven Rostedt}
5208d1491baSSteven Rostedt
521dad98754SSteven Rostedtsub read_yn {
522dad98754SSteven Rostedt    my ($prompt) = @_;
523dad98754SSteven Rostedt
524dad98754SSteven Rostedt    return read_prompt 0, $prompt;
525dad98754SSteven Rostedt}
526dad98754SSteven Rostedt
527dad98754SSteven Rostedtsub read_ync {
528dad98754SSteven Rostedt    my ($prompt) = @_;
529dad98754SSteven Rostedt
530dad98754SSteven Rostedt    return read_prompt 1, $prompt;
531dad98754SSteven Rostedt}
532dad98754SSteven Rostedt
5335269faadSSatoru Takeuchisub get_mandatory_config {
5348d1491baSSteven Rostedt    my ($config) = @_;
535815e2bd7SSteven Rostedt    my $ans;
5368d1491baSSteven Rostedt
5378d1491baSSteven Rostedt    return if (defined($opt{$config}));
5388d1491baSSteven Rostedt
5398d1491baSSteven Rostedt    if (defined($config_help{$config})) {
5408d1491baSSteven Rostedt	print "\n";
5418d1491baSSteven Rostedt	print $config_help{$config};
5428d1491baSSteven Rostedt    }
5438d1491baSSteven Rostedt
5448d1491baSSteven Rostedt    for (;;) {
5458d1491baSSteven Rostedt	print "$config = ";
546dbd3783bSSteven Rostedt	if (defined($default{$config}) && length($default{$config})) {
5478d1491baSSteven Rostedt	    print "\[$default{$config}\] ";
5488d1491baSSteven Rostedt	}
549815e2bd7SSteven Rostedt	$ans = <STDIN>;
550815e2bd7SSteven Rostedt	$ans =~ s/^\s*(.*\S)\s*$/$1/;
551815e2bd7SSteven Rostedt	if ($ans =~ /^\s*$/) {
5528d1491baSSteven Rostedt	    if ($default{$config}) {
553815e2bd7SSteven Rostedt		$ans = $default{$config};
5548d1491baSSteven Rostedt	    } else {
5558d1491baSSteven Rostedt		print "Your answer can not be blank\n";
5568d1491baSSteven Rostedt		next;
5578d1491baSSteven Rostedt	    }
5588d1491baSSteven Rostedt	}
5590e7a22deSSteven Rostedt	$entered_configs{$config} = ${ans};
5608d1491baSSteven Rostedt	last;
5618d1491baSSteven Rostedt    }
5628d1491baSSteven Rostedt}
5638d1491baSSteven Rostedt
56438fa3dc1SSteven Rostedt (Red Hat)sub show_time {
56538fa3dc1SSteven Rostedt (Red Hat)    my ($time) = @_;
56638fa3dc1SSteven Rostedt (Red Hat)
56738fa3dc1SSteven Rostedt (Red Hat)    my $hours = 0;
56838fa3dc1SSteven Rostedt (Red Hat)    my $minutes = 0;
56938fa3dc1SSteven Rostedt (Red Hat)
57038fa3dc1SSteven Rostedt (Red Hat)    if ($time > 3600) {
57138fa3dc1SSteven Rostedt (Red Hat)	$hours = int($time / 3600);
57238fa3dc1SSteven Rostedt (Red Hat)	$time -= $hours * 3600;
57338fa3dc1SSteven Rostedt (Red Hat)    }
57438fa3dc1SSteven Rostedt (Red Hat)    if ($time > 60) {
57538fa3dc1SSteven Rostedt (Red Hat)	$minutes = int($time / 60);
57638fa3dc1SSteven Rostedt (Red Hat)	$time -= $minutes * 60;
57738fa3dc1SSteven Rostedt (Red Hat)    }
57838fa3dc1SSteven Rostedt (Red Hat)
57938fa3dc1SSteven Rostedt (Red Hat)    if ($hours > 0) {
58038fa3dc1SSteven Rostedt (Red Hat)	doprint "$hours hour";
58138fa3dc1SSteven Rostedt (Red Hat)	doprint "s" if ($hours > 1);
58238fa3dc1SSteven Rostedt (Red Hat)	doprint " ";
58338fa3dc1SSteven Rostedt (Red Hat)    }
58438fa3dc1SSteven Rostedt (Red Hat)
58538fa3dc1SSteven Rostedt (Red Hat)    if ($minutes > 0) {
58638fa3dc1SSteven Rostedt (Red Hat)	doprint "$minutes minute";
58738fa3dc1SSteven Rostedt (Red Hat)	doprint "s" if ($minutes > 1);
58838fa3dc1SSteven Rostedt (Red Hat)	doprint " ";
58938fa3dc1SSteven Rostedt (Red Hat)    }
59038fa3dc1SSteven Rostedt (Red Hat)
59138fa3dc1SSteven Rostedt (Red Hat)    doprint "$time second";
59238fa3dc1SSteven Rostedt (Red Hat)    doprint "s" if ($time != 1);
59338fa3dc1SSteven Rostedt (Red Hat)}
59438fa3dc1SSteven Rostedt (Red Hat)
59538fa3dc1SSteven Rostedt (Red Hat)sub print_times {
59638fa3dc1SSteven Rostedt (Red Hat)    doprint "\n";
59738fa3dc1SSteven Rostedt (Red Hat)    if ($build_time) {
59838fa3dc1SSteven Rostedt (Red Hat)	doprint "Build time:   ";
59938fa3dc1SSteven Rostedt (Red Hat)	show_time($build_time);
60038fa3dc1SSteven Rostedt (Red Hat)	doprint "\n";
60138fa3dc1SSteven Rostedt (Red Hat)    }
60238fa3dc1SSteven Rostedt (Red Hat)    if ($install_time) {
60338fa3dc1SSteven Rostedt (Red Hat)	doprint "Install time: ";
60438fa3dc1SSteven Rostedt (Red Hat)	show_time($install_time);
60538fa3dc1SSteven Rostedt (Red Hat)	doprint "\n";
60638fa3dc1SSteven Rostedt (Red Hat)    }
60738fa3dc1SSteven Rostedt (Red Hat)    if ($reboot_time) {
60838fa3dc1SSteven Rostedt (Red Hat)	doprint "Reboot time:  ";
60938fa3dc1SSteven Rostedt (Red Hat)	show_time($reboot_time);
61038fa3dc1SSteven Rostedt (Red Hat)	doprint "\n";
61138fa3dc1SSteven Rostedt (Red Hat)    }
61238fa3dc1SSteven Rostedt (Red Hat)    if ($test_time) {
61338fa3dc1SSteven Rostedt (Red Hat)	doprint "Test time:    ";
61438fa3dc1SSteven Rostedt (Red Hat)	show_time($test_time);
61538fa3dc1SSteven Rostedt (Red Hat)	doprint "\n";
61638fa3dc1SSteven Rostedt (Red Hat)    }
61738fa3dc1SSteven Rostedt (Red Hat)    # reset for iterations like bisect
61838fa3dc1SSteven Rostedt (Red Hat)    $build_time = 0;
61938fa3dc1SSteven Rostedt (Red Hat)    $install_time = 0;
62038fa3dc1SSteven Rostedt (Red Hat)    $reboot_time = 0;
62138fa3dc1SSteven Rostedt (Red Hat)    $test_time = 0;
62238fa3dc1SSteven Rostedt (Red Hat)}
62338fa3dc1SSteven Rostedt (Red Hat)
6245269faadSSatoru Takeuchisub get_mandatory_configs {
6255269faadSSatoru Takeuchi    get_mandatory_config("MACHINE");
6265269faadSSatoru Takeuchi    get_mandatory_config("BUILD_DIR");
6275269faadSSatoru Takeuchi    get_mandatory_config("OUTPUT_DIR");
628bb8474b1SSteven Rostedt
629dbd3783bSSteven Rostedt    if ($newconfig) {
6305269faadSSatoru Takeuchi	get_mandatory_config("BUILD_OPTIONS");
631dbd3783bSSteven Rostedt    }
632dbd3783bSSteven Rostedt
633bb8474b1SSteven Rostedt    # options required for other than just building a kernel
634bb8474b1SSteven Rostedt    if (!$buildonly) {
6355269faadSSatoru Takeuchi	get_mandatory_config("POWER_CYCLE");
6365269faadSSatoru Takeuchi	get_mandatory_config("CONSOLE");
637165708b2SSteven Rostedt    }
638165708b2SSteven Rostedt
639165708b2SSteven Rostedt    # options required for install and more
640165708b2SSteven Rostedt    if ($buildonly != 1) {
6415269faadSSatoru Takeuchi	get_mandatory_config("SSH_USER");
6425269faadSSatoru Takeuchi	get_mandatory_config("BUILD_TARGET");
6435269faadSSatoru Takeuchi	get_mandatory_config("TARGET_IMAGE");
644bb8474b1SSteven Rostedt    }
645bb8474b1SSteven Rostedt
6465269faadSSatoru Takeuchi    get_mandatory_config("LOCALVERSION");
6478d1491baSSteven Rostedt
648bb8474b1SSteven Rostedt    return if ($buildonly);
649bb8474b1SSteven Rostedt
6508d1491baSSteven Rostedt    my $rtype = $opt{"REBOOT_TYPE"};
6518d1491baSSteven Rostedt
6528d1491baSSteven Rostedt    if (!defined($rtype)) {
6538d1491baSSteven Rostedt	if (!defined($opt{"GRUB_MENU"})) {
6545269faadSSatoru Takeuchi	    get_mandatory_config("REBOOT_TYPE");
6558d1491baSSteven Rostedt	    $rtype = $entered_configs{"REBOOT_TYPE"};
6568d1491baSSteven Rostedt	} else {
6578d1491baSSteven Rostedt	    $rtype = "grub";
6588d1491baSSteven Rostedt	}
6598d1491baSSteven Rostedt    }
6608d1491baSSteven Rostedt
6618d1491baSSteven Rostedt    if ($rtype eq "grub") {
6625269faadSSatoru Takeuchi	get_mandatory_config("GRUB_MENU");
6638d1491baSSteven Rostedt    }
664a15ba913SSteven Rostedt
665a15ba913SSteven Rostedt    if ($rtype eq "grub2") {
6665269faadSSatoru Takeuchi	get_mandatory_config("GRUB_MENU");
6675269faadSSatoru Takeuchi	get_mandatory_config("GRUB_FILE");
668a15ba913SSteven Rostedt    }
6697786954cSSteven Rostedt
6707786954cSSteven Rostedt    if ($rtype eq "syslinux") {
6715269faadSSatoru Takeuchi	get_mandatory_config("SYSLINUX_LABEL");
6727786954cSSteven Rostedt    }
6738d1491baSSteven Rostedt}
6748d1491baSSteven Rostedt
67577d942ceSSteven Rostedtsub process_variables {
6768d735212SSteven Rostedt    my ($value, $remove_undef) = @_;
67777d942ceSSteven Rostedt    my $retval = "";
67877d942ceSSteven Rostedt
67977d942ceSSteven Rostedt    # We want to check for '\', and it is just easier
68077d942ceSSteven Rostedt    # to check the previous characet of '$' and not need
68177d942ceSSteven Rostedt    # to worry if '$' is the first character. By adding
68277d942ceSSteven Rostedt    # a space to $value, we can just check [^\\]\$ and
68377d942ceSSteven Rostedt    # it will still work.
68477d942ceSSteven Rostedt    $value = " $value";
68577d942ceSSteven Rostedt
68677d942ceSSteven Rostedt    while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
68777d942ceSSteven Rostedt	my $begin = $1;
68877d942ceSSteven Rostedt	my $var = $2;
68977d942ceSSteven Rostedt	my $end = $3;
69077d942ceSSteven Rostedt	# append beginning of value to retval
69177d942ceSSteven Rostedt	$retval = "$retval$begin";
69277d942ceSSteven Rostedt	if (defined($variable{$var})) {
69377d942ceSSteven Rostedt	    $retval = "$retval$variable{$var}";
6948d735212SSteven Rostedt	} elsif (defined($remove_undef) && $remove_undef) {
6958d735212SSteven Rostedt	    # for if statements, any variable that is not defined,
6968d735212SSteven Rostedt	    # we simple convert to 0
6978d735212SSteven Rostedt	    $retval = "${retval}0";
69877d942ceSSteven Rostedt	} else {
69977d942ceSSteven Rostedt	    # put back the origin piece.
70077d942ceSSteven Rostedt	    $retval = "$retval\$\{$var\}";
7019cc9e091SSteven Rostedt	    # This could be an option that is used later, save
7029cc9e091SSteven Rostedt	    # it so we don't warn if this option is not one of
7039cc9e091SSteven Rostedt	    # ktests options.
7049cc9e091SSteven Rostedt	    $used_options{$var} = 1;
70577d942ceSSteven Rostedt	}
70677d942ceSSteven Rostedt	$value = $end;
70777d942ceSSteven Rostedt    }
70877d942ceSSteven Rostedt    $retval = "$retval$value";
70977d942ceSSteven Rostedt
71077d942ceSSteven Rostedt    # remove the space added in the beginning
71177d942ceSSteven Rostedt    $retval =~ s/ //;
71277d942ceSSteven Rostedt
71377d942ceSSteven Rostedt    return "$retval"
71477d942ceSSteven Rostedt}
71577d942ceSSteven Rostedt
716a57419b3SSteven Rostedtsub set_value {
7173d1cc414SSteven Rostedt    my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
7182545eb61SSteven Rostedt
719cad96669SSteven Rostedt    my $prvalue = process_variables($rvalue);
720cad96669SSteven Rostedt
721cad96669SSteven Rostedt    if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
722bb8474b1SSteven Rostedt	# Note if a test is something other than build, then we
723bb8474b1SSteven Rostedt	# will need other manditory options.
724cad96669SSteven Rostedt	if ($prvalue ne "install") {
725319ab14fSSteven Rostedt (Red Hat)	    # for bisect, we need to check BISECT_TYPE
726319ab14fSSteven Rostedt (Red Hat)	    if ($prvalue ne "bisect") {
727319ab14fSSteven Rostedt (Red Hat)		$buildonly = 0;
728319ab14fSSteven Rostedt (Red Hat)	    }
729319ab14fSSteven Rostedt (Red Hat)	} else {
730319ab14fSSteven Rostedt (Red Hat)	    # install still limits some manditory options.
731319ab14fSSteven Rostedt (Red Hat)	    $buildonly = 2;
732319ab14fSSteven Rostedt (Red Hat)	}
733319ab14fSSteven Rostedt (Red Hat)    }
734319ab14fSSteven Rostedt (Red Hat)
735319ab14fSSteven Rostedt (Red Hat)    if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
736319ab14fSSteven Rostedt (Red Hat)	if ($prvalue ne "install") {
737bb8474b1SSteven Rostedt	    $buildonly = 0;
738165708b2SSteven Rostedt	} else {
739165708b2SSteven Rostedt	    # install still limits some manditory options.
740165708b2SSteven Rostedt	    $buildonly = 2;
741165708b2SSteven Rostedt	}
742bb8474b1SSteven Rostedt    }
743bb8474b1SSteven Rostedt
744a75fececSSteven Rostedt    if (defined($opt{$lvalue})) {
7453d1cc414SSteven Rostedt	if (!$override || defined(${$overrides}{$lvalue})) {
7463d1cc414SSteven Rostedt	    my $extra = "";
7473d1cc414SSteven Rostedt	    if ($override) {
7483d1cc414SSteven Rostedt		$extra = "In the same override section!\n";
7493d1cc414SSteven Rostedt	    }
7503d1cc414SSteven Rostedt	    die "$name: $.: Option $lvalue defined more than once!\n$extra";
7513d1cc414SSteven Rostedt	}
752cad96669SSteven Rostedt	${$overrides}{$lvalue} = $prvalue;
753a75fececSSteven Rostedt    }
75422c37a9aSSteven Rostedt (Red Hat)
755cad96669SSteven Rostedt    $opt{$lvalue} = $prvalue;
75621a9679fSSteven Rostedt}
757a57419b3SSteven Rostedt
758c75d22d9SSteven Rostedt (Red Hat)sub set_eval {
759c75d22d9SSteven Rostedt (Red Hat)    my ($lvalue, $rvalue, $name) = @_;
760c75d22d9SSteven Rostedt (Red Hat)
761c75d22d9SSteven Rostedt (Red Hat)    my $prvalue = process_variables($rvalue);
762c75d22d9SSteven Rostedt (Red Hat)    my $arr;
763c75d22d9SSteven Rostedt (Red Hat)
764c75d22d9SSteven Rostedt (Red Hat)    if (defined($evals{$lvalue})) {
765c75d22d9SSteven Rostedt (Red Hat)	$arr = $evals{$lvalue};
766c75d22d9SSteven Rostedt (Red Hat)    } else {
767c75d22d9SSteven Rostedt (Red Hat)	$arr = [];
768c75d22d9SSteven Rostedt (Red Hat)	$evals{$lvalue} = $arr;
769c75d22d9SSteven Rostedt (Red Hat)    }
770c75d22d9SSteven Rostedt (Red Hat)
771c75d22d9SSteven Rostedt (Red Hat)    push @{$arr}, $rvalue;
772c75d22d9SSteven Rostedt (Red Hat)}
773c75d22d9SSteven Rostedt (Red Hat)
77477d942ceSSteven Rostedtsub set_variable {
77577d942ceSSteven Rostedt    my ($lvalue, $rvalue) = @_;
77677d942ceSSteven Rostedt
77777d942ceSSteven Rostedt    if ($rvalue =~ /^\s*$/) {
77877d942ceSSteven Rostedt	delete $variable{$lvalue};
77977d942ceSSteven Rostedt    } else {
78077d942ceSSteven Rostedt	$rvalue = process_variables($rvalue);
78177d942ceSSteven Rostedt	$variable{$lvalue} = $rvalue;
78277d942ceSSteven Rostedt    }
78377d942ceSSteven Rostedt}
78477d942ceSSteven Rostedt
785ab7a3f52SSteven Rostedtsub process_compare {
786ab7a3f52SSteven Rostedt    my ($lval, $cmp, $rval) = @_;
787ab7a3f52SSteven Rostedt
788ab7a3f52SSteven Rostedt    # remove whitespace
789ab7a3f52SSteven Rostedt
790ab7a3f52SSteven Rostedt    $lval =~ s/^\s*//;
791ab7a3f52SSteven Rostedt    $lval =~ s/\s*$//;
792ab7a3f52SSteven Rostedt
793ab7a3f52SSteven Rostedt    $rval =~ s/^\s*//;
794ab7a3f52SSteven Rostedt    $rval =~ s/\s*$//;
795ab7a3f52SSteven Rostedt
796ab7a3f52SSteven Rostedt    if ($cmp eq "==") {
797ab7a3f52SSteven Rostedt	return $lval eq $rval;
798ab7a3f52SSteven Rostedt    } elsif ($cmp eq "!=") {
799ab7a3f52SSteven Rostedt	return $lval ne $rval;
8008fddbe9bSSteven Rostedt    } elsif ($cmp eq "=~") {
8018fddbe9bSSteven Rostedt	return $lval =~ m/$rval/;
8028fddbe9bSSteven Rostedt    } elsif ($cmp eq "!~") {
8038fddbe9bSSteven Rostedt	return $lval !~ m/$rval/;
804ab7a3f52SSteven Rostedt    }
805ab7a3f52SSteven Rostedt
806ab7a3f52SSteven Rostedt    my $statement = "$lval $cmp $rval";
807ab7a3f52SSteven Rostedt    my $ret = eval $statement;
808ab7a3f52SSteven Rostedt
809ab7a3f52SSteven Rostedt    # $@ stores error of eval
810ab7a3f52SSteven Rostedt    if ($@) {
811ab7a3f52SSteven Rostedt	return -1;
812ab7a3f52SSteven Rostedt    }
813ab7a3f52SSteven Rostedt
814ab7a3f52SSteven Rostedt    return $ret;
815ab7a3f52SSteven Rostedt}
816ab7a3f52SSteven Rostedt
8179900b5dcSSteven Rostedtsub value_defined {
8189900b5dcSSteven Rostedt    my ($val) = @_;
8199900b5dcSSteven Rostedt
8209900b5dcSSteven Rostedt    return defined($variable{$2}) ||
8219900b5dcSSteven Rostedt	defined($opt{$2});
8229900b5dcSSteven Rostedt}
8239900b5dcSSteven Rostedt
8248d735212SSteven Rostedtmy $d = 0;
8258d735212SSteven Rostedtsub process_expression {
8268d735212SSteven Rostedt    my ($name, $val) = @_;
82745d73a5dSSteven Rostedt
8288d735212SSteven Rostedt    my $c = $d++;
8298d735212SSteven Rostedt
8308d735212SSteven Rostedt    while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
8318d735212SSteven Rostedt	my $express = $1;
8328d735212SSteven Rostedt
8338d735212SSteven Rostedt	if (process_expression($name, $express)) {
8348d735212SSteven Rostedt	    $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
8358d735212SSteven Rostedt	} else {
8368d735212SSteven Rostedt	    $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
8378d735212SSteven Rostedt	}
8388d735212SSteven Rostedt    }
8398d735212SSteven Rostedt
8408d735212SSteven Rostedt    $d--;
8418d735212SSteven Rostedt    my $OR = "\\|\\|";
8428d735212SSteven Rostedt    my $AND = "\\&\\&";
8438d735212SSteven Rostedt
8448d735212SSteven Rostedt    while ($val =~ s/^(.*?)($OR|$AND)//) {
8458d735212SSteven Rostedt	my $express = $1;
8468d735212SSteven Rostedt	my $op = $2;
8478d735212SSteven Rostedt
8488d735212SSteven Rostedt	if (process_expression($name, $express)) {
8498d735212SSteven Rostedt	    if ($op eq "||") {
8508d735212SSteven Rostedt		return 1;
8518d735212SSteven Rostedt	    }
8528d735212SSteven Rostedt	} else {
8538d735212SSteven Rostedt	    if ($op eq "&&") {
8548d735212SSteven Rostedt		return 0;
8558d735212SSteven Rostedt	    }
8568d735212SSteven Rostedt	}
8578d735212SSteven Rostedt    }
85845d73a5dSSteven Rostedt
8598fddbe9bSSteven Rostedt    if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
860ab7a3f52SSteven Rostedt	my $ret = process_compare($1, $2, $3);
861ab7a3f52SSteven Rostedt	if ($ret < 0) {
862ab7a3f52SSteven Rostedt	    die "$name: $.: Unable to process comparison\n";
863ab7a3f52SSteven Rostedt	}
864ab7a3f52SSteven Rostedt	return $ret;
865ab7a3f52SSteven Rostedt    }
866ab7a3f52SSteven Rostedt
8679900b5dcSSteven Rostedt    if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
8689900b5dcSSteven Rostedt	if (defined $1) {
8699900b5dcSSteven Rostedt	    return !value_defined($2);
8709900b5dcSSteven Rostedt	} else {
8719900b5dcSSteven Rostedt	    return value_defined($2);
8729900b5dcSSteven Rostedt	}
8739900b5dcSSteven Rostedt    }
8749900b5dcSSteven Rostedt
87545d73a5dSSteven Rostedt    if ($val =~ /^\s*0\s*$/) {
87645d73a5dSSteven Rostedt	return 0;
87745d73a5dSSteven Rostedt    } elsif ($val =~ /^\s*\d+\s*$/) {
87845d73a5dSSteven Rostedt	return 1;
87945d73a5dSSteven Rostedt    }
88045d73a5dSSteven Rostedt
8819900b5dcSSteven Rostedt    die ("$name: $.: Undefined content $val in if statement\n");
8828d735212SSteven Rostedt}
8838d735212SSteven Rostedt
8848d735212SSteven Rostedtsub process_if {
8858d735212SSteven Rostedt    my ($name, $value) = @_;
8868d735212SSteven Rostedt
8878d735212SSteven Rostedt    # Convert variables and replace undefined ones with 0
8888d735212SSteven Rostedt    my $val = process_variables($value, 1);
8898d735212SSteven Rostedt    my $ret = process_expression $name, $val;
8908d735212SSteven Rostedt
8918d735212SSteven Rostedt    return $ret;
89245d73a5dSSteven Rostedt}
89345d73a5dSSteven Rostedt
8942ed3b161SSteven Rostedtsub __read_config {
8952ed3b161SSteven Rostedt    my ($config, $current_test_num) = @_;
896a57419b3SSteven Rostedt
8972ed3b161SSteven Rostedt    my $in;
8982ed3b161SSteven Rostedt    open($in, $config) || die "can't read file $config";
899a57419b3SSteven Rostedt
900a57419b3SSteven Rostedt    my $name = $config;
901a57419b3SSteven Rostedt    $name =~ s,.*/(.*),$1,;
902a57419b3SSteven Rostedt
9032ed3b161SSteven Rostedt    my $test_num = $$current_test_num;
904a57419b3SSteven Rostedt    my $default = 1;
905a57419b3SSteven Rostedt    my $repeat = 1;
906a57419b3SSteven Rostedt    my $num_tests_set = 0;
907a57419b3SSteven Rostedt    my $skip = 0;
908a57419b3SSteven Rostedt    my $rest;
909a9f84424SSteven Rostedt    my $line;
9100df213caSSteven Rostedt    my $test_case = 0;
91145d73a5dSSteven Rostedt    my $if = 0;
91245d73a5dSSteven Rostedt    my $if_set = 0;
9133d1cc414SSteven Rostedt    my $override = 0;
9143d1cc414SSteven Rostedt
9153d1cc414SSteven Rostedt    my %overrides;
916a57419b3SSteven Rostedt
9172ed3b161SSteven Rostedt    while (<$in>) {
918a57419b3SSteven Rostedt
919a57419b3SSteven Rostedt	# ignore blank lines and comments
920a57419b3SSteven Rostedt	next if (/^\s*$/ || /\s*\#/);
921a57419b3SSteven Rostedt
9220050b6bbSSteven Rostedt	if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
923a57419b3SSteven Rostedt
9240050b6bbSSteven Rostedt	    my $type = $1;
9250050b6bbSSteven Rostedt	    $rest = $2;
926a9f84424SSteven Rostedt	    $line = $2;
9270050b6bbSSteven Rostedt
9280050b6bbSSteven Rostedt	    my $old_test_num;
9290050b6bbSSteven Rostedt	    my $old_repeat;
9303d1cc414SSteven Rostedt	    $override = 0;
9310050b6bbSSteven Rostedt
9320050b6bbSSteven Rostedt	    if ($type eq "TEST_START") {
933a57419b3SSteven Rostedt
934a57419b3SSteven Rostedt		if ($num_tests_set) {
935a57419b3SSteven Rostedt		    die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
936a57419b3SSteven Rostedt		}
937a57419b3SSteven Rostedt
9380050b6bbSSteven Rostedt		$old_test_num = $test_num;
9390050b6bbSSteven Rostedt		$old_repeat = $repeat;
940a57419b3SSteven Rostedt
941a57419b3SSteven Rostedt		$test_num += $repeat;
942a57419b3SSteven Rostedt		$default = 0;
943a57419b3SSteven Rostedt		$repeat = 1;
9440050b6bbSSteven Rostedt	    } else {
9450050b6bbSSteven Rostedt		$default = 1;
9460050b6bbSSteven Rostedt	    }
947a57419b3SSteven Rostedt
948a9f84424SSteven Rostedt	    # If SKIP is anywhere in the line, the command will be skipped
949a9f84424SSteven Rostedt	    if ($rest =~ s/\s+SKIP\b//) {
950a57419b3SSteven Rostedt		$skip = 1;
951a57419b3SSteven Rostedt	    } else {
9520df213caSSteven Rostedt		$test_case = 1;
953a57419b3SSteven Rostedt		$skip = 0;
954a57419b3SSteven Rostedt	    }
955a57419b3SSteven Rostedt
956a9f84424SSteven Rostedt	    if ($rest =~ s/\sELSE\b//) {
957a9f84424SSteven Rostedt		if (!$if) {
958a9f84424SSteven Rostedt		    die "$name: $.: ELSE found with out matching IF section\n$_";
959a57419b3SSteven Rostedt		}
960a9f84424SSteven Rostedt		$if = 0;
961a9f84424SSteven Rostedt
962a9f84424SSteven Rostedt		if ($if_set) {
963a9f84424SSteven Rostedt		    $skip = 1;
964a9f84424SSteven Rostedt		} else {
965a9f84424SSteven Rostedt		    $skip = 0;
9663d1cc414SSteven Rostedt		}
9673d1cc414SSteven Rostedt	    }
968a57419b3SSteven Rostedt
969a9f84424SSteven Rostedt	    if ($rest =~ s/\sIF\s+(.*)//) {
97045d73a5dSSteven Rostedt		if (process_if($name, $1)) {
97145d73a5dSSteven Rostedt		    $if_set = 1;
97245d73a5dSSteven Rostedt		} else {
973a57419b3SSteven Rostedt		    $skip = 1;
974a57419b3SSteven Rostedt		}
97545d73a5dSSteven Rostedt		$if = 1;
97645d73a5dSSteven Rostedt	    } else {
97745d73a5dSSteven Rostedt		$if = 0;
978a9f84424SSteven Rostedt		$if_set = 0;
97945d73a5dSSteven Rostedt	    }
980a57419b3SSteven Rostedt
981a9f84424SSteven Rostedt	    if (!$skip) {
982a9f84424SSteven Rostedt		if ($type eq "TEST_START") {
983a9f84424SSteven Rostedt		    if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
984a9f84424SSteven Rostedt			$repeat = $1;
985a9f84424SSteven Rostedt			$repeat_tests{"$test_num"} = $repeat;
986a9f84424SSteven Rostedt		    }
987a9f84424SSteven Rostedt		} elsif ($rest =~ s/\sOVERRIDE\b//) {
988a9f84424SSteven Rostedt		    # DEFAULT only
989a9f84424SSteven Rostedt		    $override = 1;
990a9f84424SSteven Rostedt		    # Clear previous overrides
991a9f84424SSteven Rostedt		    %overrides = ();
992a9f84424SSteven Rostedt		}
993a9f84424SSteven Rostedt	    }
994a9f84424SSteven Rostedt
995a9f84424SSteven Rostedt	    if (!$skip && $rest !~ /^\s*$/) {
9960050b6bbSSteven Rostedt		die "$name: $.: Gargbage found after $type\n$_";
997a57419b3SSteven Rostedt	    }
998a57419b3SSteven Rostedt
9990050b6bbSSteven Rostedt	    if ($skip && $type eq "TEST_START") {
1000a57419b3SSteven Rostedt		$test_num = $old_test_num;
1001e48c5293SSteven Rostedt		$repeat = $old_repeat;
1002a57419b3SSteven Rostedt	    }
1003a57419b3SSteven Rostedt
1004ab7a3f52SSteven Rostedt	} elsif (/^\s*ELSE\b(.*)$/) {
100545d73a5dSSteven Rostedt	    if (!$if) {
100645d73a5dSSteven Rostedt		die "$name: $.: ELSE found with out matching IF section\n$_";
100745d73a5dSSteven Rostedt	    }
100845d73a5dSSteven Rostedt	    $rest = $1;
100945d73a5dSSteven Rostedt	    if ($if_set) {
101045d73a5dSSteven Rostedt		$skip = 1;
1011ab7a3f52SSteven Rostedt		$rest = "";
101245d73a5dSSteven Rostedt	    } else {
101345d73a5dSSteven Rostedt		$skip = 0;
101445d73a5dSSteven Rostedt
1015ab7a3f52SSteven Rostedt		if ($rest =~ /\sIF\s+(.*)/) {
101645d73a5dSSteven Rostedt		    # May be a ELSE IF section.
101795f57838SSteven Rostedt		    if (process_if($name, $1)) {
101895f57838SSteven Rostedt			$if_set = 1;
101995f57838SSteven Rostedt		    } else {
102045d73a5dSSteven Rostedt			$skip = 1;
102145d73a5dSSteven Rostedt		    }
1022ab7a3f52SSteven Rostedt		    $rest = "";
102345d73a5dSSteven Rostedt		} else {
102445d73a5dSSteven Rostedt		    $if = 0;
102545d73a5dSSteven Rostedt		}
102645d73a5dSSteven Rostedt	    }
102745d73a5dSSteven Rostedt
1028ab7a3f52SSteven Rostedt	    if ($rest !~ /^\s*$/) {
1029ab7a3f52SSteven Rostedt		die "$name: $.: Gargbage found after DEFAULTS\n$_";
1030ab7a3f52SSteven Rostedt	    }
1031ab7a3f52SSteven Rostedt
10322ed3b161SSteven Rostedt	} elsif (/^\s*INCLUDE\s+(\S+)/) {
10332ed3b161SSteven Rostedt
10342ed3b161SSteven Rostedt	    next if ($skip);
10352ed3b161SSteven Rostedt
10362ed3b161SSteven Rostedt	    if (!$default) {
10372ed3b161SSteven Rostedt		die "$name: $.: INCLUDE can only be done in default sections\n$_";
10382ed3b161SSteven Rostedt	    }
10392ed3b161SSteven Rostedt
10402ed3b161SSteven Rostedt	    my $file = process_variables($1);
10412ed3b161SSteven Rostedt
10422ed3b161SSteven Rostedt	    if ($file !~ m,^/,) {
10432ed3b161SSteven Rostedt		# check the path of the config file first
10442ed3b161SSteven Rostedt		if ($config =~ m,(.*)/,) {
10452ed3b161SSteven Rostedt		    if (-f "$1/$file") {
10462ed3b161SSteven Rostedt			$file = "$1/$file";
10472ed3b161SSteven Rostedt		    }
10482ed3b161SSteven Rostedt		}
10492ed3b161SSteven Rostedt	    }
10502ed3b161SSteven Rostedt
10512ed3b161SSteven Rostedt	    if ( ! -r $file ) {
10522ed3b161SSteven Rostedt		die "$name: $.: Can't read file $file\n$_";
10532ed3b161SSteven Rostedt	    }
10542ed3b161SSteven Rostedt
10552ed3b161SSteven Rostedt	    if (__read_config($file, \$test_num)) {
10562ed3b161SSteven Rostedt		$test_case = 1;
10572ed3b161SSteven Rostedt	    }
10582ed3b161SSteven Rostedt
1059c75d22d9SSteven Rostedt (Red Hat)	} elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
1060c75d22d9SSteven Rostedt (Red Hat)
1061c75d22d9SSteven Rostedt (Red Hat)	    next if ($skip);
1062c75d22d9SSteven Rostedt (Red Hat)
1063c75d22d9SSteven Rostedt (Red Hat)	    my $lvalue = $1;
1064c75d22d9SSteven Rostedt (Red Hat)	    my $rvalue = $2;
1065c75d22d9SSteven Rostedt (Red Hat)
1066c75d22d9SSteven Rostedt (Red Hat)	    if ($default || $lvalue =~ /\[\d+\]$/) {
1067c75d22d9SSteven Rostedt (Red Hat)		set_eval($lvalue, $rvalue, $name);
1068c75d22d9SSteven Rostedt (Red Hat)	    } else {
1069c75d22d9SSteven Rostedt (Red Hat)		my $val = "$lvalue\[$test_num\]";
1070c75d22d9SSteven Rostedt (Red Hat)		set_eval($val, $rvalue, $name);
1071c75d22d9SSteven Rostedt (Red Hat)	    }
1072c75d22d9SSteven Rostedt (Red Hat)
1073a57419b3SSteven Rostedt	} elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1074a57419b3SSteven Rostedt
1075a57419b3SSteven Rostedt	    next if ($skip);
1076a57419b3SSteven Rostedt
1077a57419b3SSteven Rostedt	    my $lvalue = $1;
1078a57419b3SSteven Rostedt	    my $rvalue = $2;
1079a57419b3SSteven Rostedt
1080a57419b3SSteven Rostedt	    if (!$default &&
1081a57419b3SSteven Rostedt		($lvalue eq "NUM_TESTS" ||
1082a57419b3SSteven Rostedt		 $lvalue eq "LOG_FILE" ||
1083a57419b3SSteven Rostedt		 $lvalue eq "CLEAR_LOG")) {
1084a57419b3SSteven Rostedt		die "$name: $.: $lvalue must be set in DEFAULTS section\n";
1085a57419b3SSteven Rostedt	    }
1086a57419b3SSteven Rostedt
1087a57419b3SSteven Rostedt	    if ($lvalue eq "NUM_TESTS") {
1088a57419b3SSteven Rostedt		if ($test_num) {
1089a57419b3SSteven Rostedt		    die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
1090a57419b3SSteven Rostedt		}
1091a57419b3SSteven Rostedt		if (!$default) {
1092a57419b3SSteven Rostedt		    die "$name: $.: NUM_TESTS must be set in default section\n";
1093a57419b3SSteven Rostedt		}
1094a57419b3SSteven Rostedt		$num_tests_set = 1;
1095a57419b3SSteven Rostedt	    }
1096a57419b3SSteven Rostedt
1097a57419b3SSteven Rostedt	    if ($default || $lvalue =~ /\[\d+\]$/) {
10983d1cc414SSteven Rostedt		set_value($lvalue, $rvalue, $override, \%overrides, $name);
1099a57419b3SSteven Rostedt	    } else {
1100a57419b3SSteven Rostedt		my $val = "$lvalue\[$test_num\]";
11013d1cc414SSteven Rostedt		set_value($val, $rvalue, $override, \%overrides, $name);
1102a57419b3SSteven Rostedt
1103a57419b3SSteven Rostedt		if ($repeat > 1) {
1104a57419b3SSteven Rostedt		    $repeats{$val} = $repeat;
1105a57419b3SSteven Rostedt		}
1106a57419b3SSteven Rostedt	    }
110777d942ceSSteven Rostedt	} elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
110877d942ceSSteven Rostedt	    next if ($skip);
110977d942ceSSteven Rostedt
111077d942ceSSteven Rostedt	    my $lvalue = $1;
111177d942ceSSteven Rostedt	    my $rvalue = $2;
111277d942ceSSteven Rostedt
111377d942ceSSteven Rostedt	    # process config variables.
111477d942ceSSteven Rostedt	    # Config variables are only active while reading the
111577d942ceSSteven Rostedt	    # config and can be defined anywhere. They also ignore
111677d942ceSSteven Rostedt	    # TEST_START and DEFAULTS, but are skipped if they are in
111777d942ceSSteven Rostedt	    # on of these sections that have SKIP defined.
111877d942ceSSteven Rostedt	    # The save variable can be
111977d942ceSSteven Rostedt	    # defined multiple times and the new one simply overrides
112077d942ceSSteven Rostedt	    # the prevous one.
112177d942ceSSteven Rostedt	    set_variable($lvalue, $rvalue);
112277d942ceSSteven Rostedt
1123a57419b3SSteven Rostedt	} else {
1124a57419b3SSteven Rostedt	    die "$name: $.: Garbage found in config\n$_";
1125a57419b3SSteven Rostedt	}
11262545eb61SSteven Rostedt    }
11272545eb61SSteven Rostedt
1128a57419b3SSteven Rostedt    if ($test_num) {
1129a57419b3SSteven Rostedt	$test_num += $repeat - 1;
1130a57419b3SSteven Rostedt	$opt{"NUM_TESTS"} = $test_num;
1131a57419b3SSteven Rostedt    }
1132a57419b3SSteven Rostedt
11332ed3b161SSteven Rostedt    close($in);
11342ed3b161SSteven Rostedt
11352ed3b161SSteven Rostedt    $$current_test_num = $test_num;
11362ed3b161SSteven Rostedt
11372ed3b161SSteven Rostedt    return $test_case;
11382ed3b161SSteven Rostedt}
11392ed3b161SSteven Rostedt
1140c4261d0fSSteven Rostedtsub get_test_case {
1141c4261d0fSSteven Rostedt	print "What test case would you like to run?\n";
1142c4261d0fSSteven Rostedt	print " (build, install or boot)\n";
1143c4261d0fSSteven Rostedt	print " Other tests are available but require editing the config file\n";
1144c4261d0fSSteven Rostedt	my $ans = <STDIN>;
1145c4261d0fSSteven Rostedt	chomp $ans;
1146c4261d0fSSteven Rostedt	$default{"TEST_TYPE"} = $ans;
1147c4261d0fSSteven Rostedt}
1148c4261d0fSSteven Rostedt
11492ed3b161SSteven Rostedtsub read_config {
11502ed3b161SSteven Rostedt    my ($config) = @_;
11512ed3b161SSteven Rostedt
11522ed3b161SSteven Rostedt    my $test_case;
11532ed3b161SSteven Rostedt    my $test_num = 0;
11542ed3b161SSteven Rostedt
11552ed3b161SSteven Rostedt    $test_case = __read_config $config, \$test_num;
11562ed3b161SSteven Rostedt
11578d1491baSSteven Rostedt    # make sure we have all mandatory configs
11585269faadSSatoru Takeuchi    get_mandatory_configs;
11598d1491baSSteven Rostedt
11600df213caSSteven Rostedt    # was a test specified?
11610df213caSSteven Rostedt    if (!$test_case) {
11620df213caSSteven Rostedt	print "No test case specified.\n";
1163c4261d0fSSteven Rostedt	get_test_case;
11640df213caSSteven Rostedt    }
11650df213caSSteven Rostedt
1166a75fececSSteven Rostedt    # set any defaults
1167a75fececSSteven Rostedt
1168a75fececSSteven Rostedt    foreach my $default (keys %default) {
1169a75fececSSteven Rostedt	if (!defined($opt{$default})) {
1170a75fececSSteven Rostedt	    $opt{$default} = $default{$default};
1171a75fececSSteven Rostedt	}
1172a75fececSSteven Rostedt    }
11739cc9e091SSteven Rostedt
11749cc9e091SSteven Rostedt    if ($opt{"IGNORE_UNUSED"} == 1) {
11759cc9e091SSteven Rostedt	return;
11769cc9e091SSteven Rostedt    }
11779cc9e091SSteven Rostedt
11789cc9e091SSteven Rostedt    my %not_used;
11799cc9e091SSteven Rostedt
11809cc9e091SSteven Rostedt    # check if there are any stragglers (typos?)
11819cc9e091SSteven Rostedt    foreach my $option (keys %opt) {
11829cc9e091SSteven Rostedt	my $op = $option;
11839cc9e091SSteven Rostedt	# remove per test labels.
11849cc9e091SSteven Rostedt	$op =~ s/\[.*\]//;
11859cc9e091SSteven Rostedt	if (!exists($option_map{$op}) &&
11869cc9e091SSteven Rostedt	    !exists($default{$op}) &&
11879cc9e091SSteven Rostedt	    !exists($used_options{$op})) {
11889cc9e091SSteven Rostedt	    $not_used{$op} = 1;
11899cc9e091SSteven Rostedt	}
11909cc9e091SSteven Rostedt    }
11919cc9e091SSteven Rostedt
11929cc9e091SSteven Rostedt    if (%not_used) {
11939cc9e091SSteven Rostedt	my $s = "s are";
11949cc9e091SSteven Rostedt	$s = " is" if (keys %not_used == 1);
11959cc9e091SSteven Rostedt	print "The following option$s not used; could be a typo:\n";
11969cc9e091SSteven Rostedt	foreach my $option (keys %not_used) {
11979cc9e091SSteven Rostedt	    print "$option\n";
11989cc9e091SSteven Rostedt	}
11999cc9e091SSteven Rostedt	print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
12009cc9e091SSteven Rostedt	if (!read_yn "Do you want to continue?") {
12019cc9e091SSteven Rostedt	    exit -1;
12029cc9e091SSteven Rostedt	}
12039cc9e091SSteven Rostedt    }
12042545eb61SSteven Rostedt}
12052545eb61SSteven Rostedt
120623715c3cSSteven Rostedtsub __eval_option {
120704262be3SSteven Rostedt (Red Hat)    my ($name, $option, $i) = @_;
120823715c3cSSteven Rostedt
120923715c3cSSteven Rostedt    # Add space to evaluate the character before $
121023715c3cSSteven Rostedt    $option = " $option";
121123715c3cSSteven Rostedt    my $retval = "";
1212f9dfb65bSRabin Vincent    my $repeated = 0;
1213f9dfb65bSRabin Vincent    my $parent = 0;
1214f9dfb65bSRabin Vincent
1215f9dfb65bSRabin Vincent    foreach my $test (keys %repeat_tests) {
1216f9dfb65bSRabin Vincent	if ($i >= $test &&
1217f9dfb65bSRabin Vincent	    $i < $test + $repeat_tests{$test}) {
1218f9dfb65bSRabin Vincent
1219f9dfb65bSRabin Vincent	    $repeated = 1;
1220f9dfb65bSRabin Vincent	    $parent = $test;
1221f9dfb65bSRabin Vincent	    last;
1222f9dfb65bSRabin Vincent	}
1223f9dfb65bSRabin Vincent    }
122423715c3cSSteven Rostedt
122523715c3cSSteven Rostedt    while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
122623715c3cSSteven Rostedt	my $start = $1;
122723715c3cSSteven Rostedt	my $var = $2;
122823715c3cSSteven Rostedt	my $end = $3;
122923715c3cSSteven Rostedt
123023715c3cSSteven Rostedt	# Append beginning of line
123123715c3cSSteven Rostedt	$retval = "$retval$start";
123223715c3cSSteven Rostedt
123323715c3cSSteven Rostedt	# If the iteration option OPT[$i] exists, then use that.
123423715c3cSSteven Rostedt	# otherwise see if the default OPT (without [$i]) exists.
123523715c3cSSteven Rostedt
123623715c3cSSteven Rostedt	my $o = "$var\[$i\]";
1237f9dfb65bSRabin Vincent	my $parento = "$var\[$parent\]";
123823715c3cSSteven Rostedt
123904262be3SSteven Rostedt (Red Hat)	# If a variable contains itself, use the default var
124004262be3SSteven Rostedt (Red Hat)	if (($var eq $name) && defined($opt{$var})) {
124104262be3SSteven Rostedt (Red Hat)	    $o = $opt{$var};
124204262be3SSteven Rostedt (Red Hat)	    $retval = "$retval$o";
124304262be3SSteven Rostedt (Red Hat)	} elsif (defined($opt{$o})) {
124423715c3cSSteven Rostedt	    $o = $opt{$o};
124523715c3cSSteven Rostedt	    $retval = "$retval$o";
1246f9dfb65bSRabin Vincent	} elsif ($repeated && defined($opt{$parento})) {
1247f9dfb65bSRabin Vincent	    $o = $opt{$parento};
1248f9dfb65bSRabin Vincent	    $retval = "$retval$o";
124923715c3cSSteven Rostedt	} elsif (defined($opt{$var})) {
125023715c3cSSteven Rostedt	    $o = $opt{$var};
125123715c3cSSteven Rostedt	    $retval = "$retval$o";
12528e80bf05SSteven Rostedt (Red Hat)	} elsif ($var eq "KERNEL_VERSION" && defined($make)) {
12538e80bf05SSteven Rostedt (Red Hat)	    # special option KERNEL_VERSION uses kernel version
12548e80bf05SSteven Rostedt (Red Hat)	    get_version();
12558e80bf05SSteven Rostedt (Red Hat)	    $retval = "$retval$version";
125623715c3cSSteven Rostedt	} else {
125723715c3cSSteven Rostedt	    $retval = "$retval\$\{$var\}";
125823715c3cSSteven Rostedt	}
125923715c3cSSteven Rostedt
126023715c3cSSteven Rostedt	$option = $end;
126123715c3cSSteven Rostedt    }
126223715c3cSSteven Rostedt
126323715c3cSSteven Rostedt    $retval = "$retval$option";
126423715c3cSSteven Rostedt
126523715c3cSSteven Rostedt    $retval =~ s/^ //;
126623715c3cSSteven Rostedt
126723715c3cSSteven Rostedt    return $retval;
126823715c3cSSteven Rostedt}
126923715c3cSSteven Rostedt
1270c75d22d9SSteven Rostedt (Red Hat)sub process_evals {
1271c75d22d9SSteven Rostedt (Red Hat)    my ($name, $option, $i) = @_;
1272c75d22d9SSteven Rostedt (Red Hat)
1273c75d22d9SSteven Rostedt (Red Hat)    my $option_name = "$name\[$i\]";
1274c75d22d9SSteven Rostedt (Red Hat)    my $ev;
1275c75d22d9SSteven Rostedt (Red Hat)
1276c75d22d9SSteven Rostedt (Red Hat)    my $old_option = $option;
1277c75d22d9SSteven Rostedt (Red Hat)
1278c75d22d9SSteven Rostedt (Red Hat)    if (defined($evals{$option_name})) {
1279c75d22d9SSteven Rostedt (Red Hat)	$ev = $evals{$option_name};
1280c75d22d9SSteven Rostedt (Red Hat)    } elsif (defined($evals{$name})) {
1281c75d22d9SSteven Rostedt (Red Hat)	$ev = $evals{$name};
1282c75d22d9SSteven Rostedt (Red Hat)    } else {
1283c75d22d9SSteven Rostedt (Red Hat)	return $option;
1284c75d22d9SSteven Rostedt (Red Hat)    }
1285c75d22d9SSteven Rostedt (Red Hat)
1286c75d22d9SSteven Rostedt (Red Hat)    for my $e (@{$ev}) {
1287c75d22d9SSteven Rostedt (Red Hat)	eval "\$option =~ $e";
1288c75d22d9SSteven Rostedt (Red Hat)    }
1289c75d22d9SSteven Rostedt (Red Hat)
1290c75d22d9SSteven Rostedt (Red Hat)    if ($option ne $old_option) {
1291c75d22d9SSteven Rostedt (Red Hat)	doprint("$name changed from '$old_option' to '$option'\n");
1292c75d22d9SSteven Rostedt (Red Hat)    }
1293c75d22d9SSteven Rostedt (Red Hat)
1294c75d22d9SSteven Rostedt (Red Hat)    return $option;
1295c75d22d9SSteven Rostedt (Red Hat)}
1296c75d22d9SSteven Rostedt (Red Hat)
129723715c3cSSteven Rostedtsub eval_option {
129804262be3SSteven Rostedt (Red Hat)    my ($name, $option, $i) = @_;
129923715c3cSSteven Rostedt
130023715c3cSSteven Rostedt    my $prev = "";
130123715c3cSSteven Rostedt
130223715c3cSSteven Rostedt    # Since an option can evaluate to another option,
130323715c3cSSteven Rostedt    # keep iterating until we do not evaluate any more
130423715c3cSSteven Rostedt    # options.
130523715c3cSSteven Rostedt    my $r = 0;
130623715c3cSSteven Rostedt    while ($prev ne $option) {
130723715c3cSSteven Rostedt	# Check for recursive evaluations.
130823715c3cSSteven Rostedt	# 100 deep should be more than enough.
130923715c3cSSteven Rostedt	if ($r++ > 100) {
131023715c3cSSteven Rostedt	    die "Over 100 evaluations accurred with $option\n" .
131123715c3cSSteven Rostedt		"Check for recursive variables\n";
131223715c3cSSteven Rostedt	}
131323715c3cSSteven Rostedt	$prev = $option;
131404262be3SSteven Rostedt (Red Hat)	$option = __eval_option($name, $option, $i);
131523715c3cSSteven Rostedt    }
131623715c3cSSteven Rostedt
1317c75d22d9SSteven Rostedt (Red Hat)    $option = process_evals($name, $option, $i);
1318c75d22d9SSteven Rostedt (Red Hat)
131923715c3cSSteven Rostedt    return $option;
132023715c3cSSteven Rostedt}
132123715c3cSSteven Rostedt
13227faafbd6SSteven Rostedtsub run_command;
13232728be41SAndrew Jonessub start_monitor;
13242728be41SAndrew Jonessub end_monitor;
13252728be41SAndrew Jonessub wait_for_monitor;
13267faafbd6SSteven Rostedt
13277faafbd6SSteven Rostedtsub reboot {
13282728be41SAndrew Jones    my ($time) = @_;
13296474ace9SSteven Rostedt (VMware)    my $powercycle = 0;
13302728be41SAndrew Jones
13316474ace9SSteven Rostedt (VMware)    # test if the machine can be connected to within 5 seconds
13326474ace9SSteven Rostedt (VMware)    my $stat = run_ssh("echo check machine status", 5);
13336474ace9SSteven Rostedt (VMware)    if (!$stat) {
13346474ace9SSteven Rostedt (VMware)	doprint("power cycle\n");
13356474ace9SSteven Rostedt (VMware)	$powercycle = 1;
13366474ace9SSteven Rostedt (VMware)    }
13376474ace9SSteven Rostedt (VMware)
13386474ace9SSteven Rostedt (VMware)    if ($powercycle) {
13396474ace9SSteven Rostedt (VMware)	run_command "$power_cycle";
13406474ace9SSteven Rostedt (VMware)
13416474ace9SSteven Rostedt (VMware)	start_monitor;
13426474ace9SSteven Rostedt (VMware)	# flush out current monitor
13436474ace9SSteven Rostedt (VMware)	# May contain the reboot success line
13446474ace9SSteven Rostedt (VMware)	wait_for_monitor 1;
13456474ace9SSteven Rostedt (VMware)
13466474ace9SSteven Rostedt (VMware)    } else {
1347a4968722SSteven Rostedt	# Make sure everything has been written to disk
1348a4968722SSteven Rostedt	run_ssh("sync");
1349a4968722SSteven Rostedt
13502b803365SSteven Rostedt	if (defined($time)) {
13512b803365SSteven Rostedt	    start_monitor;
13522b803365SSteven Rostedt	    # flush out current monitor
13532b803365SSteven Rostedt	    # May contain the reboot success line
13542b803365SSteven Rostedt	    wait_for_monitor 1;
13552b803365SSteven Rostedt	}
13562b803365SSteven Rostedt
13577faafbd6SSteven Rostedt	# try to reboot normally
1358e48c5293SSteven Rostedt	if (run_command $reboot) {
1359576f627cSSteven Rostedt	    if (defined($powercycle_after_reboot)) {
1360576f627cSSteven Rostedt		sleep $powercycle_after_reboot;
1361576f627cSSteven Rostedt		run_command "$power_cycle";
1362576f627cSSteven Rostedt	    }
1363576f627cSSteven Rostedt	} else {
13647faafbd6SSteven Rostedt	    # nope? power cycle it.
1365a75fececSSteven Rostedt	    run_command "$power_cycle";
13667faafbd6SSteven Rostedt	}
13676474ace9SSteven Rostedt (VMware)    }
13682728be41SAndrew Jones
13692728be41SAndrew Jones    if (defined($time)) {
13704c0b67a2SSteven Rostedt (Red Hat)
13714c0b67a2SSteven Rostedt (Red Hat)	# We only want to get to the new kernel, don't fail
13724c0b67a2SSteven Rostedt (Red Hat)	# if we stumble over a call trace.
13734c0b67a2SSteven Rostedt (Red Hat)	my $save_ignore_errors = $ignore_errors;
13744c0b67a2SSteven Rostedt (Red Hat)	$ignore_errors = 1;
13754c0b67a2SSteven Rostedt (Red Hat)
1376d6845536SSteven Rostedt (Red Hat)	# Look for the good kernel to boot
1377d6845536SSteven Rostedt (Red Hat)	if (wait_for_monitor($time, "Linux version")) {
1378407b95b7SSteven Rostedt	    # reboot got stuck?
13798a80c727SSteven Rostedt	    doprint "Reboot did not finish. Forcing power cycle\n";
1380407b95b7SSteven Rostedt	    run_command "$power_cycle";
1381407b95b7SSteven Rostedt	}
1382d6845536SSteven Rostedt (Red Hat)
13834c0b67a2SSteven Rostedt (Red Hat)	$ignore_errors = $save_ignore_errors;
13844c0b67a2SSteven Rostedt (Red Hat)
1385d6845536SSteven Rostedt (Red Hat)	# Still need to wait for the reboot to finish
1386d6845536SSteven Rostedt (Red Hat)	wait_for_monitor($time, $reboot_success_line);
1387d6845536SSteven Rostedt (Red Hat)
13882728be41SAndrew Jones	end_monitor;
13892728be41SAndrew Jones    }
13907faafbd6SSteven Rostedt}
13917faafbd6SSteven Rostedt
1392bc7c5803SSteven Rostedtsub reboot_to_good {
1393bc7c5803SSteven Rostedt    my ($time) = @_;
1394bc7c5803SSteven Rostedt
1395bc7c5803SSteven Rostedt    if (defined($switch_to_good)) {
1396bc7c5803SSteven Rostedt	run_command $switch_to_good;
1397bc7c5803SSteven Rostedt    }
1398bc7c5803SSteven Rostedt
1399bc7c5803SSteven Rostedt    reboot $time;
1400bc7c5803SSteven Rostedt}
1401bc7c5803SSteven Rostedt
1402576f627cSSteven Rostedtsub do_not_reboot {
1403576f627cSSteven Rostedt    my $i = $iteration;
1404576f627cSSteven Rostedt
14054ab1cce5SSteven Rostedt    return $test_type eq "build" || $no_reboot ||
1406576f627cSSteven Rostedt	($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1407576f627cSSteven Rostedt	($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1408576f627cSSteven Rostedt}
1409576f627cSSteven Rostedt
14105c42fc5bSSteven Rostedtsub dodie {
14115a391fbfSSteven Rostedt    doprint "CRITICAL FAILURE... ", @_, "\n";
14125c42fc5bSSteven Rostedt
1413576f627cSSteven Rostedt    my $i = $iteration;
1414576f627cSSteven Rostedt
1415576f627cSSteven Rostedt    if ($reboot_on_error && !do_not_reboot) {
1416576f627cSSteven Rostedt
141775c3fda7SSteven Rostedt	doprint "REBOOTING\n";
1418bc7c5803SSteven Rostedt	reboot_to_good;
141975c3fda7SSteven Rostedt
1420a75fececSSteven Rostedt    } elsif ($poweroff_on_error && defined($power_off)) {
14215c42fc5bSSteven Rostedt	doprint "POWERING OFF\n";
1422a75fececSSteven Rostedt	`$power_off`;
14235c42fc5bSSteven Rostedt    }
142475c3fda7SSteven Rostedt
1425f80802cbSSteven Rostedt    if (defined($opt{"LOG_FILE"})) {
1426f80802cbSSteven Rostedt	print " See $opt{LOG_FILE} for more info.\n";
1427f80802cbSSteven Rostedt    }
1428f80802cbSSteven Rostedt
14291cb9e642SJosh Poimboeuf    if ($monitor_cnt) {
14301cb9e642SJosh Poimboeuf	    # restore terminal settings
14311cb9e642SJosh Poimboeuf	    system("stty $stty_orig");
14321cb9e642SJosh Poimboeuf    }
14331cb9e642SJosh Poimboeuf
14342e07c9f5SSteven Rostedt (VMware)    if (defined($post_test)) {
14352e07c9f5SSteven Rostedt (VMware)	run_command $post_test;
14362e07c9f5SSteven Rostedt (VMware)    }
14372e07c9f5SSteven Rostedt (VMware)
1438576f627cSSteven Rostedt    die @_, "\n";
14395c42fc5bSSteven Rostedt}
14405c42fc5bSSteven Rostedt
14419f2cdcbbSJosh Poimboeufsub create_pty {
14429f2cdcbbSJosh Poimboeuf    my ($ptm, $pts) = @_;
14439f2cdcbbSJosh Poimboeuf    my $tmp;
14449f2cdcbbSJosh Poimboeuf    my $TIOCSPTLCK = 0x40045431;
14459f2cdcbbSJosh Poimboeuf    my $TIOCGPTN = 0x80045430;
14467faafbd6SSteven Rostedt
14479f2cdcbbSJosh Poimboeuf    sysopen($ptm, "/dev/ptmx", O_RDWR | O_NONBLOCK) or
14489f2cdcbbSJosh Poimboeuf	dodie "Cant open /dev/ptmx";
14499f2cdcbbSJosh Poimboeuf
14509f2cdcbbSJosh Poimboeuf    # unlockpt()
14519f2cdcbbSJosh Poimboeuf    $tmp = pack("i", 0);
14529f2cdcbbSJosh Poimboeuf    ioctl($ptm, $TIOCSPTLCK, $tmp) or
14539f2cdcbbSJosh Poimboeuf	dodie "ioctl TIOCSPTLCK for /dev/ptmx failed";
14549f2cdcbbSJosh Poimboeuf
14559f2cdcbbSJosh Poimboeuf    # ptsname()
14569f2cdcbbSJosh Poimboeuf    ioctl($ptm, $TIOCGPTN, $tmp) or
14579f2cdcbbSJosh Poimboeuf	dodie "ioctl TIOCGPTN for /dev/ptmx failed";
14589f2cdcbbSJosh Poimboeuf    $tmp = unpack("i", $tmp);
14599f2cdcbbSJosh Poimboeuf
14609f2cdcbbSJosh Poimboeuf    sysopen($pts, "/dev/pts/$tmp", O_RDWR | O_NONBLOCK) or
14619f2cdcbbSJosh Poimboeuf	dodie "Can't open /dev/pts/$tmp";
14629f2cdcbbSJosh Poimboeuf}
14639f2cdcbbSJosh Poimboeuf
14649f2cdcbbSJosh Poimboeufsub exec_console {
14659f2cdcbbSJosh Poimboeuf    my ($ptm, $pts) = @_;
14669f2cdcbbSJosh Poimboeuf
14679f2cdcbbSJosh Poimboeuf    close($ptm);
14689f2cdcbbSJosh Poimboeuf
14699f2cdcbbSJosh Poimboeuf    close(\*STDIN);
14709f2cdcbbSJosh Poimboeuf    close(\*STDOUT);
14719f2cdcbbSJosh Poimboeuf    close(\*STDERR);
14729f2cdcbbSJosh Poimboeuf
14739f2cdcbbSJosh Poimboeuf    open(\*STDIN, '<&', $pts);
14749f2cdcbbSJosh Poimboeuf    open(\*STDOUT, '>&', $pts);
14759f2cdcbbSJosh Poimboeuf    open(\*STDERR, '>&', $pts);
14769f2cdcbbSJosh Poimboeuf
14779f2cdcbbSJosh Poimboeuf    close($pts);
14789f2cdcbbSJosh Poimboeuf
14799f2cdcbbSJosh Poimboeuf    exec $console or
14801cb9e642SJosh Poimboeuf	die "Can't open console $console";
14819f2cdcbbSJosh Poimboeuf}
14829f2cdcbbSJosh Poimboeuf
14839f2cdcbbSJosh Poimboeufsub open_console {
14849f2cdcbbSJosh Poimboeuf    my ($ptm) = @_;
14859f2cdcbbSJosh Poimboeuf    my $pts = \*PTSFD;
14869f2cdcbbSJosh Poimboeuf    my $pid;
14877faafbd6SSteven Rostedt
148898842782SJosh Poimboeuf    # save terminal settings
14899d2f7f05SJosh Poimboeuf    $stty_orig = `stty -g`;
14909d2f7f05SJosh Poimboeuf
14919d2f7f05SJosh Poimboeuf    # place terminal in cbreak mode so that stdin can be read one character at
14929d2f7f05SJosh Poimboeuf    # a time without having to wait for a newline
14939d2f7f05SJosh Poimboeuf    system("stty -icanon -echo -icrnl");
149498842782SJosh Poimboeuf
14959f2cdcbbSJosh Poimboeuf    create_pty($ptm, $pts);
14967faafbd6SSteven Rostedt
14979f2cdcbbSJosh Poimboeuf    $pid = fork;
14989f2cdcbbSJosh Poimboeuf
14999f2cdcbbSJosh Poimboeuf    if (!$pid) {
15009f2cdcbbSJosh Poimboeuf	# child
15019f2cdcbbSJosh Poimboeuf	exec_console($ptm, $pts)
15029f2cdcbbSJosh Poimboeuf    }
15039f2cdcbbSJosh Poimboeuf
15049f2cdcbbSJosh Poimboeuf    # parent
15059f2cdcbbSJosh Poimboeuf    close($pts);
15067faafbd6SSteven Rostedt
15077faafbd6SSteven Rostedt    return $pid;
15089f2cdcbbSJosh Poimboeuf
15099f2cdcbbSJosh Poimboeuf    open(PTSFD, "Stop perl from warning about single use of PTSFD");
15107faafbd6SSteven Rostedt}
15117faafbd6SSteven Rostedt
15127faafbd6SSteven Rostedtsub close_console {
15137faafbd6SSteven Rostedt    my ($fp, $pid) = @_;
15147faafbd6SSteven Rostedt
15157faafbd6SSteven Rostedt    doprint "kill child process $pid\n";
15165a5d8e48SSatoru Takeuchi    kill $close_console_signal, $pid;
15177faafbd6SSteven Rostedt
15187faafbd6SSteven Rostedt    print "closing!\n";
15197faafbd6SSteven Rostedt    close($fp);
152098842782SJosh Poimboeuf
152198842782SJosh Poimboeuf    # restore terminal settings
15229d2f7f05SJosh Poimboeuf    system("stty $stty_orig");
15237faafbd6SSteven Rostedt}
15247faafbd6SSteven Rostedt
15257faafbd6SSteven Rostedtsub start_monitor {
15267faafbd6SSteven Rostedt    if ($monitor_cnt++) {
15277faafbd6SSteven Rostedt	return;
15287faafbd6SSteven Rostedt    }
15297faafbd6SSteven Rostedt    $monitor_fp = \*MONFD;
15307faafbd6SSteven Rostedt    $monitor_pid = open_console $monitor_fp;
1531a75fececSSteven Rostedt
1532a75fececSSteven Rostedt    return;
1533a75fececSSteven Rostedt
1534a75fececSSteven Rostedt    open(MONFD, "Stop perl from warning about single use of MONFD");
15357faafbd6SSteven Rostedt}
15367faafbd6SSteven Rostedt
15377faafbd6SSteven Rostedtsub end_monitor {
1538319ab14fSSteven Rostedt (Red Hat)    return if (!defined $console);
15397faafbd6SSteven Rostedt    if (--$monitor_cnt) {
15407faafbd6SSteven Rostedt	return;
15417faafbd6SSteven Rostedt    }
15427faafbd6SSteven Rostedt    close_console($monitor_fp, $monitor_pid);
15437faafbd6SSteven Rostedt}
15447faafbd6SSteven Rostedt
15457faafbd6SSteven Rostedtsub wait_for_monitor {
15462b803365SSteven Rostedt    my ($time, $stop) = @_;
15472b803365SSteven Rostedt    my $full_line = "";
15487faafbd6SSteven Rostedt    my $line;
15492b803365SSteven Rostedt    my $booted = 0;
1550407b95b7SSteven Rostedt    my $start_time = time;
15518a80c727SSteven Rostedt    my $skip_call_trace = 0;
15528a80c727SSteven Rostedt    my $bug = 0;
15538a80c727SSteven Rostedt    my $bug_ignored = 0;
1554407b95b7SSteven Rostedt    my $now;
15557faafbd6SSteven Rostedt
1556a75fececSSteven Rostedt    doprint "** Wait for monitor to settle down **\n";
15577faafbd6SSteven Rostedt
15587faafbd6SSteven Rostedt    # read the monitor and wait for the system to calm down
15592b803365SSteven Rostedt    while (!$booted) {
15607faafbd6SSteven Rostedt	$line = wait_for_input($monitor_fp, $time);
15612b803365SSteven Rostedt	last if (!defined($line));
15622b803365SSteven Rostedt	print "$line";
15632b803365SSteven Rostedt	$full_line .= $line;
15642b803365SSteven Rostedt
15652b803365SSteven Rostedt	if (defined($stop) && $full_line =~ /$stop/) {
15662b803365SSteven Rostedt	    doprint "wait for monitor detected $stop\n";
15672b803365SSteven Rostedt	    $booted = 1;
15682b803365SSteven Rostedt	}
15692b803365SSteven Rostedt
15708a80c727SSteven Rostedt	if ($full_line =~ /\[ backtrace testing \]/) {
15718a80c727SSteven Rostedt	    $skip_call_trace = 1;
15728a80c727SSteven Rostedt	}
15738a80c727SSteven Rostedt
15748a80c727SSteven Rostedt	if ($full_line =~ /call trace:/i) {
15758a80c727SSteven Rostedt	    if (!$bug && !$skip_call_trace) {
15768a80c727SSteven Rostedt		if ($ignore_errors) {
15778a80c727SSteven Rostedt		    $bug_ignored = 1;
15788a80c727SSteven Rostedt		} else {
15798a80c727SSteven Rostedt		    $bug = 1;
15808a80c727SSteven Rostedt		}
15818a80c727SSteven Rostedt	    }
15828a80c727SSteven Rostedt	}
15838a80c727SSteven Rostedt
15848a80c727SSteven Rostedt	if ($full_line =~ /\[ end of backtrace testing \]/) {
15858a80c727SSteven Rostedt	    $skip_call_trace = 0;
15868a80c727SSteven Rostedt	}
15878a80c727SSteven Rostedt
15888a80c727SSteven Rostedt	if ($full_line =~ /Kernel panic -/) {
15898a80c727SSteven Rostedt	    $bug = 1;
15908a80c727SSteven Rostedt	}
15918a80c727SSteven Rostedt
15922b803365SSteven Rostedt	if ($line =~ /\n/) {
15932b803365SSteven Rostedt	    $full_line = "";
15942b803365SSteven Rostedt	}
1595407b95b7SSteven Rostedt	$now = time;
1596407b95b7SSteven Rostedt	if ($now - $start_time >= $max_monitor_wait) {
1597407b95b7SSteven Rostedt	    doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1598407b95b7SSteven Rostedt	    return 1;
1599407b95b7SSteven Rostedt	}
16002b803365SSteven Rostedt    }
1601a75fececSSteven Rostedt    print "** Monitor flushed **\n";
1602995bc431SSteven Rostedt (Red Hat)
1603995bc431SSteven Rostedt (Red Hat)    # if stop is defined but wasn't hit, return error
1604995bc431SSteven Rostedt (Red Hat)    # used by reboot (which wants to see a reboot)
1605995bc431SSteven Rostedt (Red Hat)    if (defined($stop) && !$booted) {
1606995bc431SSteven Rostedt (Red Hat)	$bug = 1;
1607995bc431SSteven Rostedt (Red Hat)    }
16088a80c727SSteven Rostedt    return $bug;
16097faafbd6SSteven Rostedt}
16107faafbd6SSteven Rostedt
1611de5b6e3bSRabin Vincentsub save_logs {
1612de5b6e3bSRabin Vincent	my ($result, $basedir) = @_;
1613de5b6e3bSRabin Vincent	my @t = localtime;
1614de5b6e3bSRabin Vincent	my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1615de5b6e3bSRabin Vincent		1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1616de5b6e3bSRabin Vincent
1617de5b6e3bSRabin Vincent	my $type = $build_type;
1618de5b6e3bSRabin Vincent	if ($type =~ /useconfig/) {
1619de5b6e3bSRabin Vincent	    $type = "useconfig";
1620de5b6e3bSRabin Vincent	}
1621de5b6e3bSRabin Vincent
1622de5b6e3bSRabin Vincent	my $dir = "$machine-$test_type-$type-$result-$date";
1623de5b6e3bSRabin Vincent
1624de5b6e3bSRabin Vincent	$dir = "$basedir/$dir";
1625de5b6e3bSRabin Vincent
1626de5b6e3bSRabin Vincent	if (!-d $dir) {
1627de5b6e3bSRabin Vincent	    mkpath($dir) or
1628de5b6e3bSRabin Vincent		die "can't create $dir";
1629de5b6e3bSRabin Vincent	}
1630de5b6e3bSRabin Vincent
1631de5b6e3bSRabin Vincent	my %files = (
1632de5b6e3bSRabin Vincent		"config" => $output_config,
1633de5b6e3bSRabin Vincent		"buildlog" => $buildlog,
1634de5b6e3bSRabin Vincent		"dmesg" => $dmesg,
1635de5b6e3bSRabin Vincent		"testlog" => $testlog,
1636de5b6e3bSRabin Vincent	);
1637de5b6e3bSRabin Vincent
1638de5b6e3bSRabin Vincent	while (my ($name, $source) = each(%files)) {
1639de5b6e3bSRabin Vincent		if (-f "$source") {
1640de5b6e3bSRabin Vincent			cp "$source", "$dir/$name" or
1641de5b6e3bSRabin Vincent				die "failed to copy $source";
1642de5b6e3bSRabin Vincent		}
1643de5b6e3bSRabin Vincent	}
1644de5b6e3bSRabin Vincent
1645de5b6e3bSRabin Vincent	doprint "*** Saved info to $dir ***\n";
1646de5b6e3bSRabin Vincent}
1647de5b6e3bSRabin Vincent
16482b7d9b21SSteven Rostedtsub fail {
16492b7d9b21SSteven Rostedt
1650a75fececSSteven Rostedt	if ($die_on_failure) {
16512b7d9b21SSteven Rostedt		dodie @_;
16522b7d9b21SSteven Rostedt	}
16532b7d9b21SSteven Rostedt
1654a75fececSSteven Rostedt	doprint "FAILED\n";
16557faafbd6SSteven Rostedt
1656576f627cSSteven Rostedt	my $i = $iteration;
1657576f627cSSteven Rostedt
1658a75fececSSteven Rostedt	# no need to reboot for just building.
1659576f627cSSteven Rostedt	if (!do_not_reboot) {
16607faafbd6SSteven Rostedt	    doprint "REBOOTING\n";
1661bc7c5803SSteven Rostedt	    reboot_to_good $sleep_time;
1662a75fececSSteven Rostedt	}
16637faafbd6SSteven Rostedt
16649064af52SSteven Rostedt	my $name = "";
16659064af52SSteven Rostedt
16669064af52SSteven Rostedt	if (defined($test_name)) {
16679064af52SSteven Rostedt	    $name = " ($test_name)";
16689064af52SSteven Rostedt	}
16699064af52SSteven Rostedt
16704bf6e1fcSSteven Rostedt (Red Hat)	print_times;
16714bf6e1fcSSteven Rostedt (Red Hat)
1672576f627cSSteven Rostedt	doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1673576f627cSSteven Rostedt	doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
16749064af52SSteven Rostedt	doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1675576f627cSSteven Rostedt	doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1676576f627cSSteven Rostedt	doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1677a75fececSSteven Rostedt
1678de5b6e3bSRabin Vincent	if (defined($store_failures)) {
1679de5b6e3bSRabin Vincent	    save_logs "fail", $store_failures;
1680cccae1a6SSteven Rostedt        }
1681cccae1a6SSteven Rostedt
16822e07c9f5SSteven Rostedt (VMware)	if (defined($post_test)) {
16832e07c9f5SSteven Rostedt (VMware)		run_command $post_test;
16842e07c9f5SSteven Rostedt (VMware)	}
16852e07c9f5SSteven Rostedt (VMware)
16862b7d9b21SSteven Rostedt	return 1;
16872b7d9b21SSteven Rostedt}
16882b7d9b21SSteven Rostedt
16892545eb61SSteven Rostedtsub run_command {
16906e98d1b4SSteven Rostedt (VMware)    my ($command, $redirect, $timeout) = @_;
1691b53486e0SSteven Rostedt (Red Hat)    my $start_time;
1692b53486e0SSteven Rostedt (Red Hat)    my $end_time;
1693d6ce2a0bSSteven Rostedt    my $dolog = 0;
1694d6ce2a0bSSteven Rostedt    my $dord = 0;
1695d6ce2a0bSSteven Rostedt    my $pid;
1696d6ce2a0bSSteven Rostedt
1697e48c5293SSteven Rostedt    $command =~ s/\$SSH_USER/$ssh_user/g;
1698e48c5293SSteven Rostedt    $command =~ s/\$MACHINE/$machine/g;
1699e48c5293SSteven Rostedt
1700d6ce2a0bSSteven Rostedt    doprint("$command ... ");
17016e98d1b4SSteven Rostedt (VMware)    $start_time = time;
1702d6ce2a0bSSteven Rostedt
1703d6ce2a0bSSteven Rostedt    $pid = open(CMD, "$command 2>&1 |") or
17042b7d9b21SSteven Rostedt	(fail "unable to exec $command" and return 0);
17052545eb61SSteven Rostedt
17062545eb61SSteven Rostedt    if (defined($opt{"LOG_FILE"})) {
1707d6ce2a0bSSteven Rostedt	open(LOG, ">>$opt{LOG_FILE}") or
1708d6ce2a0bSSteven Rostedt	    dodie "failed to write to log";
1709d6ce2a0bSSteven Rostedt	$dolog = 1;
17106c5ee0beSSteven Rostedt    }
17116c5ee0beSSteven Rostedt
17126c5ee0beSSteven Rostedt    if (defined($redirect)) {
1713d6ce2a0bSSteven Rostedt	open (RD, ">$redirect") or
1714d6ce2a0bSSteven Rostedt	    dodie "failed to write to redirect $redirect";
1715d6ce2a0bSSteven Rostedt	$dord = 1;
17162545eb61SSteven Rostedt    }
17172545eb61SSteven Rostedt
17186e98d1b4SSteven Rostedt (VMware)    my $hit_timeout = 0;
17196e98d1b4SSteven Rostedt (VMware)
17206e98d1b4SSteven Rostedt (VMware)    while (1) {
17216e98d1b4SSteven Rostedt (VMware)	my $fp = \*CMD;
17226e98d1b4SSteven Rostedt (VMware)	if (defined($timeout)) {
17236e98d1b4SSteven Rostedt (VMware)	    doprint "timeout = $timeout\n";
17246e98d1b4SSteven Rostedt (VMware)	}
17256e98d1b4SSteven Rostedt (VMware)	my $line = wait_for_input($fp, $timeout);
17266e98d1b4SSteven Rostedt (VMware)	if (!defined($line)) {
17276e98d1b4SSteven Rostedt (VMware)	    my $now = time;
17286e98d1b4SSteven Rostedt (VMware)	    if (defined($timeout) && (($now - $start_time) >= $timeout)) {
17296e98d1b4SSteven Rostedt (VMware)		doprint "Hit timeout of $timeout, killing process\n";
17306e98d1b4SSteven Rostedt (VMware)		$hit_timeout = 1;
17316e98d1b4SSteven Rostedt (VMware)		kill 9, $pid;
17326e98d1b4SSteven Rostedt (VMware)	    }
17336e98d1b4SSteven Rostedt (VMware)	    last;
17346e98d1b4SSteven Rostedt (VMware)	}
17356e98d1b4SSteven Rostedt (VMware)	print LOG $line if ($dolog);
17366e98d1b4SSteven Rostedt (VMware)	print RD $line if ($dord);
1737d6ce2a0bSSteven Rostedt    }
17382545eb61SSteven Rostedt
1739d6ce2a0bSSteven Rostedt    waitpid($pid, 0);
17405739438bSSteven Rostedt (VMware)    # shift 8 for real exit status
17415739438bSSteven Rostedt (VMware)    $run_command_status = $? >> 8;
17426e98d1b4SSteven Rostedt (VMware)
1743d6ce2a0bSSteven Rostedt    close(CMD);
1744d6ce2a0bSSteven Rostedt    close(LOG) if ($dolog);
1745d6ce2a0bSSteven Rostedt    close(RD)  if ($dord);
1746d6ce2a0bSSteven Rostedt
1747b53486e0SSteven Rostedt (Red Hat)    $end_time = time;
1748b53486e0SSteven Rostedt (Red Hat)    my $delta = $end_time - $start_time;
1749b53486e0SSteven Rostedt (Red Hat)
1750b53486e0SSteven Rostedt (Red Hat)    if ($delta == 1) {
1751b53486e0SSteven Rostedt (Red Hat)	doprint "[1 second] ";
1752b53486e0SSteven Rostedt (Red Hat)    } else {
1753b53486e0SSteven Rostedt (Red Hat)	doprint "[$delta seconds] ";
1754b53486e0SSteven Rostedt (Red Hat)    }
1755b53486e0SSteven Rostedt (Red Hat)
17565739438bSSteven Rostedt (VMware)    if ($hit_timeout) {
17575739438bSSteven Rostedt (VMware)	$run_command_status = 1;
17585739438bSSteven Rostedt (VMware)    }
17595739438bSSteven Rostedt (VMware)
17605739438bSSteven Rostedt (VMware)    if ($run_command_status) {
17612545eb61SSteven Rostedt	doprint "FAILED!\n";
17622545eb61SSteven Rostedt    } else {
17632545eb61SSteven Rostedt	doprint "SUCCESS\n";
17642545eb61SSteven Rostedt    }
17652545eb61SSteven Rostedt
17665739438bSSteven Rostedt (VMware)    return !$run_command_status;
17675f9b6cedSSteven Rostedt}
17685f9b6cedSSteven Rostedt
1769e48c5293SSteven Rostedtsub run_ssh {
17706e98d1b4SSteven Rostedt (VMware)    my ($cmd, $timeout) = @_;
1771e48c5293SSteven Rostedt    my $cp_exec = $ssh_exec;
1772e48c5293SSteven Rostedt
1773e48c5293SSteven Rostedt    $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
17746e98d1b4SSteven Rostedt (VMware)    return run_command "$cp_exec", undef , $timeout;
1775e48c5293SSteven Rostedt}
1776e48c5293SSteven Rostedt
1777e48c5293SSteven Rostedtsub run_scp {
177802ad2617SSteven Rostedt    my ($src, $dst, $cp_scp) = @_;
1779e48c5293SSteven Rostedt
1780e48c5293SSteven Rostedt    $cp_scp =~ s/\$SRC_FILE/$src/g;
1781e48c5293SSteven Rostedt    $cp_scp =~ s/\$DST_FILE/$dst/g;
1782e48c5293SSteven Rostedt
1783e48c5293SSteven Rostedt    return run_command "$cp_scp";
1784e48c5293SSteven Rostedt}
1785e48c5293SSteven Rostedt
178602ad2617SSteven Rostedtsub run_scp_install {
178702ad2617SSteven Rostedt    my ($src, $dst) = @_;
178802ad2617SSteven Rostedt
178902ad2617SSteven Rostedt    my $cp_scp = $scp_to_target_install;
179002ad2617SSteven Rostedt
179102ad2617SSteven Rostedt    return run_scp($src, $dst, $cp_scp);
179202ad2617SSteven Rostedt}
179302ad2617SSteven Rostedt
179402ad2617SSteven Rostedtsub run_scp_mod {
179502ad2617SSteven Rostedt    my ($src, $dst) = @_;
179602ad2617SSteven Rostedt
179702ad2617SSteven Rostedt    my $cp_scp = $scp_to_target;
179802ad2617SSteven Rostedt
179902ad2617SSteven Rostedt    return run_scp($src, $dst, $cp_scp);
180002ad2617SSteven Rostedt}
180102ad2617SSteven Rostedt
1802a15ba913SSteven Rostedtsub get_grub2_index {
1803a15ba913SSteven Rostedt
1804752d9665SSteven Rostedt (Red Hat)    return if (defined($grub_number) && defined($last_grub_menu) &&
1805df5f7c66SSteven Rostedt (Red Hat)	       $last_grub_menu eq $grub_menu && defined($last_machine) &&
1806df5f7c66SSteven Rostedt (Red Hat)	       $last_machine eq $machine);
1807a15ba913SSteven Rostedt
1808a15ba913SSteven Rostedt    doprint "Find grub2 menu ... ";
1809a15ba913SSteven Rostedt    $grub_number = -1;
1810a15ba913SSteven Rostedt
1811a15ba913SSteven Rostedt    my $ssh_grub = $ssh_exec;
1812a15ba913SSteven Rostedt    $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1813a15ba913SSteven Rostedt
1814a15ba913SSteven Rostedt    open(IN, "$ssh_grub |")
1815a15ba913SSteven Rostedt	or die "unable to get $grub_file";
1816a15ba913SSteven Rostedt
1817a15ba913SSteven Rostedt    my $found = 0;
1818a15ba913SSteven Rostedt
1819a15ba913SSteven Rostedt    while (<IN>) {
1820a15ba913SSteven Rostedt	if (/^menuentry.*$grub_menu/) {
1821a15ba913SSteven Rostedt	    $grub_number++;
1822a15ba913SSteven Rostedt	    $found = 1;
1823a15ba913SSteven Rostedt	    last;
1824a15ba913SSteven Rostedt	} elsif (/^menuentry\s/) {
1825a15ba913SSteven Rostedt	    $grub_number++;
1826a15ba913SSteven Rostedt	}
1827a15ba913SSteven Rostedt    }
1828a15ba913SSteven Rostedt    close(IN);
1829a15ba913SSteven Rostedt
1830a15ba913SSteven Rostedt    die "Could not find '$grub_menu' in $grub_file on $machine"
1831a15ba913SSteven Rostedt	if (!$found);
1832a15ba913SSteven Rostedt    doprint "$grub_number\n";
1833752d9665SSteven Rostedt (Red Hat)    $last_grub_menu = $grub_menu;
1834df5f7c66SSteven Rostedt (Red Hat)    $last_machine = $machine;
1835a15ba913SSteven Rostedt}
1836a15ba913SSteven Rostedt
18375f9b6cedSSteven Rostedtsub get_grub_index {
18385f9b6cedSSteven Rostedt
1839a15ba913SSteven Rostedt    if ($reboot_type eq "grub2") {
1840a15ba913SSteven Rostedt	get_grub2_index;
1841a15ba913SSteven Rostedt	return;
1842a15ba913SSteven Rostedt    }
1843a15ba913SSteven Rostedt
1844a75fececSSteven Rostedt    if ($reboot_type ne "grub") {
1845a75fececSSteven Rostedt	return;
1846a75fececSSteven Rostedt    }
1847752d9665SSteven Rostedt (Red Hat)    return if (defined($grub_number) && defined($last_grub_menu) &&
1848df5f7c66SSteven Rostedt (Red Hat)	       $last_grub_menu eq $grub_menu && defined($last_machine) &&
1849df5f7c66SSteven Rostedt (Red Hat)	       $last_machine eq $machine);
18505f9b6cedSSteven Rostedt
18515f9b6cedSSteven Rostedt    doprint "Find grub menu ... ";
18525f9b6cedSSteven Rostedt    $grub_number = -1;
1853e48c5293SSteven Rostedt
1854e48c5293SSteven Rostedt    my $ssh_grub = $ssh_exec;
1855e48c5293SSteven Rostedt    $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1856e48c5293SSteven Rostedt
1857e48c5293SSteven Rostedt    open(IN, "$ssh_grub |")
18585f9b6cedSSteven Rostedt	or die "unable to get menu.lst";
1859e48c5293SSteven Rostedt
1860eaa1fe25SSteven Rostedt    my $found = 0;
1861eaa1fe25SSteven Rostedt
18625f9b6cedSSteven Rostedt    while (<IN>) {
1863a75fececSSteven Rostedt	if (/^\s*title\s+$grub_menu\s*$/) {
18645f9b6cedSSteven Rostedt	    $grub_number++;
1865eaa1fe25SSteven Rostedt	    $found = 1;
18665f9b6cedSSteven Rostedt	    last;
18675f9b6cedSSteven Rostedt	} elsif (/^\s*title\s/) {
18685f9b6cedSSteven Rostedt	    $grub_number++;
18695f9b6cedSSteven Rostedt	}
18705f9b6cedSSteven Rostedt    }
18715f9b6cedSSteven Rostedt    close(IN);
18725f9b6cedSSteven Rostedt
1873a75fececSSteven Rostedt    die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1874eaa1fe25SSteven Rostedt	if (!$found);
18755f9b6cedSSteven Rostedt    doprint "$grub_number\n";
1876752d9665SSteven Rostedt (Red Hat)    $last_grub_menu = $grub_menu;
1877df5f7c66SSteven Rostedt (Red Hat)    $last_machine = $machine;
18782545eb61SSteven Rostedt}
18792545eb61SSteven Rostedt
18802545eb61SSteven Rostedtsub wait_for_input
18812545eb61SSteven Rostedt{
18822545eb61SSteven Rostedt    my ($fp, $time) = @_;
1883*f7c6401fSSteven Rostedt (VMware)    my $start_time;
18842545eb61SSteven Rostedt    my $rin;
18859d2f7f05SJosh Poimboeuf    my $rout;
18869d2f7f05SJosh Poimboeuf    my $nr;
18879d2f7f05SJosh Poimboeuf    my $buf;
18882545eb61SSteven Rostedt    my $line;
18892545eb61SSteven Rostedt    my $ch;
18902545eb61SSteven Rostedt
18912545eb61SSteven Rostedt    if (!defined($time)) {
18922545eb61SSteven Rostedt	$time = $timeout;
18932545eb61SSteven Rostedt    }
18942545eb61SSteven Rostedt
18952545eb61SSteven Rostedt    $rin = '';
18962545eb61SSteven Rostedt    vec($rin, fileno($fp), 1) = 1;
18979d2f7f05SJosh Poimboeuf    vec($rin, fileno(\*STDIN), 1) = 1;
18989d2f7f05SJosh Poimboeuf
1899*f7c6401fSSteven Rostedt (VMware)    $start_time = time;
1900*f7c6401fSSteven Rostedt (VMware)
19019d2f7f05SJosh Poimboeuf    while (1) {
19029d2f7f05SJosh Poimboeuf	$nr = select($rout=$rin, undef, undef, $time);
19039d2f7f05SJosh Poimboeuf
1904*f7c6401fSSteven Rostedt (VMware)	last if ($nr <= 0);
19059d2f7f05SJosh Poimboeuf
19069d2f7f05SJosh Poimboeuf	# copy data from stdin to the console
19079d2f7f05SJosh Poimboeuf	if (vec($rout, fileno(\*STDIN), 1) == 1) {
190899c014a8SSteven Rostedt (VMware)	    $nr = sysread(\*STDIN, $buf, 1000);
190999c014a8SSteven Rostedt (VMware)	    syswrite($fp, $buf, $nr) if ($nr > 0);
19109d2f7f05SJosh Poimboeuf	}
19112545eb61SSteven Rostedt
1912*f7c6401fSSteven Rostedt (VMware)	# The timeout is based on time waiting for the fp data
1913*f7c6401fSSteven Rostedt (VMware)	if (vec($rout, fileno($fp), 1) != 1) {
1914*f7c6401fSSteven Rostedt (VMware)	    last if (defined($time) && (time - $start_time > $time));
1915*f7c6401fSSteven Rostedt (VMware)	    next;
1916*f7c6401fSSteven Rostedt (VMware)	}
191799c014a8SSteven Rostedt (VMware)
19182545eb61SSteven Rostedt	$line = "";
19192545eb61SSteven Rostedt
19202545eb61SSteven Rostedt	# try to read one char at a time
19212545eb61SSteven Rostedt	while (sysread $fp, $ch, 1) {
19222545eb61SSteven Rostedt	    $line .= $ch;
19232545eb61SSteven Rostedt	    last if ($ch eq "\n");
19242545eb61SSteven Rostedt	}
19252545eb61SSteven Rostedt
1926*f7c6401fSSteven Rostedt (VMware)	last if (!length($line));
19272545eb61SSteven Rostedt
19282545eb61SSteven Rostedt	return $line;
19292545eb61SSteven Rostedt    }
1930*f7c6401fSSteven Rostedt (VMware)    return undef;
19319d2f7f05SJosh Poimboeuf}
19322545eb61SSteven Rostedt
193375c3fda7SSteven Rostedtsub reboot_to {
1934bc7c5803SSteven Rostedt    if (defined($switch_to_test)) {
1935bc7c5803SSteven Rostedt	run_command $switch_to_test;
1936bc7c5803SSteven Rostedt    }
1937bc7c5803SSteven Rostedt
1938a75fececSSteven Rostedt    if ($reboot_type eq "grub") {
1939c54367f9SSteven Rostedt	run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1940a15ba913SSteven Rostedt    } elsif ($reboot_type eq "grub2") {
1941a15ba913SSteven Rostedt	run_ssh "$grub_reboot $grub_number";
19427786954cSSteven Rostedt    } elsif ($reboot_type eq "syslinux") {
19437786954cSSteven Rostedt	run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
194496f6a0dfSSteven Rostedt    } elsif (defined $reboot_script) {
1945a75fececSSteven Rostedt	run_command "$reboot_script";
19462545eb61SSteven Rostedt    }
194796f6a0dfSSteven Rostedt    reboot;
194896f6a0dfSSteven Rostedt}
19492545eb61SSteven Rostedt
1950a57419b3SSteven Rostedtsub get_sha1 {
1951a57419b3SSteven Rostedt    my ($commit) = @_;
1952a57419b3SSteven Rostedt
1953a57419b3SSteven Rostedt    doprint "git rev-list --max-count=1 $commit ... ";
1954a57419b3SSteven Rostedt    my $sha1 = `git rev-list --max-count=1 $commit`;
1955a57419b3SSteven Rostedt    my $ret = $?;
1956a57419b3SSteven Rostedt
1957a57419b3SSteven Rostedt    logit $sha1;
1958a57419b3SSteven Rostedt
1959a57419b3SSteven Rostedt    if ($ret) {
1960a57419b3SSteven Rostedt	doprint "FAILED\n";
1961a57419b3SSteven Rostedt	dodie "Failed to get git $commit";
1962a57419b3SSteven Rostedt    }
1963a57419b3SSteven Rostedt
1964a57419b3SSteven Rostedt    print "SUCCESS\n";
1965a57419b3SSteven Rostedt
1966a57419b3SSteven Rostedt    chomp $sha1;
1967a57419b3SSteven Rostedt
1968a57419b3SSteven Rostedt    return $sha1;
1969a57419b3SSteven Rostedt}
1970a57419b3SSteven Rostedt
19715a391fbfSSteven Rostedtsub monitor {
19722545eb61SSteven Rostedt    my $booted = 0;
19732545eb61SSteven Rostedt    my $bug = 0;
19746ca996ccSSteven Rostedt    my $bug_ignored = 0;
19755c42fc5bSSteven Rostedt    my $skip_call_trace = 0;
19762b7d9b21SSteven Rostedt    my $loops;
19772545eb61SSteven Rostedt
197838fa3dc1SSteven Rostedt (Red Hat)    my $start_time = time;
197938fa3dc1SSteven Rostedt (Red Hat)
19807faafbd6SSteven Rostedt    wait_for_monitor 5;
19812545eb61SSteven Rostedt
19822545eb61SSteven Rostedt    my $line;
19832545eb61SSteven Rostedt    my $full_line = "";
19842545eb61SSteven Rostedt
19857faafbd6SSteven Rostedt    open(DMESG, "> $dmesg") or
19867faafbd6SSteven Rostedt	die "unable to write to $dmesg";
19872545eb61SSteven Rostedt
198875c3fda7SSteven Rostedt    reboot_to;
19892545eb61SSteven Rostedt
19901c8a617aSSteven Rostedt    my $success_start;
19911c8a617aSSteven Rostedt    my $failure_start;
19922d01b26aSSteven Rostedt    my $monitor_start = time;
19932d01b26aSSteven Rostedt    my $done = 0;
1994f1a5b962SSteven Rostedt    my $version_found = 0;
19951c8a617aSSteven Rostedt
19962d01b26aSSteven Rostedt    while (!$done) {
19972545eb61SSteven Rostedt
1998ecaf8e52SSteven Rostedt	if ($bug && defined($stop_after_failure) &&
1999ecaf8e52SSteven Rostedt	    $stop_after_failure >= 0) {
2000ecaf8e52SSteven Rostedt	    my $time = $stop_after_failure - (time - $failure_start);
2001ecaf8e52SSteven Rostedt	    $line = wait_for_input($monitor_fp, $time);
2002ecaf8e52SSteven Rostedt	    if (!defined($line)) {
2003ecaf8e52SSteven Rostedt		doprint "bug timed out after $booted_timeout seconds\n";
2004ecaf8e52SSteven Rostedt		doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
2005ecaf8e52SSteven Rostedt		last;
2006ecaf8e52SSteven Rostedt	    }
2007ecaf8e52SSteven Rostedt	} elsif ($booted) {
2008a75fececSSteven Rostedt	    $line = wait_for_input($monitor_fp, $booted_timeout);
2009cd4f1d53SSteven Rostedt	    if (!defined($line)) {
2010cd4f1d53SSteven Rostedt		my $s = $booted_timeout == 1 ? "" : "s";
2011cd4f1d53SSteven Rostedt		doprint "Successful boot found: break after $booted_timeout second$s\n";
2012cd4f1d53SSteven Rostedt		last;
2013cd4f1d53SSteven Rostedt	    }
20142b7d9b21SSteven Rostedt	} else {
20157faafbd6SSteven Rostedt	    $line = wait_for_input($monitor_fp);
2016cd4f1d53SSteven Rostedt	    if (!defined($line)) {
2017cd4f1d53SSteven Rostedt		my $s = $timeout == 1 ? "" : "s";
2018cd4f1d53SSteven Rostedt		doprint "Timed out after $timeout second$s\n";
2019cd4f1d53SSteven Rostedt		last;
20202b7d9b21SSteven Rostedt	    }
2021cd4f1d53SSteven Rostedt	}
20222545eb61SSteven Rostedt
20232545eb61SSteven Rostedt	doprint $line;
20247faafbd6SSteven Rostedt	print DMESG $line;
20252545eb61SSteven Rostedt
20262545eb61SSteven Rostedt	# we are not guaranteed to get a full line
20272545eb61SSteven Rostedt	$full_line .= $line;
20282545eb61SSteven Rostedt
2029a75fececSSteven Rostedt	if ($full_line =~ /$success_line/) {
20302545eb61SSteven Rostedt	    $booted = 1;
20311c8a617aSSteven Rostedt	    $success_start = time;
20321c8a617aSSteven Rostedt	}
20331c8a617aSSteven Rostedt
20341c8a617aSSteven Rostedt	if ($booted && defined($stop_after_success) &&
20351c8a617aSSteven Rostedt	    $stop_after_success >= 0) {
20361c8a617aSSteven Rostedt	    my $now = time;
20371c8a617aSSteven Rostedt	    if ($now - $success_start >= $stop_after_success) {
20381c8a617aSSteven Rostedt		doprint "Test forced to stop after $stop_after_success seconds after success\n";
20391c8a617aSSteven Rostedt		last;
20401c8a617aSSteven Rostedt	    }
20412545eb61SSteven Rostedt	}
20422545eb61SSteven Rostedt
20435c42fc5bSSteven Rostedt	if ($full_line =~ /\[ backtrace testing \]/) {
20445c42fc5bSSteven Rostedt	    $skip_call_trace = 1;
20455c42fc5bSSteven Rostedt	}
20465c42fc5bSSteven Rostedt
20472545eb61SSteven Rostedt	if ($full_line =~ /call trace:/i) {
20486ca996ccSSteven Rostedt	    if (!$bug && !$skip_call_trace) {
20496ca996ccSSteven Rostedt		if ($ignore_errors) {
20506ca996ccSSteven Rostedt		    $bug_ignored = 1;
20516ca996ccSSteven Rostedt		} else {
20521c8a617aSSteven Rostedt		    $bug = 1;
20531c8a617aSSteven Rostedt		    $failure_start = time;
20541c8a617aSSteven Rostedt		}
20551c8a617aSSteven Rostedt	    }
20566ca996ccSSteven Rostedt	}
20571c8a617aSSteven Rostedt
20581c8a617aSSteven Rostedt	if ($bug && defined($stop_after_failure) &&
20591c8a617aSSteven Rostedt	    $stop_after_failure >= 0) {
20601c8a617aSSteven Rostedt	    my $now = time;
20611c8a617aSSteven Rostedt	    if ($now - $failure_start >= $stop_after_failure) {
20621c8a617aSSteven Rostedt		doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
20631c8a617aSSteven Rostedt		last;
20641c8a617aSSteven Rostedt	    }
20655c42fc5bSSteven Rostedt	}
20665c42fc5bSSteven Rostedt
20675c42fc5bSSteven Rostedt	if ($full_line =~ /\[ end of backtrace testing \]/) {
20685c42fc5bSSteven Rostedt	    $skip_call_trace = 0;
20695c42fc5bSSteven Rostedt	}
20705c42fc5bSSteven Rostedt
20715c42fc5bSSteven Rostedt	if ($full_line =~ /Kernel panic -/) {
207210abf118SSteven Rostedt	    $failure_start = time;
20732545eb61SSteven Rostedt	    $bug = 1;
20742545eb61SSteven Rostedt	}
20752545eb61SSteven Rostedt
2076f1a5b962SSteven Rostedt	# Detect triple faults by testing the banner
2077f1a5b962SSteven Rostedt	if ($full_line =~ /\bLinux version (\S+).*\n/) {
2078f1a5b962SSteven Rostedt	    if ($1 eq $version) {
2079f1a5b962SSteven Rostedt		$version_found = 1;
2080f1a5b962SSteven Rostedt	    } elsif ($version_found && $detect_triplefault) {
2081f1a5b962SSteven Rostedt		# We already booted into the kernel we are testing,
2082f1a5b962SSteven Rostedt		# but now we booted into another kernel?
2083f1a5b962SSteven Rostedt		# Consider this a triple fault.
20848b513d0cSMasanari Iida		doprint "Already booted in Linux kernel $version, but now\n";
2085f1a5b962SSteven Rostedt		doprint "we booted into Linux kernel $1.\n";
2086f1a5b962SSteven Rostedt		doprint "Assuming that this is a triple fault.\n";
2087f1a5b962SSteven Rostedt		doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
2088f1a5b962SSteven Rostedt		last;
2089f1a5b962SSteven Rostedt	    }
2090f1a5b962SSteven Rostedt	}
2091f1a5b962SSteven Rostedt
20922545eb61SSteven Rostedt	if ($line =~ /\n/) {
20932545eb61SSteven Rostedt	    $full_line = "";
20942545eb61SSteven Rostedt	}
20952d01b26aSSteven Rostedt
20962d01b26aSSteven Rostedt	if ($stop_test_after > 0 && !$booted && !$bug) {
20972d01b26aSSteven Rostedt	    if (time - $monitor_start > $stop_test_after) {
20984d62bf51SSteven Rostedt		doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
20992d01b26aSSteven Rostedt		$done = 1;
21002d01b26aSSteven Rostedt	    }
21012d01b26aSSteven Rostedt	}
21022545eb61SSteven Rostedt    }
21032545eb61SSteven Rostedt
210438fa3dc1SSteven Rostedt (Red Hat)    my $end_time = time;
210538fa3dc1SSteven Rostedt (Red Hat)    $reboot_time = $end_time - $start_time;
210638fa3dc1SSteven Rostedt (Red Hat)
21077faafbd6SSteven Rostedt    close(DMESG);
21082545eb61SSteven Rostedt
21092545eb61SSteven Rostedt    if ($bug) {
21102b7d9b21SSteven Rostedt	return 0 if ($in_bisect);
2111576f627cSSteven Rostedt	fail "failed - got a bug report" and return 0;
21122545eb61SSteven Rostedt    }
21135f9b6cedSSteven Rostedt
2114a75fececSSteven Rostedt    if (!$booted) {
2115a75fececSSteven Rostedt	return 0 if ($in_bisect);
2116576f627cSSteven Rostedt	fail "failed - never got a boot prompt." and return 0;
2117a75fececSSteven Rostedt    }
2118a75fececSSteven Rostedt
21196ca996ccSSteven Rostedt    if ($bug_ignored) {
21206ca996ccSSteven Rostedt	doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
21216ca996ccSSteven Rostedt    }
21226ca996ccSSteven Rostedt
21232b7d9b21SSteven Rostedt    return 1;
21242545eb61SSteven Rostedt}
21252545eb61SSteven Rostedt
21262b29b2f8SSteven Rostedtsub eval_kernel_version {
21272b29b2f8SSteven Rostedt    my ($option) = @_;
21282b29b2f8SSteven Rostedt
21292b29b2f8SSteven Rostedt    $option =~ s/\$KERNEL_VERSION/$version/g;
21302b29b2f8SSteven Rostedt
21312b29b2f8SSteven Rostedt    return $option;
21322b29b2f8SSteven Rostedt}
21332b29b2f8SSteven Rostedt
2134db05cfefSSteven Rostedtsub do_post_install {
2135db05cfefSSteven Rostedt
2136db05cfefSSteven Rostedt    return if (!defined($post_install));
2137db05cfefSSteven Rostedt
21382b29b2f8SSteven Rostedt    my $cp_post_install = eval_kernel_version $post_install;
2139db05cfefSSteven Rostedt    run_command "$cp_post_install" or
2140db05cfefSSteven Rostedt	dodie "Failed to run post install";
2141db05cfefSSteven Rostedt}
2142db05cfefSSteven Rostedt
2143e1a6c3d7SSteven Rostedt# Sometimes the reboot fails, and will hang. We try to ssh to the box
2144e1a6c3d7SSteven Rostedt# and if we fail, we force another reboot, that should powercycle it.
2145e1a6c3d7SSteven Rostedtsub test_booted {
2146e1a6c3d7SSteven Rostedt    if (!run_ssh "echo testing connection") {
2147e1a6c3d7SSteven Rostedt	reboot $sleep_time;
2148e1a6c3d7SSteven Rostedt    }
2149e1a6c3d7SSteven Rostedt}
2150e1a6c3d7SSteven Rostedt
21512545eb61SSteven Rostedtsub install {
21522545eb61SSteven Rostedt
2153e0a8742eSSteven Rostedt    return if ($no_install);
2154e0a8742eSSteven Rostedt
215538fa3dc1SSteven Rostedt (Red Hat)    my $start_time = time;
215638fa3dc1SSteven Rostedt (Red Hat)
2157e5c2ec11SSteven Rostedt    if (defined($pre_install)) {
2158e5c2ec11SSteven Rostedt	my $cp_pre_install = eval_kernel_version $pre_install;
2159e5c2ec11SSteven Rostedt	run_command "$cp_pre_install" or
2160e5c2ec11SSteven Rostedt	    dodie "Failed to run pre install";
2161e5c2ec11SSteven Rostedt    }
2162e5c2ec11SSteven Rostedt
21632b29b2f8SSteven Rostedt    my $cp_target = eval_kernel_version $target_image;
21642b29b2f8SSteven Rostedt
2165e1a6c3d7SSteven Rostedt    test_booted;
2166e1a6c3d7SSteven Rostedt
216702ad2617SSteven Rostedt    run_scp_install "$outputdir/$build_target", "$cp_target" or
21685c42fc5bSSteven Rostedt	dodie "failed to copy image";
21695f9b6cedSSteven Rostedt
21705f9b6cedSSteven Rostedt    my $install_mods = 0;
21715f9b6cedSSteven Rostedt
21725f9b6cedSSteven Rostedt    # should we process modules?
21735f9b6cedSSteven Rostedt    $install_mods = 0;
217451ad1dd1SSteven Rostedt    open(IN, "$output_config") or dodie("Can't read config file");
21755f9b6cedSSteven Rostedt    while (<IN>) {
21765f9b6cedSSteven Rostedt	if (/CONFIG_MODULES(=y)?/) {
21778bc5e4eaSSteven Rostedt	    if (defined($1)) {
21788bc5e4eaSSteven Rostedt		$install_mods = 1;
21795f9b6cedSSteven Rostedt		last;
21805f9b6cedSSteven Rostedt	    }
21815f9b6cedSSteven Rostedt	}
21828bc5e4eaSSteven Rostedt    }
21835f9b6cedSSteven Rostedt    close(IN);
21845f9b6cedSSteven Rostedt
21855f9b6cedSSteven Rostedt    if (!$install_mods) {
2186db05cfefSSteven Rostedt	do_post_install;
21875f9b6cedSSteven Rostedt	doprint "No modules needed\n";
218838fa3dc1SSteven Rostedt (Red Hat)	my $end_time = time;
218938fa3dc1SSteven Rostedt (Red Hat)	$install_time = $end_time - $start_time;
21905f9b6cedSSteven Rostedt	return;
21912545eb61SSteven Rostedt    }
21922545eb61SSteven Rostedt
2193627977d8SSteven Rostedt    run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
21945f9b6cedSSteven Rostedt	dodie "Failed to install modules";
21955f9b6cedSSteven Rostedt
21962545eb61SSteven Rostedt    my $modlib = "/lib/modules/$version";
2197a57419b3SSteven Rostedt    my $modtar = "ktest-mods.tar.bz2";
21982545eb61SSteven Rostedt
2199e48c5293SSteven Rostedt    run_ssh "rm -rf $modlib" or
22005c42fc5bSSteven Rostedt	dodie "failed to remove old mods: $modlib";
22012545eb61SSteven Rostedt
22025c42fc5bSSteven Rostedt    # would be nice if scp -r did not follow symbolic links
2203a75fececSSteven Rostedt    run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
22045c42fc5bSSteven Rostedt	dodie "making tarball";
22055c42fc5bSSteven Rostedt
220602ad2617SSteven Rostedt    run_scp_mod "$tmpdir/$modtar", "/tmp" or
22075c42fc5bSSteven Rostedt	dodie "failed to copy modules";
22085c42fc5bSSteven Rostedt
2209a75fececSSteven Rostedt    unlink "$tmpdir/$modtar";
22105c42fc5bSSteven Rostedt
2211e7b13441SSteven Rostedt    run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
22125c42fc5bSSteven Rostedt	dodie "failed to tar modules";
22135c42fc5bSSteven Rostedt
2214e48c5293SSteven Rostedt    run_ssh "rm -f /tmp/$modtar";
22158b37ca8cSSteven Rostedt
2216db05cfefSSteven Rostedt    do_post_install;
221738fa3dc1SSteven Rostedt (Red Hat)
221838fa3dc1SSteven Rostedt (Red Hat)    my $end_time = time;
221938fa3dc1SSteven Rostedt (Red Hat)    $install_time = $end_time - $start_time;
22202545eb61SSteven Rostedt}
22212545eb61SSteven Rostedt
2222ddf607e5SSteven Rostedtsub get_version {
2223ddf607e5SSteven Rostedt    # get the release name
2224683a3e64SSteven Rostedt    return if ($have_version);
2225ddf607e5SSteven Rostedt    doprint "$make kernelrelease ... ";
222617150fefSSteven Rostedt (Red Hat)    $version = `$make -s kernelrelease | tail -1`;
2227ddf607e5SSteven Rostedt    chomp($version);
2228ddf607e5SSteven Rostedt    doprint "$version\n";
2229683a3e64SSteven Rostedt    $have_version = 1;
2230ddf607e5SSteven Rostedt}
2231ddf607e5SSteven Rostedt
223264d98283SSteven Rostedt (Red Hat)sub start_monitor_and_install {
22339f7424ccSSteven Rostedt    # Make sure the stable kernel has finished booting
2234319ab14fSSteven Rostedt (Red Hat)
2235319ab14fSSteven Rostedt (Red Hat)    # Install bisects, don't need console
2236319ab14fSSteven Rostedt (Red Hat)    if (defined $console) {
22379f7424ccSSteven Rostedt	start_monitor;
22389f7424ccSSteven Rostedt	wait_for_monitor 5;
22399f7424ccSSteven Rostedt	end_monitor;
2240319ab14fSSteven Rostedt (Red Hat)    }
22419f7424ccSSteven Rostedt
2242ddf607e5SSteven Rostedt    get_grub_index;
2243ddf607e5SSteven Rostedt    get_version;
2244ddf607e5SSteven Rostedt    install;
2245ddf607e5SSteven Rostedt
2246319ab14fSSteven Rostedt (Red Hat)    start_monitor if (defined $console);
2247ddf607e5SSteven Rostedt    return monitor;
2248ddf607e5SSteven Rostedt}
2249ddf607e5SSteven Rostedt
22504283b169SSteven Rostedt (Red Hat)my $check_build_re = ".*:.*(warning|error|Error):.*";
22514283b169SSteven Rostedt (Red Hat)my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
22524283b169SSteven Rostedt (Red Hat)
22537328735cSSteven Rostedt (Red Hat)sub process_warning_line {
22547328735cSSteven Rostedt (Red Hat)    my ($line) = @_;
22557328735cSSteven Rostedt (Red Hat)
22567328735cSSteven Rostedt (Red Hat)    chomp $line;
22577328735cSSteven Rostedt (Red Hat)
22587328735cSSteven Rostedt (Red Hat)    # for distcc heterogeneous systems, some compilers
22597328735cSSteven Rostedt (Red Hat)    # do things differently causing warning lines
22607328735cSSteven Rostedt (Red Hat)    # to be slightly different. This makes an attempt
22617328735cSSteven Rostedt (Red Hat)    # to fixe those issues.
22627328735cSSteven Rostedt (Red Hat)
22637328735cSSteven Rostedt (Red Hat)    # chop off the index into the line
22647328735cSSteven Rostedt (Red Hat)    # using distcc, some compilers give different indexes
22657328735cSSteven Rostedt (Red Hat)    # depending on white space
22667328735cSSteven Rostedt (Red Hat)    $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
22677328735cSSteven Rostedt (Red Hat)
22687328735cSSteven Rostedt (Red Hat)    # Some compilers use UTF-8 extended for quotes and some don't.
22697328735cSSteven Rostedt (Red Hat)    $line =~ s/$utf8_quote/'/g;
22707328735cSSteven Rostedt (Red Hat)
22717328735cSSteven Rostedt (Red Hat)    return $line;
22727328735cSSteven Rostedt (Red Hat)}
22737328735cSSteven Rostedt (Red Hat)
22744283b169SSteven Rostedt (Red Hat)# Read buildlog and check against warnings file for any
22754283b169SSteven Rostedt (Red Hat)# new warnings.
22764283b169SSteven Rostedt (Red Hat)#
22774283b169SSteven Rostedt (Red Hat)# Returns 1 if OK
22784283b169SSteven Rostedt (Red Hat)#         0 otherwise
22796c5ee0beSSteven Rostedtsub check_buildlog {
22804283b169SSteven Rostedt (Red Hat)    return 1 if (!defined $warnings_file);
22814283b169SSteven Rostedt (Red Hat)
22824283b169SSteven Rostedt (Red Hat)    my %warnings_list;
22834283b169SSteven Rostedt (Red Hat)
22844283b169SSteven Rostedt (Red Hat)    # Failed builds should not reboot the target
22854283b169SSteven Rostedt (Red Hat)    my $save_no_reboot = $no_reboot;
22864283b169SSteven Rostedt (Red Hat)    $no_reboot = 1;
22874283b169SSteven Rostedt (Red Hat)
22884283b169SSteven Rostedt (Red Hat)    if (-f $warnings_file) {
22894283b169SSteven Rostedt (Red Hat)	open(IN, $warnings_file) or
22904283b169SSteven Rostedt (Red Hat)	    dodie "Error opening $warnings_file";
22914283b169SSteven Rostedt (Red Hat)
22924283b169SSteven Rostedt (Red Hat)	while (<IN>) {
22934283b169SSteven Rostedt (Red Hat)	    if (/$check_build_re/) {
22947328735cSSteven Rostedt (Red Hat)		my $warning = process_warning_line $_;
22957328735cSSteven Rostedt (Red Hat)
22967328735cSSteven Rostedt (Red Hat)		$warnings_list{$warning} = 1;
22974283b169SSteven Rostedt (Red Hat)	    }
22984283b169SSteven Rostedt (Red Hat)	}
22994283b169SSteven Rostedt (Red Hat)	close(IN);
23004283b169SSteven Rostedt (Red Hat)    }
23014283b169SSteven Rostedt (Red Hat)
23024283b169SSteven Rostedt (Red Hat)    # If warnings file didn't exist, and WARNINGS_FILE exist,
23034283b169SSteven Rostedt (Red Hat)    # then we fail on any warning!
23044283b169SSteven Rostedt (Red Hat)
23054283b169SSteven Rostedt (Red Hat)    open(IN, $buildlog) or dodie "Can't open $buildlog";
23064283b169SSteven Rostedt (Red Hat)    while (<IN>) {
23074283b169SSteven Rostedt (Red Hat)	if (/$check_build_re/) {
23087328735cSSteven Rostedt (Red Hat)	    my $warning = process_warning_line $_;
23094283b169SSteven Rostedt (Red Hat)
23107328735cSSteven Rostedt (Red Hat)	    if (!defined $warnings_list{$warning}) {
23114283b169SSteven Rostedt (Red Hat)		fail "New warning found (not in $warnings_file)\n$_\n";
23124283b169SSteven Rostedt (Red Hat)		$no_reboot = $save_no_reboot;
23134283b169SSteven Rostedt (Red Hat)		return 0;
23144283b169SSteven Rostedt (Red Hat)	    }
23154283b169SSteven Rostedt (Red Hat)	}
23164283b169SSteven Rostedt (Red Hat)    }
23174283b169SSteven Rostedt (Red Hat)    $no_reboot = $save_no_reboot;
23184283b169SSteven Rostedt (Red Hat)    close(IN);
23194283b169SSteven Rostedt (Red Hat)}
23204283b169SSteven Rostedt (Red Hat)
23214283b169SSteven Rostedt (Red Hat)sub check_patch_buildlog {
23226c5ee0beSSteven Rostedt    my ($patch) = @_;
23236c5ee0beSSteven Rostedt
23246c5ee0beSSteven Rostedt    my @files = `git show $patch | diffstat -l`;
23256c5ee0beSSteven Rostedt
232635275685SSteven Rostedt (Red Hat)    foreach my $file (@files) {
232735275685SSteven Rostedt (Red Hat)	chomp $file;
232835275685SSteven Rostedt (Red Hat)    }
232935275685SSteven Rostedt (Red Hat)
23306c5ee0beSSteven Rostedt    open(IN, "git show $patch |") or
23316c5ee0beSSteven Rostedt	dodie "failed to show $patch";
23326c5ee0beSSteven Rostedt    while (<IN>) {
23336c5ee0beSSteven Rostedt	if (m,^--- a/(.*),) {
23346c5ee0beSSteven Rostedt	    chomp $1;
23356c5ee0beSSteven Rostedt	    $files[$#files] = $1;
23366c5ee0beSSteven Rostedt	}
23376c5ee0beSSteven Rostedt    }
23386c5ee0beSSteven Rostedt    close(IN);
23396c5ee0beSSteven Rostedt
23406c5ee0beSSteven Rostedt    open(IN, $buildlog) or dodie "Can't open $buildlog";
23416c5ee0beSSteven Rostedt    while (<IN>) {
23426c5ee0beSSteven Rostedt	if (/^\s*(.*?):.*(warning|error)/) {
23436c5ee0beSSteven Rostedt	    my $err = $1;
23446c5ee0beSSteven Rostedt	    foreach my $file (@files) {
2345a75fececSSteven Rostedt		my $fullpath = "$builddir/$file";
23466c5ee0beSSteven Rostedt		if ($file eq $err || $fullpath eq $err) {
23472b7d9b21SSteven Rostedt		    fail "$file built with warnings" and return 0;
23486c5ee0beSSteven Rostedt		}
23496c5ee0beSSteven Rostedt	    }
23506c5ee0beSSteven Rostedt	}
23516c5ee0beSSteven Rostedt    }
23526c5ee0beSSteven Rostedt    close(IN);
23532b7d9b21SSteven Rostedt
23542b7d9b21SSteven Rostedt    return 1;
23556c5ee0beSSteven Rostedt}
23566c5ee0beSSteven Rostedt
2357fcb3f16aSSteven Rostedtsub apply_min_config {
2358fcb3f16aSSteven Rostedt    my $outconfig = "$output_config.new";
2359612b9e9bSSteven Rostedt
2360fcb3f16aSSteven Rostedt    # Read the config file and remove anything that
2361fcb3f16aSSteven Rostedt    # is in the force_config hash (from minconfig and others)
2362fcb3f16aSSteven Rostedt    # then add the force config back.
2363fcb3f16aSSteven Rostedt
2364fcb3f16aSSteven Rostedt    doprint "Applying minimum configurations into $output_config.new\n";
2365fcb3f16aSSteven Rostedt
2366fcb3f16aSSteven Rostedt    open (OUT, ">$outconfig") or
2367fcb3f16aSSteven Rostedt	dodie "Can't create $outconfig";
2368fcb3f16aSSteven Rostedt
2369fcb3f16aSSteven Rostedt    if (-f $output_config) {
2370fcb3f16aSSteven Rostedt	open (IN, $output_config) or
2371fcb3f16aSSteven Rostedt	    dodie "Failed to open $output_config";
2372fcb3f16aSSteven Rostedt	while (<IN>) {
2373fcb3f16aSSteven Rostedt	    if (/^(# )?(CONFIG_[^\s=]*)/) {
2374fcb3f16aSSteven Rostedt		next if (defined($force_config{$2}));
2375fcb3f16aSSteven Rostedt	    }
2376fcb3f16aSSteven Rostedt	    print OUT;
2377fcb3f16aSSteven Rostedt	}
2378fcb3f16aSSteven Rostedt	close IN;
2379fcb3f16aSSteven Rostedt    }
2380fcb3f16aSSteven Rostedt    foreach my $config (keys %force_config) {
2381fcb3f16aSSteven Rostedt	print OUT "$force_config{$config}\n";
2382fcb3f16aSSteven Rostedt    }
2383fcb3f16aSSteven Rostedt    close OUT;
2384fcb3f16aSSteven Rostedt
2385fcb3f16aSSteven Rostedt    run_command "mv $outconfig $output_config";
2386fcb3f16aSSteven Rostedt}
2387fcb3f16aSSteven Rostedt
2388fcb3f16aSSteven Rostedtsub make_oldconfig {
2389fcb3f16aSSteven Rostedt
23904c4ab120SSteven Rostedt    my @force_list = keys %force_config;
23914c4ab120SSteven Rostedt
23924c4ab120SSteven Rostedt    if ($#force_list >= 0) {
2393fcb3f16aSSteven Rostedt	apply_min_config;
23944c4ab120SSteven Rostedt    }
2395fcb3f16aSSteven Rostedt
2396fb16d891SAdam Lee    if (!run_command "$make olddefconfig") {
2397fb16d891SAdam Lee	# Perhaps olddefconfig doesn't exist in this version of the kernel
239818925170SSteven Rostedt	# try oldnoconfig
239918925170SSteven Rostedt	doprint "olddefconfig failed, trying make oldnoconfig\n";
240018925170SSteven Rostedt	if (!run_command "$make oldnoconfig") {
240118925170SSteven Rostedt	    doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2402612b9e9bSSteven Rostedt	    # try a yes '' | oldconfig
2403fcb3f16aSSteven Rostedt	    run_command "yes '' | $make oldconfig" or
2404612b9e9bSSteven Rostedt		dodie "failed make config oldconfig";
2405612b9e9bSSteven Rostedt	}
2406612b9e9bSSteven Rostedt    }
240718925170SSteven Rostedt}
2408612b9e9bSSteven Rostedt
2409fcb3f16aSSteven Rostedt# read a config file and use this to force new configs.
2410fcb3f16aSSteven Rostedtsub load_force_config {
2411fcb3f16aSSteven Rostedt    my ($config) = @_;
2412fcb3f16aSSteven Rostedt
2413cf79fab6SSteven Rostedt    doprint "Loading force configs from $config\n";
2414fcb3f16aSSteven Rostedt    open(IN, $config) or
2415fcb3f16aSSteven Rostedt	dodie "failed to read $config";
2416fcb3f16aSSteven Rostedt    while (<IN>) {
2417fcb3f16aSSteven Rostedt	chomp;
2418fcb3f16aSSteven Rostedt	if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2419fcb3f16aSSteven Rostedt	    $force_config{$1} = $_;
2420fcb3f16aSSteven Rostedt	} elsif (/^# (CONFIG_\S*) is not set/) {
2421fcb3f16aSSteven Rostedt	    $force_config{$1} = $_;
2422fcb3f16aSSteven Rostedt	}
2423fcb3f16aSSteven Rostedt    }
2424fcb3f16aSSteven Rostedt    close IN;
2425fcb3f16aSSteven Rostedt}
2426fcb3f16aSSteven Rostedt
24272545eb61SSteven Rostedtsub build {
24282545eb61SSteven Rostedt    my ($type) = @_;
24292545eb61SSteven Rostedt
24307faafbd6SSteven Rostedt    unlink $buildlog;
24317faafbd6SSteven Rostedt
243238fa3dc1SSteven Rostedt (Red Hat)    my $start_time = time;
243338fa3dc1SSteven Rostedt (Red Hat)
24344ab1cce5SSteven Rostedt    # Failed builds should not reboot the target
24354ab1cce5SSteven Rostedt    my $save_no_reboot = $no_reboot;
24364ab1cce5SSteven Rostedt    $no_reboot = 1;
24374ab1cce5SSteven Rostedt
2438683a3e64SSteven Rostedt    # Calculate a new version from here.
2439683a3e64SSteven Rostedt    $have_version = 0;
2440683a3e64SSteven Rostedt
24410bd6c1a3SSteven Rostedt    if (defined($pre_build)) {
24420bd6c1a3SSteven Rostedt	my $ret = run_command $pre_build;
24430bd6c1a3SSteven Rostedt	if (!$ret && defined($pre_build_die) &&
24440bd6c1a3SSteven Rostedt	    $pre_build_die) {
24450bd6c1a3SSteven Rostedt	    dodie "failed to pre_build\n";
24460bd6c1a3SSteven Rostedt	}
24470bd6c1a3SSteven Rostedt    }
24480bd6c1a3SSteven Rostedt
244975c3fda7SSteven Rostedt    if ($type =~ /^useconfig:(.*)/) {
245051ad1dd1SSteven Rostedt	run_command "cp $1 $output_config" or
245175c3fda7SSteven Rostedt	    dodie "could not copy $1 to .config";
24525f9b6cedSSteven Rostedt
245375c3fda7SSteven Rostedt	$type = "oldconfig";
245475c3fda7SSteven Rostedt    }
245575c3fda7SSteven Rostedt
24565c42fc5bSSteven Rostedt    # old config can ask questions
24575c42fc5bSSteven Rostedt    if ($type eq "oldconfig") {
2458fb16d891SAdam Lee	$type = "olddefconfig";
245975c3fda7SSteven Rostedt
246075c3fda7SSteven Rostedt	# allow for empty configs
246151ad1dd1SSteven Rostedt	run_command "touch $output_config";
246275c3fda7SSteven Rostedt
246313488231SAndrew Jones	if (!$noclean) {
246451ad1dd1SSteven Rostedt	    run_command "mv $output_config $outputdir/config_temp" or
24655c42fc5bSSteven Rostedt		dodie "moving .config";
24665c42fc5bSSteven Rostedt
246713488231SAndrew Jones	    run_command "$make mrproper" or dodie "make mrproper";
24685c42fc5bSSteven Rostedt
246951ad1dd1SSteven Rostedt	    run_command "mv $outputdir/config_temp $output_config" or
24705c42fc5bSSteven Rostedt		dodie "moving config_temp";
247113488231SAndrew Jones	}
24725c42fc5bSSteven Rostedt
24735c42fc5bSSteven Rostedt    } elsif (!$noclean) {
247451ad1dd1SSteven Rostedt	unlink "$output_config";
24755f9b6cedSSteven Rostedt	run_command "$make mrproper" or
24765c42fc5bSSteven Rostedt	    dodie "make mrproper";
24775c42fc5bSSteven Rostedt    }
24782545eb61SSteven Rostedt
24792545eb61SSteven Rostedt    # add something to distinguish this build
2480a75fececSSteven Rostedt    open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2481a75fececSSteven Rostedt    print OUT "$localversion\n";
24822545eb61SSteven Rostedt    close(OUT);
24832545eb61SSteven Rostedt
24845f9b6cedSSteven Rostedt    if (defined($minconfig)) {
2485fcb3f16aSSteven Rostedt	load_force_config($minconfig);
24862545eb61SSteven Rostedt    }
24872545eb61SSteven Rostedt
2488fb16d891SAdam Lee    if ($type ne "olddefconfig") {
2489fcb3f16aSSteven Rostedt	run_command "$make $type" or
24905c42fc5bSSteven Rostedt	    dodie "failed make config";
2491612b9e9bSSteven Rostedt    }
2492fcb3f16aSSteven Rostedt    # Run old config regardless, to enforce min configurations
2493fcb3f16aSSteven Rostedt    make_oldconfig;
24942545eb61SSteven Rostedt
2495f983a2bcSSatoru Takeuchi    my $build_ret = run_command "$make $build_options", $buildlog;
24960bd6c1a3SSteven Rostedt
24970bd6c1a3SSteven Rostedt    if (defined($post_build)) {
2498683a3e64SSteven Rostedt	# Because a post build may change the kernel version
2499683a3e64SSteven Rostedt	# do it now.
2500683a3e64SSteven Rostedt	get_version;
25010bd6c1a3SSteven Rostedt	my $ret = run_command $post_build;
25020bd6c1a3SSteven Rostedt	if (!$ret && defined($post_build_die) &&
25030bd6c1a3SSteven Rostedt	    $post_build_die) {
25040bd6c1a3SSteven Rostedt	    dodie "failed to post_build\n";
25050bd6c1a3SSteven Rostedt	}
25060bd6c1a3SSteven Rostedt    }
25070bd6c1a3SSteven Rostedt
25080bd6c1a3SSteven Rostedt    if (!$build_ret) {
25095f9b6cedSSteven Rostedt	# bisect may need this to pass
25104ab1cce5SSteven Rostedt	if ($in_bisect) {
25114ab1cce5SSteven Rostedt	    $no_reboot = $save_no_reboot;
25124ab1cce5SSteven Rostedt	    return 0;
25134ab1cce5SSteven Rostedt	}
25142b7d9b21SSteven Rostedt	fail "failed build" and return 0;
25152545eb61SSteven Rostedt    }
25165f9b6cedSSteven Rostedt
25174ab1cce5SSteven Rostedt    $no_reboot = $save_no_reboot;
25184ab1cce5SSteven Rostedt
251938fa3dc1SSteven Rostedt (Red Hat)    my $end_time = time;
252038fa3dc1SSteven Rostedt (Red Hat)    $build_time = $end_time - $start_time;
252138fa3dc1SSteven Rostedt (Red Hat)
25222b7d9b21SSteven Rostedt    return 1;
25232545eb61SSteven Rostedt}
25242545eb61SSteven Rostedt
252575c3fda7SSteven Rostedtsub halt {
2526e48c5293SSteven Rostedt    if (!run_ssh "halt" or defined($power_off)) {
2527576f627cSSteven Rostedt	if (defined($poweroff_after_halt)) {
2528576f627cSSteven Rostedt	    sleep $poweroff_after_halt;
2529576f627cSSteven Rostedt	    run_command "$power_off";
2530576f627cSSteven Rostedt	}
2531576f627cSSteven Rostedt    } else {
253275c3fda7SSteven Rostedt	# nope? the zap it!
2533a75fececSSteven Rostedt	run_command "$power_off";
253475c3fda7SSteven Rostedt    }
253575c3fda7SSteven Rostedt}
253675c3fda7SSteven Rostedt
25375f9b6cedSSteven Rostedtsub success {
25385f9b6cedSSteven Rostedt    my ($i) = @_;
25395f9b6cedSSteven Rostedt
2540e48c5293SSteven Rostedt    $successes++;
2541e48c5293SSteven Rostedt
25429064af52SSteven Rostedt    my $name = "";
25439064af52SSteven Rostedt
25449064af52SSteven Rostedt    if (defined($test_name)) {
25459064af52SSteven Rostedt	$name = " ($test_name)";
25469064af52SSteven Rostedt    }
25479064af52SSteven Rostedt
25484bf6e1fcSSteven Rostedt (Red Hat)    print_times;
25494bf6e1fcSSteven Rostedt (Red Hat)
25505f9b6cedSSteven Rostedt    doprint "\n\n*******************************************\n";
25515f9b6cedSSteven Rostedt    doprint     "*******************************************\n";
25529064af52SSteven Rostedt    doprint     "KTEST RESULT: TEST $i$name SUCCESS!!!!         **\n";
25535f9b6cedSSteven Rostedt    doprint     "*******************************************\n";
25545f9b6cedSSteven Rostedt    doprint     "*******************************************\n";
25555f9b6cedSSteven Rostedt
2556de5b6e3bSRabin Vincent    if (defined($store_successes)) {
2557de5b6e3bSRabin Vincent        save_logs "success", $store_successes;
2558de5b6e3bSRabin Vincent    }
2559de5b6e3bSRabin Vincent
2560576f627cSSteven Rostedt    if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
2561a75fececSSteven Rostedt	doprint "Reboot and wait $sleep_time seconds\n";
2562bc7c5803SSteven Rostedt	reboot_to_good $sleep_time;
25635f9b6cedSSteven Rostedt    }
25642e07c9f5SSteven Rostedt (VMware)
25652e07c9f5SSteven Rostedt (VMware)    if (defined($post_test)) {
25662e07c9f5SSteven Rostedt (VMware)	run_command $post_test;
25672e07c9f5SSteven Rostedt (VMware)    }
25685f9b6cedSSteven Rostedt}
25695f9b6cedSSteven Rostedt
2570c960bb9fSSteven Rostedtsub answer_bisect {
2571c960bb9fSSteven Rostedt    for (;;) {
2572fee9d3e6SChris J Arges	doprint "Pass, fail, or skip? [p/f/s]";
2573c960bb9fSSteven Rostedt	my $ans = <STDIN>;
2574c960bb9fSSteven Rostedt	chomp $ans;
2575c960bb9fSSteven Rostedt	if ($ans eq "p" || $ans eq "P") {
2576c960bb9fSSteven Rostedt	    return 1;
2577c960bb9fSSteven Rostedt	} elsif ($ans eq "f" || $ans eq "F") {
2578c960bb9fSSteven Rostedt	    return 0;
2579fee9d3e6SChris J Arges	} elsif ($ans eq "s" || $ans eq "S") {
2580fee9d3e6SChris J Arges	    return -1;
2581c960bb9fSSteven Rostedt	} else {
2582fee9d3e6SChris J Arges	    print "Please answer 'p', 'f', or 's'\n";
2583c960bb9fSSteven Rostedt	}
2584c960bb9fSSteven Rostedt    }
2585c960bb9fSSteven Rostedt}
2586c960bb9fSSteven Rostedt
25875a391fbfSSteven Rostedtsub child_run_test {
25885a391fbfSSteven Rostedt
25897faafbd6SSteven Rostedt    # child should have no power
2590a75fececSSteven Rostedt    $reboot_on_error = 0;
2591a75fececSSteven Rostedt    $poweroff_on_error = 0;
2592a75fececSSteven Rostedt    $die_on_failure = 1;
25937faafbd6SSteven Rostedt
25945739438bSSteven Rostedt (VMware)    run_command $run_test, $testlog;
2595a9dd5d63SRabin Vincent
25965739438bSSteven Rostedt (VMware)    exit $run_command_status;
25975a391fbfSSteven Rostedt}
25985a391fbfSSteven Rostedt
25995a391fbfSSteven Rostedtmy $child_done;
26005a391fbfSSteven Rostedt
26015a391fbfSSteven Rostedtsub child_finished {
26025a391fbfSSteven Rostedt    $child_done = 1;
26035a391fbfSSteven Rostedt}
26045a391fbfSSteven Rostedt
26055a391fbfSSteven Rostedtsub do_run_test {
26065a391fbfSSteven Rostedt    my $child_pid;
26075a391fbfSSteven Rostedt    my $child_exit;
26085a391fbfSSteven Rostedt    my $line;
26095a391fbfSSteven Rostedt    my $full_line;
26105a391fbfSSteven Rostedt    my $bug = 0;
26119b1d367dSSteven Rostedt    my $bug_ignored = 0;
26125a391fbfSSteven Rostedt
261338fa3dc1SSteven Rostedt (Red Hat)    my $start_time = time;
261438fa3dc1SSteven Rostedt (Red Hat)
26157faafbd6SSteven Rostedt    wait_for_monitor 1;
26165a391fbfSSteven Rostedt
26177faafbd6SSteven Rostedt    doprint "run test $run_test\n";
26185a391fbfSSteven Rostedt
26195a391fbfSSteven Rostedt    $child_done = 0;
26205a391fbfSSteven Rostedt
26215a391fbfSSteven Rostedt    $SIG{CHLD} = qw(child_finished);
26225a391fbfSSteven Rostedt
26235a391fbfSSteven Rostedt    $child_pid = fork;
26245a391fbfSSteven Rostedt
26255a391fbfSSteven Rostedt    child_run_test if (!$child_pid);
26265a391fbfSSteven Rostedt
26275a391fbfSSteven Rostedt    $full_line = "";
26285a391fbfSSteven Rostedt
26295a391fbfSSteven Rostedt    do {
26307faafbd6SSteven Rostedt	$line = wait_for_input($monitor_fp, 1);
26315a391fbfSSteven Rostedt	if (defined($line)) {
26325a391fbfSSteven Rostedt
26335a391fbfSSteven Rostedt	    # we are not guaranteed to get a full line
26345a391fbfSSteven Rostedt	    $full_line .= $line;
26358ea0e063SSteven Rostedt	    doprint $line;
26365a391fbfSSteven Rostedt
26375a391fbfSSteven Rostedt	    if ($full_line =~ /call trace:/i) {
26389b1d367dSSteven Rostedt		if ($ignore_errors) {
26399b1d367dSSteven Rostedt		    $bug_ignored = 1;
26409b1d367dSSteven Rostedt		} else {
26415a391fbfSSteven Rostedt		    $bug = 1;
26425a391fbfSSteven Rostedt		}
26439b1d367dSSteven Rostedt	    }
26445a391fbfSSteven Rostedt
26455a391fbfSSteven Rostedt	    if ($full_line =~ /Kernel panic -/) {
26465a391fbfSSteven Rostedt		$bug = 1;
26475a391fbfSSteven Rostedt	    }
26485a391fbfSSteven Rostedt
26495a391fbfSSteven Rostedt	    if ($line =~ /\n/) {
26505a391fbfSSteven Rostedt		$full_line = "";
26515a391fbfSSteven Rostedt	    }
26525a391fbfSSteven Rostedt	}
26535a391fbfSSteven Rostedt    } while (!$child_done && !$bug);
26545a391fbfSSteven Rostedt
26559b1d367dSSteven Rostedt    if (!$bug && $bug_ignored) {
26569b1d367dSSteven Rostedt	doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
26579b1d367dSSteven Rostedt    }
26589b1d367dSSteven Rostedt
26595a391fbfSSteven Rostedt    if ($bug) {
26608ea0e063SSteven Rostedt	my $failure_start = time;
26618ea0e063SSteven Rostedt	my $now;
26628ea0e063SSteven Rostedt	do {
26638ea0e063SSteven Rostedt	    $line = wait_for_input($monitor_fp, 1);
26648ea0e063SSteven Rostedt	    if (defined($line)) {
26658ea0e063SSteven Rostedt		doprint $line;
26668ea0e063SSteven Rostedt	    }
26678ea0e063SSteven Rostedt	    $now = time;
26688ea0e063SSteven Rostedt	    if ($now - $failure_start >= $stop_after_failure) {
26698ea0e063SSteven Rostedt		last;
26708ea0e063SSteven Rostedt	    }
26718ea0e063SSteven Rostedt	} while (defined($line));
26728ea0e063SSteven Rostedt
26735a391fbfSSteven Rostedt	doprint "Detected kernel crash!\n";
26745a391fbfSSteven Rostedt	# kill the child with extreme prejudice
26755a391fbfSSteven Rostedt	kill 9, $child_pid;
26765a391fbfSSteven Rostedt    }
26775a391fbfSSteven Rostedt
26785a391fbfSSteven Rostedt    waitpid $child_pid, 0;
267932677207SSteven Rostedt (VMware)    $child_exit = $? >> 8;
26805a391fbfSSteven Rostedt
268138fa3dc1SSteven Rostedt (Red Hat)    my $end_time = time;
268238fa3dc1SSteven Rostedt (Red Hat)    $test_time = $end_time - $start_time;
268338fa3dc1SSteven Rostedt (Red Hat)
2684c5dacb88SSteven Rostedt    if (!$bug && $in_bisect) {
2685c5dacb88SSteven Rostedt	if (defined($bisect_ret_good)) {
2686c5dacb88SSteven Rostedt	    if ($child_exit == $bisect_ret_good) {
2687c5dacb88SSteven Rostedt		return 1;
2688c5dacb88SSteven Rostedt	    }
2689c5dacb88SSteven Rostedt	}
2690c5dacb88SSteven Rostedt	if (defined($bisect_ret_skip)) {
2691c5dacb88SSteven Rostedt	    if ($child_exit == $bisect_ret_skip) {
2692c5dacb88SSteven Rostedt		return -1;
2693c5dacb88SSteven Rostedt	    }
2694c5dacb88SSteven Rostedt	}
2695c5dacb88SSteven Rostedt	if (defined($bisect_ret_abort)) {
2696c5dacb88SSteven Rostedt	    if ($child_exit == $bisect_ret_abort) {
2697c5dacb88SSteven Rostedt		fail "test abort" and return -2;
2698c5dacb88SSteven Rostedt	    }
2699c5dacb88SSteven Rostedt	}
2700c5dacb88SSteven Rostedt	if (defined($bisect_ret_bad)) {
2701c5dacb88SSteven Rostedt	    if ($child_exit == $bisect_ret_skip) {
2702c5dacb88SSteven Rostedt		return 0;
2703c5dacb88SSteven Rostedt	    }
2704c5dacb88SSteven Rostedt	}
2705c5dacb88SSteven Rostedt	if (defined($bisect_ret_default)) {
2706c5dacb88SSteven Rostedt	    if ($bisect_ret_default eq "good") {
2707c5dacb88SSteven Rostedt		return 1;
2708c5dacb88SSteven Rostedt	    } elsif ($bisect_ret_default eq "bad") {
2709c5dacb88SSteven Rostedt		return 0;
2710c5dacb88SSteven Rostedt	    } elsif ($bisect_ret_default eq "skip") {
2711c5dacb88SSteven Rostedt		return -1;
2712c5dacb88SSteven Rostedt	    } elsif ($bisect_ret_default eq "abort") {
2713c5dacb88SSteven Rostedt		return -2;
2714c5dacb88SSteven Rostedt	    } else {
2715c5dacb88SSteven Rostedt		fail "unknown default action: $bisect_ret_default"
2716c5dacb88SSteven Rostedt		    and return -2;
2717c5dacb88SSteven Rostedt	    }
2718c5dacb88SSteven Rostedt	}
2719c5dacb88SSteven Rostedt    }
2720c5dacb88SSteven Rostedt
27215a391fbfSSteven Rostedt    if ($bug || $child_exit) {
27222b7d9b21SSteven Rostedt	return 0 if $in_bisect;
27232b7d9b21SSteven Rostedt	fail "test failed" and return 0;
27245a391fbfSSteven Rostedt    }
27252b7d9b21SSteven Rostedt    return 1;
27265a391fbfSSteven Rostedt}
27275a391fbfSSteven Rostedt
2728a75fececSSteven Rostedtsub run_git_bisect {
2729a75fececSSteven Rostedt    my ($command) = @_;
2730a75fececSSteven Rostedt
2731a75fececSSteven Rostedt    doprint "$command ... ";
2732a75fececSSteven Rostedt
2733a75fececSSteven Rostedt    my $output = `$command 2>&1`;
2734a75fececSSteven Rostedt    my $ret = $?;
2735a75fececSSteven Rostedt
2736a75fececSSteven Rostedt    logit $output;
2737a75fececSSteven Rostedt
2738a75fececSSteven Rostedt    if ($ret) {
2739a75fececSSteven Rostedt	doprint "FAILED\n";
2740a75fececSSteven Rostedt	dodie "Failed to git bisect";
2741a75fececSSteven Rostedt    }
2742a75fececSSteven Rostedt
2743a75fececSSteven Rostedt    doprint "SUCCESS\n";
2744a75fececSSteven Rostedt    if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2745a75fececSSteven Rostedt	doprint "$1 [$2]\n";
2746a75fececSSteven Rostedt    } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
2747b5f4aea6SSteven Rostedt	$bisect_bad_commit = $1;
2748a75fececSSteven Rostedt	doprint "Found bad commit... $1\n";
2749a75fececSSteven Rostedt	return 0;
2750a75fececSSteven Rostedt    } else {
2751a75fececSSteven Rostedt	# we already logged it, just print it now.
2752a75fececSSteven Rostedt	print $output;
2753a75fececSSteven Rostedt    }
2754a75fececSSteven Rostedt
2755a75fececSSteven Rostedt    return 1;
2756a75fececSSteven Rostedt}
2757a75fececSSteven Rostedt
2758c23dca7cSSteven Rostedtsub bisect_reboot {
2759c23dca7cSSteven Rostedt    doprint "Reboot and sleep $bisect_sleep_time seconds\n";
2760bc7c5803SSteven Rostedt    reboot_to_good $bisect_sleep_time;
2761c23dca7cSSteven Rostedt}
2762c23dca7cSSteven Rostedt
2763c23dca7cSSteven Rostedt# returns 1 on success, 0 on failure, -1 on skip
27640a05c769SSteven Rostedtsub run_bisect_test {
27650a05c769SSteven Rostedt    my ($type, $buildtype) = @_;
27665f9b6cedSSteven Rostedt
27672b7d9b21SSteven Rostedt    my $failed = 0;
27685f9b6cedSSteven Rostedt    my $result;
27695f9b6cedSSteven Rostedt    my $output;
27705f9b6cedSSteven Rostedt    my $ret;
27715f9b6cedSSteven Rostedt
27720a05c769SSteven Rostedt    $in_bisect = 1;
27730a05c769SSteven Rostedt
27740a05c769SSteven Rostedt    build $buildtype or $failed = 1;
27755f9b6cedSSteven Rostedt
27765f9b6cedSSteven Rostedt    if ($type ne "build") {
2777c23dca7cSSteven Rostedt	if ($failed && $bisect_skip) {
2778c23dca7cSSteven Rostedt	    $in_bisect = 0;
2779c23dca7cSSteven Rostedt	    return -1;
2780c23dca7cSSteven Rostedt	}
27817faafbd6SSteven Rostedt	dodie "Failed on build" if $failed;
27825f9b6cedSSteven Rostedt
27835f9b6cedSSteven Rostedt	# Now boot the box
278464d98283SSteven Rostedt (Red Hat)	start_monitor_and_install or $failed = 1;
27855f9b6cedSSteven Rostedt
27865f9b6cedSSteven Rostedt	if ($type ne "boot") {
2787c23dca7cSSteven Rostedt	    if ($failed && $bisect_skip) {
2788c23dca7cSSteven Rostedt		end_monitor;
2789c23dca7cSSteven Rostedt		bisect_reboot;
2790c23dca7cSSteven Rostedt		$in_bisect = 0;
2791c23dca7cSSteven Rostedt		return -1;
2792c23dca7cSSteven Rostedt	    }
27937faafbd6SSteven Rostedt	    dodie "Failed on boot" if $failed;
27945a391fbfSSteven Rostedt
27952b7d9b21SSteven Rostedt	    do_run_test or $failed = 1;
27965f9b6cedSSteven Rostedt	}
27977faafbd6SSteven Rostedt	end_monitor;
27985f9b6cedSSteven Rostedt    }
27995f9b6cedSSteven Rostedt
28005f9b6cedSSteven Rostedt    if ($failed) {
28010a05c769SSteven Rostedt	$result = 0;
28025f9b6cedSSteven Rostedt    } else {
28030a05c769SSteven Rostedt	$result = 1;
28045f9b6cedSSteven Rostedt    }
28054025bc62SSteven Rostedt
28064025bc62SSteven Rostedt    # reboot the box to a kernel we can ssh to
28074025bc62SSteven Rostedt    if ($type ne "build") {
28084025bc62SSteven Rostedt	bisect_reboot;
28094025bc62SSteven Rostedt    }
28100a05c769SSteven Rostedt    $in_bisect = 0;
28110a05c769SSteven Rostedt
28120a05c769SSteven Rostedt    return $result;
28130a05c769SSteven Rostedt}
28140a05c769SSteven Rostedt
28150a05c769SSteven Rostedtsub run_bisect {
28160a05c769SSteven Rostedt    my ($type) = @_;
28170a05c769SSteven Rostedt    my $buildtype = "oldconfig";
28180a05c769SSteven Rostedt
28190a05c769SSteven Rostedt    # We should have a minconfig to use?
28200a05c769SSteven Rostedt    if (defined($minconfig)) {
28210a05c769SSteven Rostedt	$buildtype = "useconfig:$minconfig";
28220a05c769SSteven Rostedt    }
28230a05c769SSteven Rostedt
2824961d9cacSSteven Rostedt (Red Hat)    # If the user sets bisect_tries to less than 1, then no tries
2825961d9cacSSteven Rostedt (Red Hat)    # is a success.
2826961d9cacSSteven Rostedt (Red Hat)    my $ret = 1;
2827961d9cacSSteven Rostedt (Red Hat)
2828961d9cacSSteven Rostedt (Red Hat)    # Still let the user manually decide that though.
2829961d9cacSSteven Rostedt (Red Hat)    if ($bisect_tries < 1 && $bisect_manual) {
2830961d9cacSSteven Rostedt (Red Hat)	$ret = answer_bisect;
2831961d9cacSSteven Rostedt (Red Hat)    }
2832961d9cacSSteven Rostedt (Red Hat)
2833961d9cacSSteven Rostedt (Red Hat)    for (my $i = 0; $i < $bisect_tries; $i++) {
2834961d9cacSSteven Rostedt (Red Hat)	if ($bisect_tries > 1) {
2835961d9cacSSteven Rostedt (Red Hat)	    my $t = $i + 1;
2836961d9cacSSteven Rostedt (Red Hat)	    doprint("Running bisect trial $t of $bisect_tries:\n");
2837961d9cacSSteven Rostedt (Red Hat)	}
2838961d9cacSSteven Rostedt (Red Hat)	$ret = run_bisect_test $type, $buildtype;
28390a05c769SSteven Rostedt
2840c960bb9fSSteven Rostedt	if ($bisect_manual) {
2841c960bb9fSSteven Rostedt	    $ret = answer_bisect;
2842c960bb9fSSteven Rostedt	}
28435f9b6cedSSteven Rostedt
2844961d9cacSSteven Rostedt (Red Hat)	last if (!$ret);
2845961d9cacSSteven Rostedt (Red Hat)    }
2846961d9cacSSteven Rostedt (Red Hat)
2847d6ce2a0bSSteven Rostedt    # Are we looking for where it worked, not failed?
28485158ba3eSRuss Dill    if ($reverse_bisect && $ret >= 0) {
28490a05c769SSteven Rostedt	$ret = !$ret;
2850d6ce2a0bSSteven Rostedt    }
2851d6ce2a0bSSteven Rostedt
2852c23dca7cSSteven Rostedt    if ($ret > 0) {
28530a05c769SSteven Rostedt	return "good";
2854c23dca7cSSteven Rostedt    } elsif ($ret == 0) {
28550a05c769SSteven Rostedt	return  "bad";
2856c23dca7cSSteven Rostedt    } elsif ($bisect_skip) {
2857c23dca7cSSteven Rostedt	doprint "HIT A BAD COMMIT ... SKIPPING\n";
2858c23dca7cSSteven Rostedt	return "skip";
28590a05c769SSteven Rostedt    }
28605f9b6cedSSteven Rostedt}
28615f9b6cedSSteven Rostedt
2862dad98754SSteven Rostedtsub update_bisect_replay {
2863dad98754SSteven Rostedt    my $tmp_log = "$tmpdir/ktest_bisect_log";
2864dad98754SSteven Rostedt    run_command "git bisect log > $tmp_log" or
2865dad98754SSteven Rostedt	die "can't create bisect log";
2866dad98754SSteven Rostedt    return $tmp_log;
2867dad98754SSteven Rostedt}
2868dad98754SSteven Rostedt
28695f9b6cedSSteven Rostedtsub bisect {
28705f9b6cedSSteven Rostedt    my ($i) = @_;
28715f9b6cedSSteven Rostedt
28725f9b6cedSSteven Rostedt    my $result;
28735f9b6cedSSteven Rostedt
2874b5f4aea6SSteven Rostedt    die "BISECT_GOOD[$i] not defined\n"	if (!defined($bisect_good));
2875b5f4aea6SSteven Rostedt    die "BISECT_BAD[$i] not defined\n"	if (!defined($bisect_bad));
2876b5f4aea6SSteven Rostedt    die "BISECT_TYPE[$i] not defined\n"	if (!defined($bisect_type));
28775f9b6cedSSteven Rostedt
2878b5f4aea6SSteven Rostedt    my $good = $bisect_good;
2879b5f4aea6SSteven Rostedt    my $bad = $bisect_bad;
2880b5f4aea6SSteven Rostedt    my $type = $bisect_type;
2881b5f4aea6SSteven Rostedt    my $start = $bisect_start;
2882b5f4aea6SSteven Rostedt    my $replay = $bisect_replay;
2883b5f4aea6SSteven Rostedt    my $start_files = $bisect_files;
28843410f6fdSSteven Rostedt
28853410f6fdSSteven Rostedt    if (defined($start_files)) {
28863410f6fdSSteven Rostedt	$start_files = " -- " . $start_files;
28873410f6fdSSteven Rostedt    } else {
28883410f6fdSSteven Rostedt	$start_files = "";
28893410f6fdSSteven Rostedt    }
28905f9b6cedSSteven Rostedt
2891a57419b3SSteven Rostedt    # convert to true sha1's
2892a57419b3SSteven Rostedt    $good = get_sha1($good);
2893a57419b3SSteven Rostedt    $bad = get_sha1($bad);
2894a57419b3SSteven Rostedt
2895b5f4aea6SSteven Rostedt    if (defined($bisect_reverse) && $bisect_reverse == 1) {
2896d6ce2a0bSSteven Rostedt	doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2897d6ce2a0bSSteven Rostedt	$reverse_bisect = 1;
2898d6ce2a0bSSteven Rostedt    } else {
2899d6ce2a0bSSteven Rostedt	$reverse_bisect = 0;
2900d6ce2a0bSSteven Rostedt    }
2901d6ce2a0bSSteven Rostedt
29025a391fbfSSteven Rostedt    # Can't have a test without having a test to run
29035a391fbfSSteven Rostedt    if ($type eq "test" && !defined($run_test)) {
29045a391fbfSSteven Rostedt	$type = "boot";
29055a391fbfSSteven Rostedt    }
29065a391fbfSSteven Rostedt
2907dad98754SSteven Rostedt    # Check if a bisect was running
2908dad98754SSteven Rostedt    my $bisect_start_file = "$builddir/.git/BISECT_START";
2909dad98754SSteven Rostedt
2910b5f4aea6SSteven Rostedt    my $check = $bisect_check;
2911dad98754SSteven Rostedt    my $do_check = defined($check) && $check ne "0";
2912dad98754SSteven Rostedt
2913dad98754SSteven Rostedt    if ( -f $bisect_start_file ) {
2914dad98754SSteven Rostedt	print "Bisect in progress found\n";
2915dad98754SSteven Rostedt	if ($do_check) {
2916dad98754SSteven Rostedt	    print " If you say yes, then no checks of good or bad will be done\n";
2917dad98754SSteven Rostedt	}
2918dad98754SSteven Rostedt	if (defined($replay)) {
2919dad98754SSteven Rostedt	    print "** BISECT_REPLAY is defined in config file **";
2920dad98754SSteven Rostedt	    print " Ignore config option and perform new git bisect log?\n";
2921dad98754SSteven Rostedt	    if (read_ync " (yes, no, or cancel) ") {
2922dad98754SSteven Rostedt		$replay = update_bisect_replay;
2923dad98754SSteven Rostedt		$do_check = 0;
2924dad98754SSteven Rostedt	    }
2925dad98754SSteven Rostedt	} elsif (read_yn "read git log and continue?") {
2926dad98754SSteven Rostedt	    $replay = update_bisect_replay;
2927dad98754SSteven Rostedt	    $do_check = 0;
2928dad98754SSteven Rostedt	}
2929dad98754SSteven Rostedt    }
2930dad98754SSteven Rostedt
2931dad98754SSteven Rostedt    if ($do_check) {
2932a75fececSSteven Rostedt
2933a75fececSSteven Rostedt	# get current HEAD
2934a57419b3SSteven Rostedt	my $head = get_sha1("HEAD");
2935a75fececSSteven Rostedt
2936a75fececSSteven Rostedt	if ($check ne "good") {
2937a75fececSSteven Rostedt	    doprint "TESTING BISECT BAD [$bad]\n";
2938a75fececSSteven Rostedt	    run_command "git checkout $bad" or
2939a75fececSSteven Rostedt		die "Failed to checkout $bad";
2940a75fececSSteven Rostedt
2941a75fececSSteven Rostedt	    $result = run_bisect $type;
2942a75fececSSteven Rostedt
2943a75fececSSteven Rostedt	    if ($result ne "bad") {
2944a75fececSSteven Rostedt		fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2945a75fececSSteven Rostedt	    }
2946a75fececSSteven Rostedt	}
2947a75fececSSteven Rostedt
2948a75fececSSteven Rostedt	if ($check ne "bad") {
2949a75fececSSteven Rostedt	    doprint "TESTING BISECT GOOD [$good]\n";
2950a75fececSSteven Rostedt	    run_command "git checkout $good" or
2951a75fececSSteven Rostedt		die "Failed to checkout $good";
2952a75fececSSteven Rostedt
2953a75fececSSteven Rostedt	    $result = run_bisect $type;
2954a75fececSSteven Rostedt
2955a75fececSSteven Rostedt	    if ($result ne "good") {
2956a75fececSSteven Rostedt		fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2957a75fececSSteven Rostedt	    }
2958a75fececSSteven Rostedt	}
2959a75fececSSteven Rostedt
2960a75fececSSteven Rostedt	# checkout where we started
2961a75fececSSteven Rostedt	run_command "git checkout $head" or
2962a75fececSSteven Rostedt	    die "Failed to checkout $head";
2963a75fececSSteven Rostedt    }
2964a75fececSSteven Rostedt
29653410f6fdSSteven Rostedt    run_command "git bisect start$start_files" or
2966a75fececSSteven Rostedt	dodie "could not start bisect";
2967a75fececSSteven Rostedt
2968d832d743SSteven Rostedt (Red Hat)    if (defined($replay)) {
2969d832d743SSteven Rostedt (Red Hat)	run_command "git bisect replay $replay" or
2970d832d743SSteven Rostedt (Red Hat)	    dodie "failed to run replay";
2971d832d743SSteven Rostedt (Red Hat)    } else {
2972d832d743SSteven Rostedt (Red Hat)
2973a75fececSSteven Rostedt	run_command "git bisect good $good" or
2974a75fececSSteven Rostedt	    dodie "could not set bisect good to $good";
2975a75fececSSteven Rostedt
2976a75fececSSteven Rostedt	run_git_bisect "git bisect bad $bad" or
2977a75fececSSteven Rostedt	    dodie "could not set bisect bad to $bad";
2978a75fececSSteven Rostedt
2979a75fececSSteven Rostedt    }
2980a75fececSSteven Rostedt
2981a75fececSSteven Rostedt    if (defined($start)) {
2982a75fececSSteven Rostedt	run_command "git checkout $start" or
2983a75fececSSteven Rostedt	    dodie "failed to checkout $start";
2984a75fececSSteven Rostedt    }
2985a75fececSSteven Rostedt
2986a75fececSSteven Rostedt    my $test;
29875f9b6cedSSteven Rostedt    do {
29885f9b6cedSSteven Rostedt	$result = run_bisect $type;
2989a75fececSSteven Rostedt	$test = run_git_bisect "git bisect $result";
299038fa3dc1SSteven Rostedt (Red Hat)	print_times;
2991a75fececSSteven Rostedt    } while ($test);
29925f9b6cedSSteven Rostedt
29935f9b6cedSSteven Rostedt    run_command "git bisect log" or
29945f9b6cedSSteven Rostedt	dodie "could not capture git bisect log";
29955f9b6cedSSteven Rostedt
29965f9b6cedSSteven Rostedt    run_command "git bisect reset" or
29975f9b6cedSSteven Rostedt	dodie "could not reset git bisect";
29985f9b6cedSSteven Rostedt
2999b5f4aea6SSteven Rostedt    doprint "Bad commit was [$bisect_bad_commit]\n";
30005f9b6cedSSteven Rostedt
30010a05c769SSteven Rostedt    success $i;
30020a05c769SSteven Rostedt}
30030a05c769SSteven Rostedt
3004cf79fab6SSteven Rostedt# config_ignore holds the configs that were set (or unset) for
3005cf79fab6SSteven Rostedt# a good config and we will ignore these configs for the rest
3006cf79fab6SSteven Rostedt# of a config bisect. These configs stay as they were.
30070a05c769SSteven Rostedtmy %config_ignore;
3008cf79fab6SSteven Rostedt
3009cf79fab6SSteven Rostedt# config_set holds what all configs were set as.
30100a05c769SSteven Rostedtmy %config_set;
30110a05c769SSteven Rostedt
3012cf79fab6SSteven Rostedt# config_off holds the set of configs that the bad config had disabled.
3013cf79fab6SSteven Rostedt# We need to record them and set them in the .config when running
3014fb16d891SAdam Lee# olddefconfig, because olddefconfig keeps the defaults.
3015cf79fab6SSteven Rostedtmy %config_off;
3016cf79fab6SSteven Rostedt
3017cf79fab6SSteven Rostedt# config_off_tmp holds a set of configs to turn off for now
3018cf79fab6SSteven Rostedtmy @config_off_tmp;
3019cf79fab6SSteven Rostedt
3020cf79fab6SSteven Rostedt# config_list is the set of configs that are being tested
30210a05c769SSteven Rostedtmy %config_list;
30220a05c769SSteven Rostedtmy %null_config;
30230a05c769SSteven Rostedt
30240a05c769SSteven Rostedtmy %dependency;
30250a05c769SSteven Rostedt
30264c4ab120SSteven Rostedtsub assign_configs {
30274c4ab120SSteven Rostedt    my ($hash, $config) = @_;
30280a05c769SSteven Rostedt
30296071c22eSSteven Rostedt (Red Hat)    doprint "Reading configs from $config\n";
30306071c22eSSteven Rostedt (Red Hat)
30310a05c769SSteven Rostedt    open (IN, $config)
30320a05c769SSteven Rostedt	or dodie "Failed to read $config";
30330a05c769SSteven Rostedt
30340a05c769SSteven Rostedt    while (<IN>) {
30356071c22eSSteven Rostedt (Red Hat)	chomp;
30369bf71749SSteven Rostedt	if (/^((CONFIG\S*)=.*)/) {
30374c4ab120SSteven Rostedt	    ${$hash}{$2} = $1;
30386071c22eSSteven Rostedt (Red Hat)	} elsif (/^(# (CONFIG\S*) is not set)/) {
30396071c22eSSteven Rostedt (Red Hat)	    ${$hash}{$2} = $1;
30400a05c769SSteven Rostedt	}
30410a05c769SSteven Rostedt    }
30420a05c769SSteven Rostedt
30430a05c769SSteven Rostedt    close(IN);
30440a05c769SSteven Rostedt}
30450a05c769SSteven Rostedt
30464c4ab120SSteven Rostedtsub process_config_ignore {
30474c4ab120SSteven Rostedt    my ($config) = @_;
30484c4ab120SSteven Rostedt
30494c4ab120SSteven Rostedt    assign_configs \%config_ignore, $config;
30504c4ab120SSteven Rostedt}
30514c4ab120SSteven Rostedt
30520a05c769SSteven Rostedtsub get_dependencies {
30530a05c769SSteven Rostedt    my ($config) = @_;
30540a05c769SSteven Rostedt
30550a05c769SSteven Rostedt    my $arr = $dependency{$config};
30560a05c769SSteven Rostedt    if (!defined($arr)) {
30570a05c769SSteven Rostedt	return ();
30580a05c769SSteven Rostedt    }
30590a05c769SSteven Rostedt
30600a05c769SSteven Rostedt    my @deps = @{$arr};
30610a05c769SSteven Rostedt
30620a05c769SSteven Rostedt    foreach my $dep (@{$arr}) {
30630a05c769SSteven Rostedt	print "ADD DEP $dep\n";
30640a05c769SSteven Rostedt	@deps = (@deps, get_dependencies $dep);
30650a05c769SSteven Rostedt    }
30660a05c769SSteven Rostedt
30670a05c769SSteven Rostedt    return @deps;
30680a05c769SSteven Rostedt}
30690a05c769SSteven Rostedt
30706071c22eSSteven Rostedt (Red Hat)sub save_config {
30716071c22eSSteven Rostedt (Red Hat)    my ($pc, $file) = @_;
30720a05c769SSteven Rostedt
30736071c22eSSteven Rostedt (Red Hat)    my %configs = %{$pc};
30740a05c769SSteven Rostedt
30756071c22eSSteven Rostedt (Red Hat)    doprint "Saving configs into $file\n";
30760a05c769SSteven Rostedt
30776071c22eSSteven Rostedt (Red Hat)    open(OUT, ">$file") or dodie "Can not write to $file";
3078cf79fab6SSteven Rostedt
30796071c22eSSteven Rostedt (Red Hat)    foreach my $config (keys %configs) {
30806071c22eSSteven Rostedt (Red Hat)	print OUT "$configs{$config}\n";
30810a05c769SSteven Rostedt    }
30820a05c769SSteven Rostedt    close(OUT);
30836071c22eSSteven Rostedt (Red Hat)}
30846071c22eSSteven Rostedt (Red Hat)
30856071c22eSSteven Rostedt (Red Hat)sub create_config {
30866071c22eSSteven Rostedt (Red Hat)    my ($name, $pc) = @_;
30876071c22eSSteven Rostedt (Red Hat)
30886071c22eSSteven Rostedt (Red Hat)    doprint "Creating old config from $name configs\n";
30896071c22eSSteven Rostedt (Red Hat)
30906071c22eSSteven Rostedt (Red Hat)    save_config $pc, $output_config;
30910a05c769SSteven Rostedt
3092fcb3f16aSSteven Rostedt    make_oldconfig;
30930a05c769SSteven Rostedt}
30940a05c769SSteven Rostedt
30956071c22eSSteven Rostedt (Red Hat)# compare two config hashes, and return configs with different vals.
30966071c22eSSteven Rostedt (Red Hat)# It returns B's config values, but you can use A to see what A was.
30976071c22eSSteven Rostedt (Red Hat)sub diff_config_vals {
30986071c22eSSteven Rostedt (Red Hat)    my ($pa, $pb) = @_;
30996071c22eSSteven Rostedt (Red Hat)
31006071c22eSSteven Rostedt (Red Hat)    # crappy Perl way to pass in hashes.
31016071c22eSSteven Rostedt (Red Hat)    my %a = %{$pa};
31026071c22eSSteven Rostedt (Red Hat)    my %b = %{$pb};
31036071c22eSSteven Rostedt (Red Hat)
31046071c22eSSteven Rostedt (Red Hat)    my %ret;
31056071c22eSSteven Rostedt (Red Hat)
31066071c22eSSteven Rostedt (Red Hat)    foreach my $item (keys %a) {
31076071c22eSSteven Rostedt (Red Hat)	if (defined($b{$item}) && $b{$item} ne $a{$item}) {
31086071c22eSSteven Rostedt (Red Hat)	    $ret{$item} = $b{$item};
31096071c22eSSteven Rostedt (Red Hat)	}
31106071c22eSSteven Rostedt (Red Hat)    }
31116071c22eSSteven Rostedt (Red Hat)
31126071c22eSSteven Rostedt (Red Hat)    return %ret;
31136071c22eSSteven Rostedt (Red Hat)}
31146071c22eSSteven Rostedt (Red Hat)
31156071c22eSSteven Rostedt (Red Hat)# compare two config hashes and return the configs in B but not A
31166071c22eSSteven Rostedt (Red Hat)sub diff_configs {
31176071c22eSSteven Rostedt (Red Hat)    my ($pa, $pb) = @_;
31186071c22eSSteven Rostedt (Red Hat)
31196071c22eSSteven Rostedt (Red Hat)    my %ret;
31206071c22eSSteven Rostedt (Red Hat)
31216071c22eSSteven Rostedt (Red Hat)    # crappy Perl way to pass in hashes.
31226071c22eSSteven Rostedt (Red Hat)    my %a = %{$pa};
31236071c22eSSteven Rostedt (Red Hat)    my %b = %{$pb};
31246071c22eSSteven Rostedt (Red Hat)
31256071c22eSSteven Rostedt (Red Hat)    foreach my $item (keys %b) {
31266071c22eSSteven Rostedt (Red Hat)	if (!defined($a{$item})) {
31276071c22eSSteven Rostedt (Red Hat)	    $ret{$item} = $b{$item};
31286071c22eSSteven Rostedt (Red Hat)	}
31296071c22eSSteven Rostedt (Red Hat)    }
31306071c22eSSteven Rostedt (Red Hat)
31316071c22eSSteven Rostedt (Red Hat)    return %ret;
31326071c22eSSteven Rostedt (Red Hat)}
31336071c22eSSteven Rostedt (Red Hat)
31346071c22eSSteven Rostedt (Red Hat)# return if two configs are equal or not
31356071c22eSSteven Rostedt (Red Hat)# 0 is equal +1 b has something a does not
31366071c22eSSteven Rostedt (Red Hat)# +1 if a and b have a different item.
31376071c22eSSteven Rostedt (Red Hat)# -1 if a has something b does not
31380a05c769SSteven Rostedtsub compare_configs {
31396071c22eSSteven Rostedt (Red Hat)    my ($pa, $pb) = @_;
31406071c22eSSteven Rostedt (Red Hat)
31416071c22eSSteven Rostedt (Red Hat)    my %ret;
31426071c22eSSteven Rostedt (Red Hat)
31436071c22eSSteven Rostedt (Red Hat)    # crappy Perl way to pass in hashes.
31446071c22eSSteven Rostedt (Red Hat)    my %a = %{$pa};
31456071c22eSSteven Rostedt (Red Hat)    my %b = %{$pb};
31466071c22eSSteven Rostedt (Red Hat)
31476071c22eSSteven Rostedt (Red Hat)    foreach my $item (keys %b) {
31486071c22eSSteven Rostedt (Red Hat)	if (!defined($a{$item})) {
31496071c22eSSteven Rostedt (Red Hat)	    return 1;
31506071c22eSSteven Rostedt (Red Hat)	}
31516071c22eSSteven Rostedt (Red Hat)	if ($a{$item} ne $b{$item}) {
31526071c22eSSteven Rostedt (Red Hat)	    return 1;
31536071c22eSSteven Rostedt (Red Hat)	}
31546071c22eSSteven Rostedt (Red Hat)    }
31550a05c769SSteven Rostedt
31560a05c769SSteven Rostedt    foreach my $item (keys %a) {
31570a05c769SSteven Rostedt	if (!defined($b{$item})) {
31586071c22eSSteven Rostedt (Red Hat)	    return -1;
31590a05c769SSteven Rostedt	}
31600a05c769SSteven Rostedt    }
31610a05c769SSteven Rostedt
31620a05c769SSteven Rostedt    return 0;
31630a05c769SSteven Rostedt}
31640a05c769SSteven Rostedt
31650a05c769SSteven Rostedtsub run_config_bisect_test {
31660a05c769SSteven Rostedt    my ($type) = @_;
31670a05c769SSteven Rostedt
31684cc559bdSSteven Rostedt (Red Hat)    my $ret = run_bisect_test $type, "oldconfig";
31694cc559bdSSteven Rostedt (Red Hat)
31704cc559bdSSteven Rostedt (Red Hat)    if ($bisect_manual) {
31714cc559bdSSteven Rostedt (Red Hat)	$ret = answer_bisect;
31724cc559bdSSteven Rostedt (Red Hat)    }
31734cc559bdSSteven Rostedt (Red Hat)
31744cc559bdSSteven Rostedt (Red Hat)    return $ret;
31750a05c769SSteven Rostedt}
31760a05c769SSteven Rostedt
31770a05c769SSteven Rostedtsub process_failed {
31780a05c769SSteven Rostedt    my ($config) = @_;
31790a05c769SSteven Rostedt
31800a05c769SSteven Rostedt    doprint "\n\n***************************************\n";
31810a05c769SSteven Rostedt    doprint "Found bad config: $config\n";
31820a05c769SSteven Rostedt    doprint "***************************************\n\n";
31830a05c769SSteven Rostedt}
31840a05c769SSteven Rostedt
31856071c22eSSteven Rostedt (Red Hat)# used for config bisecting
31866071c22eSSteven Rostedt (Red Hat)my $good_config;
31876071c22eSSteven Rostedt (Red Hat)my $bad_config;
31880a05c769SSteven Rostedt
31896071c22eSSteven Rostedt (Red Hat)sub process_new_config {
31906071c22eSSteven Rostedt (Red Hat)    my ($tc, $nc, $gc, $bc) = @_;
31910a05c769SSteven Rostedt
31926071c22eSSteven Rostedt (Red Hat)    my %tmp_config = %{$tc};
31936071c22eSSteven Rostedt (Red Hat)    my %good_configs = %{$gc};
31946071c22eSSteven Rostedt (Red Hat)    my %bad_configs = %{$bc};
31950a05c769SSteven Rostedt
31966071c22eSSteven Rostedt (Red Hat)    my %new_configs;
31976071c22eSSteven Rostedt (Red Hat)
31986071c22eSSteven Rostedt (Red Hat)    my $runtest = 1;
31990a05c769SSteven Rostedt    my $ret;
32000a05c769SSteven Rostedt
32016071c22eSSteven Rostedt (Red Hat)    create_config "tmp_configs", \%tmp_config;
32026071c22eSSteven Rostedt (Red Hat)    assign_configs \%new_configs, $output_config;
32030a05c769SSteven Rostedt
32046071c22eSSteven Rostedt (Red Hat)    $ret = compare_configs \%new_configs, \%bad_configs;
32056071c22eSSteven Rostedt (Red Hat)    if (!$ret) {
32066071c22eSSteven Rostedt (Red Hat)	doprint "New config equals bad config, try next test\n";
32076071c22eSSteven Rostedt (Red Hat)	$runtest = 0;
32086071c22eSSteven Rostedt (Red Hat)    }
32090a05c769SSteven Rostedt
32106071c22eSSteven Rostedt (Red Hat)    if ($runtest) {
32116071c22eSSteven Rostedt (Red Hat)	$ret = compare_configs \%new_configs, \%good_configs;
32126071c22eSSteven Rostedt (Red Hat)	if (!$ret) {
32136071c22eSSteven Rostedt (Red Hat)	    doprint "New config equals good config, try next test\n";
32146071c22eSSteven Rostedt (Red Hat)	    $runtest = 0;
32156071c22eSSteven Rostedt (Red Hat)	}
32166071c22eSSteven Rostedt (Red Hat)    }
32170a05c769SSteven Rostedt
32186071c22eSSteven Rostedt (Red Hat)    %{$nc} = %new_configs;
32196071c22eSSteven Rostedt (Red Hat)
32206071c22eSSteven Rostedt (Red Hat)    return $runtest;
32216071c22eSSteven Rostedt (Red Hat)}
32226071c22eSSteven Rostedt (Red Hat)
32236071c22eSSteven Rostedt (Red Hat)sub run_config_bisect {
32246071c22eSSteven Rostedt (Red Hat)    my ($pgood, $pbad) = @_;
32256071c22eSSteven Rostedt (Red Hat)
32266071c22eSSteven Rostedt (Red Hat)    my $type = $config_bisect_type;
32276071c22eSSteven Rostedt (Red Hat)
32286071c22eSSteven Rostedt (Red Hat)    my %good_configs = %{$pgood};
32296071c22eSSteven Rostedt (Red Hat)    my %bad_configs = %{$pbad};
32306071c22eSSteven Rostedt (Red Hat)
32316071c22eSSteven Rostedt (Red Hat)    my %diff_configs = diff_config_vals \%good_configs, \%bad_configs;
32326071c22eSSteven Rostedt (Red Hat)    my %b_configs = diff_configs \%good_configs, \%bad_configs;
32336071c22eSSteven Rostedt (Red Hat)    my %g_configs = diff_configs \%bad_configs, \%good_configs;
32346071c22eSSteven Rostedt (Red Hat)
32356071c22eSSteven Rostedt (Red Hat)    my @diff_arr = keys %diff_configs;
32366071c22eSSteven Rostedt (Red Hat)    my $len_diff = $#diff_arr + 1;
32376071c22eSSteven Rostedt (Red Hat)
32386071c22eSSteven Rostedt (Red Hat)    my @b_arr = keys %b_configs;
32396071c22eSSteven Rostedt (Red Hat)    my $len_b = $#b_arr + 1;
32406071c22eSSteven Rostedt (Red Hat)
32416071c22eSSteven Rostedt (Red Hat)    my @g_arr = keys %g_configs;
32426071c22eSSteven Rostedt (Red Hat)    my $len_g = $#g_arr + 1;
32436071c22eSSteven Rostedt (Red Hat)
32446071c22eSSteven Rostedt (Red Hat)    my $runtest = 1;
32456071c22eSSteven Rostedt (Red Hat)    my %new_configs;
32466071c22eSSteven Rostedt (Red Hat)    my $ret;
32476071c22eSSteven Rostedt (Red Hat)
32486071c22eSSteven Rostedt (Red Hat)    # First, lets get it down to a single subset.
32496071c22eSSteven Rostedt (Red Hat)    # Is the problem with a difference in values?
32506071c22eSSteven Rostedt (Red Hat)    # Is the problem with a missing config?
32516071c22eSSteven Rostedt (Red Hat)    # Is the problem with a config that breaks things?
32526071c22eSSteven Rostedt (Red Hat)
32536071c22eSSteven Rostedt (Red Hat)    # Enable all of one set and see if we get a new bad
32546071c22eSSteven Rostedt (Red Hat)    # or good config.
32556071c22eSSteven Rostedt (Red Hat)
32566071c22eSSteven Rostedt (Red Hat)    # first set the good config to the bad values.
32576071c22eSSteven Rostedt (Red Hat)
32586071c22eSSteven Rostedt (Red Hat)    doprint "d=$len_diff g=$len_g b=$len_b\n";
32596071c22eSSteven Rostedt (Red Hat)
32606071c22eSSteven Rostedt (Red Hat)    # first lets enable things in bad config that are enabled in good config
32616071c22eSSteven Rostedt (Red Hat)
32626071c22eSSteven Rostedt (Red Hat)    if ($len_diff > 0) {
32636071c22eSSteven Rostedt (Red Hat)	if ($len_b > 0 || $len_g > 0) {
32646071c22eSSteven Rostedt (Red Hat)	    my %tmp_config = %bad_configs;
32656071c22eSSteven Rostedt (Red Hat)
32666071c22eSSteven Rostedt (Red Hat)	    doprint "Set tmp config to be bad config with good config values\n";
32676071c22eSSteven Rostedt (Red Hat)	    foreach my $item (@diff_arr) {
32686071c22eSSteven Rostedt (Red Hat)		$tmp_config{$item} = $good_configs{$item};
32696071c22eSSteven Rostedt (Red Hat)	    }
32706071c22eSSteven Rostedt (Red Hat)
32716071c22eSSteven Rostedt (Red Hat)	    $runtest = process_new_config \%tmp_config, \%new_configs,
32726071c22eSSteven Rostedt (Red Hat)			    \%good_configs, \%bad_configs;
32736071c22eSSteven Rostedt (Red Hat)	}
32746071c22eSSteven Rostedt (Red Hat)    }
32756071c22eSSteven Rostedt (Red Hat)
32766071c22eSSteven Rostedt (Red Hat)    if (!$runtest && $len_diff > 0) {
32776071c22eSSteven Rostedt (Red Hat)
32786071c22eSSteven Rostedt (Red Hat)	if ($len_diff == 1) {
32794186cb45SSteven Rostedt (Red Hat)	    process_failed $diff_arr[0];
32806071c22eSSteven Rostedt (Red Hat)	    return 1;
32816071c22eSSteven Rostedt (Red Hat)	}
32826071c22eSSteven Rostedt (Red Hat)	my %tmp_config = %bad_configs;
32836071c22eSSteven Rostedt (Red Hat)
32846071c22eSSteven Rostedt (Red Hat)	my $half = int($#diff_arr / 2);
32856071c22eSSteven Rostedt (Red Hat)	my @tophalf = @diff_arr[0 .. $half];
32866071c22eSSteven Rostedt (Red Hat)
32876071c22eSSteven Rostedt (Red Hat)	doprint "Settings bisect with top half:\n";
32886071c22eSSteven Rostedt (Red Hat)	doprint "Set tmp config to be bad config with some good config values\n";
32896071c22eSSteven Rostedt (Red Hat)	foreach my $item (@tophalf) {
32906071c22eSSteven Rostedt (Red Hat)	    $tmp_config{$item} = $good_configs{$item};
32916071c22eSSteven Rostedt (Red Hat)	}
32926071c22eSSteven Rostedt (Red Hat)
32936071c22eSSteven Rostedt (Red Hat)	$runtest = process_new_config \%tmp_config, \%new_configs,
32946071c22eSSteven Rostedt (Red Hat)			    \%good_configs, \%bad_configs;
32956071c22eSSteven Rostedt (Red Hat)
32966071c22eSSteven Rostedt (Red Hat)	if (!$runtest) {
32976071c22eSSteven Rostedt (Red Hat)	    my %tmp_config = %bad_configs;
32986071c22eSSteven Rostedt (Red Hat)
32996071c22eSSteven Rostedt (Red Hat)	    doprint "Try bottom half\n";
33006071c22eSSteven Rostedt (Red Hat)
33016071c22eSSteven Rostedt (Red Hat)	    my @bottomhalf = @diff_arr[$half+1 .. $#diff_arr];
33026071c22eSSteven Rostedt (Red Hat)
33036071c22eSSteven Rostedt (Red Hat)	    foreach my $item (@bottomhalf) {
33046071c22eSSteven Rostedt (Red Hat)		$tmp_config{$item} = $good_configs{$item};
33056071c22eSSteven Rostedt (Red Hat)	    }
33066071c22eSSteven Rostedt (Red Hat)
33076071c22eSSteven Rostedt (Red Hat)	    $runtest = process_new_config \%tmp_config, \%new_configs,
33086071c22eSSteven Rostedt (Red Hat)			    \%good_configs, \%bad_configs;
33096071c22eSSteven Rostedt (Red Hat)	}
33106071c22eSSteven Rostedt (Red Hat)    }
33116071c22eSSteven Rostedt (Red Hat)
33126071c22eSSteven Rostedt (Red Hat)    if ($runtest) {
33136071c22eSSteven Rostedt (Red Hat)	$ret = run_config_bisect_test $type;
33146071c22eSSteven Rostedt (Red Hat)	if ($ret) {
33156071c22eSSteven Rostedt (Red Hat)	    doprint "NEW GOOD CONFIG\n";
33166071c22eSSteven Rostedt (Red Hat)	    %good_configs = %new_configs;
33176071c22eSSteven Rostedt (Red Hat)	    run_command "mv $good_config ${good_config}.last";
33186071c22eSSteven Rostedt (Red Hat)	    save_config \%good_configs, $good_config;
33196071c22eSSteven Rostedt (Red Hat)	    %{$pgood} = %good_configs;
3320cf79fab6SSteven Rostedt	} else {
33216071c22eSSteven Rostedt (Red Hat)	    doprint "NEW BAD CONFIG\n";
33226071c22eSSteven Rostedt (Red Hat)	    %bad_configs = %new_configs;
33236071c22eSSteven Rostedt (Red Hat)	    run_command "mv $bad_config ${bad_config}.last";
33246071c22eSSteven Rostedt (Red Hat)	    save_config \%bad_configs, $bad_config;
33256071c22eSSteven Rostedt (Red Hat)	    %{$pbad} = %bad_configs;
33266071c22eSSteven Rostedt (Red Hat)	}
33276071c22eSSteven Rostedt (Red Hat)	return 0;
3328cf79fab6SSteven Rostedt    }
3329cf79fab6SSteven Rostedt
33306071c22eSSteven Rostedt (Red Hat)    fail "Hmm, need to do a mix match?\n";
33310a05c769SSteven Rostedt    return -1;
33320a05c769SSteven Rostedt}
33330a05c769SSteven Rostedt
33340a05c769SSteven Rostedtsub config_bisect {
33350a05c769SSteven Rostedt    my ($i) = @_;
33360a05c769SSteven Rostedt
33376071c22eSSteven Rostedt (Red Hat)    my $type = $config_bisect_type;
3338c4d1d11fSSteven Rostedt (Red Hat)    my $ret;
33390a05c769SSteven Rostedt
33406071c22eSSteven Rostedt (Red Hat)    $bad_config = $config_bisect;
33410a05c769SSteven Rostedt
334230f75da5SSteven Rostedt    if (defined($config_bisect_good)) {
33436071c22eSSteven Rostedt (Red Hat)	$good_config = $config_bisect_good;
33446071c22eSSteven Rostedt (Red Hat)    } elsif (defined($minconfig)) {
33456071c22eSSteven Rostedt (Red Hat)	$good_config = $minconfig;
33460a05c769SSteven Rostedt    } else {
33476071c22eSSteven Rostedt (Red Hat)	doprint "No config specified, checking if defconfig works";
3348c4d1d11fSSteven Rostedt (Red Hat)	$ret = run_bisect_test $type, "defconfig";
33496071c22eSSteven Rostedt (Red Hat)	if (!$ret) {
33506071c22eSSteven Rostedt (Red Hat)	    fail "Have no good config to compare with, please set CONFIG_BISECT_GOOD";
33516071c22eSSteven Rostedt (Red Hat)	    return 1;
33526071c22eSSteven Rostedt (Red Hat)	}
33536071c22eSSteven Rostedt (Red Hat)	$good_config = $output_config;
33540a05c769SSteven Rostedt    }
33550a05c769SSteven Rostedt
33566071c22eSSteven Rostedt (Red Hat)    # we don't want min configs to cause issues here.
33576071c22eSSteven Rostedt (Red Hat)    doprint "Disabling 'MIN_CONFIG' for this test\n";
33586071c22eSSteven Rostedt (Red Hat)    undef $minconfig;
33590a05c769SSteven Rostedt
33606071c22eSSteven Rostedt (Red Hat)    my %good_configs;
33616071c22eSSteven Rostedt (Red Hat)    my %bad_configs;
33626071c22eSSteven Rostedt (Red Hat)    my %tmp_configs;
33630a05c769SSteven Rostedt
33646071c22eSSteven Rostedt (Red Hat)    doprint "Run good configs through make oldconfig\n";
33656071c22eSSteven Rostedt (Red Hat)    assign_configs \%tmp_configs, $good_config;
33666071c22eSSteven Rostedt (Red Hat)    create_config "$good_config", \%tmp_configs;
33676071c22eSSteven Rostedt (Red Hat)    assign_configs \%good_configs, $output_config;
33680a05c769SSteven Rostedt
33696071c22eSSteven Rostedt (Red Hat)    doprint "Run bad configs through make oldconfig\n";
33706071c22eSSteven Rostedt (Red Hat)    assign_configs \%tmp_configs, $bad_config;
33716071c22eSSteven Rostedt (Red Hat)    create_config "$bad_config", \%tmp_configs;
33726071c22eSSteven Rostedt (Red Hat)    assign_configs \%bad_configs, $output_config;
33730a05c769SSteven Rostedt
33746071c22eSSteven Rostedt (Red Hat)    $good_config = "$tmpdir/good_config";
33756071c22eSSteven Rostedt (Red Hat)    $bad_config = "$tmpdir/bad_config";
33760a05c769SSteven Rostedt
33776071c22eSSteven Rostedt (Red Hat)    save_config \%good_configs, $good_config;
33786071c22eSSteven Rostedt (Red Hat)    save_config \%bad_configs, $bad_config;
33790a05c769SSteven Rostedt
3380c4d1d11fSSteven Rostedt (Red Hat)    if (defined($config_bisect_check) && $config_bisect_check ne "0") {
3381c4d1d11fSSteven Rostedt (Red Hat)	if ($config_bisect_check ne "good") {
3382c4d1d11fSSteven Rostedt (Red Hat)	    doprint "Testing bad config\n";
3383c4d1d11fSSteven Rostedt (Red Hat)
3384c4d1d11fSSteven Rostedt (Red Hat)	    $ret = run_bisect_test $type, "useconfig:$bad_config";
3385c4d1d11fSSteven Rostedt (Red Hat)	    if ($ret) {
3386c4d1d11fSSteven Rostedt (Red Hat)		fail "Bad config succeeded when expected to fail!";
3387c4d1d11fSSteven Rostedt (Red Hat)		return 0;
3388c4d1d11fSSteven Rostedt (Red Hat)	    }
3389c4d1d11fSSteven Rostedt (Red Hat)	}
3390c4d1d11fSSteven Rostedt (Red Hat)	if ($config_bisect_check ne "bad") {
3391c4d1d11fSSteven Rostedt (Red Hat)	    doprint "Testing good config\n";
3392c4d1d11fSSteven Rostedt (Red Hat)
3393c4d1d11fSSteven Rostedt (Red Hat)	    $ret = run_bisect_test $type, "useconfig:$good_config";
3394c4d1d11fSSteven Rostedt (Red Hat)	    if (!$ret) {
3395c4d1d11fSSteven Rostedt (Red Hat)		fail "Good config failed when expected to succeed!";
3396c4d1d11fSSteven Rostedt (Red Hat)		return 0;
3397c4d1d11fSSteven Rostedt (Red Hat)	    }
3398c4d1d11fSSteven Rostedt (Red Hat)	}
3399c4d1d11fSSteven Rostedt (Red Hat)    }
3400b0918612SSteven Rostedt
34010a05c769SSteven Rostedt    do {
34026071c22eSSteven Rostedt (Red Hat)	$ret = run_config_bisect \%good_configs, \%bad_configs;
340338fa3dc1SSteven Rostedt (Red Hat)	print_times;
34040a05c769SSteven Rostedt    } while (!$ret);
34050a05c769SSteven Rostedt
34060a05c769SSteven Rostedt    return $ret if ($ret < 0);
34075f9b6cedSSteven Rostedt
34085f9b6cedSSteven Rostedt    success $i;
34095f9b6cedSSteven Rostedt}
34105f9b6cedSSteven Rostedt
341127d934b2SSteven Rostedtsub patchcheck_reboot {
341227d934b2SSteven Rostedt    doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
3413bc7c5803SSteven Rostedt    reboot_to_good $patchcheck_sleep_time;
341427d934b2SSteven Rostedt}
341527d934b2SSteven Rostedt
34166c5ee0beSSteven Rostedtsub patchcheck {
34176c5ee0beSSteven Rostedt    my ($i) = @_;
34186c5ee0beSSteven Rostedt
34196c5ee0beSSteven Rostedt    die "PATCHCHECK_START[$i] not defined\n"
3420b5f4aea6SSteven Rostedt	if (!defined($patchcheck_start));
34216c5ee0beSSteven Rostedt    die "PATCHCHECK_TYPE[$i] not defined\n"
3422b5f4aea6SSteven Rostedt	if (!defined($patchcheck_type));
34236c5ee0beSSteven Rostedt
3424b5f4aea6SSteven Rostedt    my $start = $patchcheck_start;
34256c5ee0beSSteven Rostedt
342623a0e161SSteven Rostedt (Red Hat)    my $cherry = $patchcheck_cherry;
342723a0e161SSteven Rostedt (Red Hat)    if (!defined($cherry)) {
342823a0e161SSteven Rostedt (Red Hat)	$cherry = 0;
342923a0e161SSteven Rostedt (Red Hat)    }
343023a0e161SSteven Rostedt (Red Hat)
34316c5ee0beSSteven Rostedt    my $end = "HEAD";
3432b5f4aea6SSteven Rostedt    if (defined($patchcheck_end)) {
3433b5f4aea6SSteven Rostedt	$end = $patchcheck_end;
343423a0e161SSteven Rostedt (Red Hat)    } elsif ($cherry) {
343523a0e161SSteven Rostedt (Red Hat)	die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
34366c5ee0beSSteven Rostedt    }
34376c5ee0beSSteven Rostedt
3438a57419b3SSteven Rostedt    # Get the true sha1's since we can use things like HEAD~3
3439a57419b3SSteven Rostedt    $start = get_sha1($start);
3440a57419b3SSteven Rostedt    $end = get_sha1($end);
3441a57419b3SSteven Rostedt
3442b5f4aea6SSteven Rostedt    my $type = $patchcheck_type;
34436c5ee0beSSteven Rostedt
34446c5ee0beSSteven Rostedt    # Can't have a test without having a test to run
34456c5ee0beSSteven Rostedt    if ($type eq "test" && !defined($run_test)) {
34466c5ee0beSSteven Rostedt	$type = "boot";
34476c5ee0beSSteven Rostedt    }
34486c5ee0beSSteven Rostedt
344923a0e161SSteven Rostedt (Red Hat)    if ($cherry) {
345023a0e161SSteven Rostedt (Red Hat)	open (IN, "git cherry -v $start $end|") or
345123a0e161SSteven Rostedt (Red Hat)	    dodie "could not get git list";
345223a0e161SSteven Rostedt (Red Hat)    } else {
34536c5ee0beSSteven Rostedt	open (IN, "git log --pretty=oneline $end|") or
34546c5ee0beSSteven Rostedt	    dodie "could not get git list";
345523a0e161SSteven Rostedt (Red Hat)    }
34566c5ee0beSSteven Rostedt
34576c5ee0beSSteven Rostedt    my @list;
34586c5ee0beSSteven Rostedt
34596c5ee0beSSteven Rostedt    while (<IN>) {
34606c5ee0beSSteven Rostedt	chomp;
346123a0e161SSteven Rostedt (Red Hat)	# git cherry adds a '+' we want to remove
346223a0e161SSteven Rostedt (Red Hat)	s/^\+ //;
34636c5ee0beSSteven Rostedt	$list[$#list+1] = $_;
34646c5ee0beSSteven Rostedt	last if (/^$start/);
34656c5ee0beSSteven Rostedt    }
34666c5ee0beSSteven Rostedt    close(IN);
34676c5ee0beSSteven Rostedt
346823a0e161SSteven Rostedt (Red Hat)    if (!$cherry) {
34696c5ee0beSSteven Rostedt	if ($list[$#list] !~ /^$start/) {
34702b7d9b21SSteven Rostedt	    fail "SHA1 $start not found";
34716c5ee0beSSteven Rostedt	}
34726c5ee0beSSteven Rostedt
34736c5ee0beSSteven Rostedt	# go backwards in the list
34746c5ee0beSSteven Rostedt	@list = reverse @list;
347523a0e161SSteven Rostedt (Red Hat)    }
347623a0e161SSteven Rostedt (Red Hat)
347723a0e161SSteven Rostedt (Red Hat)    doprint("Going to test the following commits:\n");
347823a0e161SSteven Rostedt (Red Hat)    foreach my $l (@list) {
347923a0e161SSteven Rostedt (Red Hat)	doprint "$l\n";
348023a0e161SSteven Rostedt (Red Hat)    }
34816c5ee0beSSteven Rostedt
34826c5ee0beSSteven Rostedt    my $save_clean = $noclean;
34831990207dSSteven Rostedt    my %ignored_warnings;
34841990207dSSteven Rostedt
34851990207dSSteven Rostedt    if (defined($ignore_warnings)) {
34861990207dSSteven Rostedt	foreach my $sha1 (split /\s+/, $ignore_warnings) {
34871990207dSSteven Rostedt	    $ignored_warnings{$sha1} = 1;
34881990207dSSteven Rostedt	}
34891990207dSSteven Rostedt    }
34906c5ee0beSSteven Rostedt
34916c5ee0beSSteven Rostedt    $in_patchcheck = 1;
34926c5ee0beSSteven Rostedt    foreach my $item (@list) {
34936c5ee0beSSteven Rostedt	my $sha1 = $item;
34946c5ee0beSSteven Rostedt	$sha1 =~ s/^([[:xdigit:]]+).*/$1/;
34956c5ee0beSSteven Rostedt
34967c2c49ecSSteven Rostedt (Red Hat)	doprint "\nProcessing commit \"$item\"\n\n";
34976c5ee0beSSteven Rostedt
34986c5ee0beSSteven Rostedt	run_command "git checkout $sha1" or
34996c5ee0beSSteven Rostedt	    die "Failed to checkout $sha1";
35006c5ee0beSSteven Rostedt
35016c5ee0beSSteven Rostedt	# only clean on the first and last patch
35026c5ee0beSSteven Rostedt	if ($item eq $list[0] ||
35036c5ee0beSSteven Rostedt	    $item eq $list[$#list]) {
35046c5ee0beSSteven Rostedt	    $noclean = $save_clean;
35056c5ee0beSSteven Rostedt	} else {
35066c5ee0beSSteven Rostedt	    $noclean = 1;
35076c5ee0beSSteven Rostedt	}
35086c5ee0beSSteven Rostedt
35096c5ee0beSSteven Rostedt	if (defined($minconfig)) {
35102b7d9b21SSteven Rostedt	    build "useconfig:$minconfig" or return 0;
35116c5ee0beSSteven Rostedt	} else {
35126c5ee0beSSteven Rostedt	    # ?? no config to use?
35132b7d9b21SSteven Rostedt	    build "oldconfig" or return 0;
35146c5ee0beSSteven Rostedt	}
35156c5ee0beSSteven Rostedt
35164283b169SSteven Rostedt (Red Hat)	# No need to do per patch checking if warnings file exists
35174283b169SSteven Rostedt (Red Hat)	if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
35184283b169SSteven Rostedt (Red Hat)	    check_patch_buildlog $sha1 or return 0;
35191990207dSSteven Rostedt	}
35206c5ee0beSSteven Rostedt
35214283b169SSteven Rostedt (Red Hat)	check_buildlog or return 0;
35224283b169SSteven Rostedt (Red Hat)
35236c5ee0beSSteven Rostedt	next if ($type eq "build");
35246c5ee0beSSteven Rostedt
35257faafbd6SSteven Rostedt	my $failed = 0;
35267faafbd6SSteven Rostedt
352764d98283SSteven Rostedt (Red Hat)	start_monitor_and_install or $failed = 1;
35287faafbd6SSteven Rostedt
35297faafbd6SSteven Rostedt	if (!$failed && $type ne "boot"){
35307faafbd6SSteven Rostedt	    do_run_test or $failed = 1;
35317faafbd6SSteven Rostedt	}
35327faafbd6SSteven Rostedt	end_monitor;
353338fa3dc1SSteven Rostedt (Red Hat)	if ($failed) {
353438fa3dc1SSteven Rostedt (Red Hat)	    print_times;
353538fa3dc1SSteven Rostedt (Red Hat)	    return 0;
353638fa3dc1SSteven Rostedt (Red Hat)	}
353727d934b2SSteven Rostedt	patchcheck_reboot;
353838fa3dc1SSteven Rostedt (Red Hat)	print_times;
35396c5ee0beSSteven Rostedt    }
35406c5ee0beSSteven Rostedt    $in_patchcheck = 0;
35416c5ee0beSSteven Rostedt    success $i;
35422b7d9b21SSteven Rostedt
35432b7d9b21SSteven Rostedt    return 1;
35446c5ee0beSSteven Rostedt}
35456c5ee0beSSteven Rostedt
3546b9066f6cSSteven Rostedtmy %depends;
3547ac6974c7SSteven Rostedtmy %depcount;
3548b9066f6cSSteven Rostedtmy $iflevel = 0;
3549b9066f6cSSteven Rostedtmy @ifdeps;
3550b9066f6cSSteven Rostedt
3551b9066f6cSSteven Rostedt# prevent recursion
3552b9066f6cSSteven Rostedtmy %read_kconfigs;
3553b9066f6cSSteven Rostedt
3554ac6974c7SSteven Rostedtsub add_dep {
3555ac6974c7SSteven Rostedt    # $config depends on $dep
3556ac6974c7SSteven Rostedt    my ($config, $dep) = @_;
3557ac6974c7SSteven Rostedt
3558ac6974c7SSteven Rostedt    if (defined($depends{$config})) {
3559ac6974c7SSteven Rostedt	$depends{$config} .= " " . $dep;
3560ac6974c7SSteven Rostedt    } else {
3561ac6974c7SSteven Rostedt	$depends{$config} = $dep;
3562ac6974c7SSteven Rostedt    }
3563ac6974c7SSteven Rostedt
3564ac6974c7SSteven Rostedt    # record the number of configs depending on $dep
3565ac6974c7SSteven Rostedt    if (defined $depcount{$dep}) {
3566ac6974c7SSteven Rostedt	$depcount{$dep}++;
3567ac6974c7SSteven Rostedt    } else {
3568ac6974c7SSteven Rostedt	$depcount{$dep} = 1;
3569ac6974c7SSteven Rostedt    }
3570ac6974c7SSteven Rostedt}
3571ac6974c7SSteven Rostedt
3572b9066f6cSSteven Rostedt# taken from streamline_config.pl
3573b9066f6cSSteven Rostedtsub read_kconfig {
3574b9066f6cSSteven Rostedt    my ($kconfig) = @_;
3575b9066f6cSSteven Rostedt
3576b9066f6cSSteven Rostedt    my $state = "NONE";
3577b9066f6cSSteven Rostedt    my $config;
3578b9066f6cSSteven Rostedt    my @kconfigs;
3579b9066f6cSSteven Rostedt
3580b9066f6cSSteven Rostedt    my $cont = 0;
3581b9066f6cSSteven Rostedt    my $line;
3582b9066f6cSSteven Rostedt
3583b9066f6cSSteven Rostedt
3584b9066f6cSSteven Rostedt    if (! -f $kconfig) {
3585b9066f6cSSteven Rostedt	doprint "file $kconfig does not exist, skipping\n";
3586b9066f6cSSteven Rostedt	return;
3587b9066f6cSSteven Rostedt    }
3588b9066f6cSSteven Rostedt
3589b9066f6cSSteven Rostedt    open(KIN, "$kconfig")
3590b9066f6cSSteven Rostedt	or die "Can't open $kconfig";
3591b9066f6cSSteven Rostedt    while (<KIN>) {
3592b9066f6cSSteven Rostedt	chomp;
3593b9066f6cSSteven Rostedt
3594b9066f6cSSteven Rostedt	# Make sure that lines ending with \ continue
3595b9066f6cSSteven Rostedt	if ($cont) {
3596b9066f6cSSteven Rostedt	    $_ = $line . " " . $_;
3597b9066f6cSSteven Rostedt	}
3598b9066f6cSSteven Rostedt
3599b9066f6cSSteven Rostedt	if (s/\\$//) {
3600b9066f6cSSteven Rostedt	    $cont = 1;
3601b9066f6cSSteven Rostedt	    $line = $_;
3602b9066f6cSSteven Rostedt	    next;
3603b9066f6cSSteven Rostedt	}
3604b9066f6cSSteven Rostedt
3605b9066f6cSSteven Rostedt	$cont = 0;
3606b9066f6cSSteven Rostedt
3607b9066f6cSSteven Rostedt	# collect any Kconfig sources
3608b9066f6cSSteven Rostedt	if (/^source\s*"(.*)"/) {
3609b9066f6cSSteven Rostedt	    $kconfigs[$#kconfigs+1] = $1;
3610b9066f6cSSteven Rostedt	}
3611b9066f6cSSteven Rostedt
3612b9066f6cSSteven Rostedt	# configs found
3613b9066f6cSSteven Rostedt	if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3614b9066f6cSSteven Rostedt	    $state = "NEW";
3615b9066f6cSSteven Rostedt	    $config = $2;
3616b9066f6cSSteven Rostedt
3617b9066f6cSSteven Rostedt	    for (my $i = 0; $i < $iflevel; $i++) {
3618ac6974c7SSteven Rostedt		add_dep $config, $ifdeps[$i];
3619b9066f6cSSteven Rostedt	    }
3620b9066f6cSSteven Rostedt
3621b9066f6cSSteven Rostedt	# collect the depends for the config
3622b9066f6cSSteven Rostedt	} elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3623b9066f6cSSteven Rostedt
3624ac6974c7SSteven Rostedt	    add_dep $config, $1;
3625b9066f6cSSteven Rostedt
3626b9066f6cSSteven Rostedt	# Get the configs that select this config
3627ac6974c7SSteven Rostedt	} elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3628ac6974c7SSteven Rostedt
3629ac6974c7SSteven Rostedt	    # selected by depends on config
3630ac6974c7SSteven Rostedt	    add_dep $1, $config;
3631b9066f6cSSteven Rostedt
3632b9066f6cSSteven Rostedt	# Check for if statements
3633b9066f6cSSteven Rostedt	} elsif (/^if\s+(.*\S)\s*$/) {
3634b9066f6cSSteven Rostedt	    my $deps = $1;
3635b9066f6cSSteven Rostedt	    # remove beginning and ending non text
3636b9066f6cSSteven Rostedt	    $deps =~ s/^[^a-zA-Z0-9_]*//;
3637b9066f6cSSteven Rostedt	    $deps =~ s/[^a-zA-Z0-9_]*$//;
3638b9066f6cSSteven Rostedt
3639b9066f6cSSteven Rostedt	    my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3640b9066f6cSSteven Rostedt
3641b9066f6cSSteven Rostedt	    $ifdeps[$iflevel++] = join ':', @deps;
3642b9066f6cSSteven Rostedt
3643b9066f6cSSteven Rostedt	} elsif (/^endif/) {
3644b9066f6cSSteven Rostedt
3645b9066f6cSSteven Rostedt	    $iflevel-- if ($iflevel);
3646b9066f6cSSteven Rostedt
3647b9066f6cSSteven Rostedt	# stop on "help"
3648b9066f6cSSteven Rostedt	} elsif (/^\s*help\s*$/) {
3649b9066f6cSSteven Rostedt	    $state = "NONE";
3650b9066f6cSSteven Rostedt	}
3651b9066f6cSSteven Rostedt    }
3652b9066f6cSSteven Rostedt    close(KIN);
3653b9066f6cSSteven Rostedt
3654b9066f6cSSteven Rostedt    # read in any configs that were found.
3655b9066f6cSSteven Rostedt    foreach $kconfig (@kconfigs) {
3656b9066f6cSSteven Rostedt	if (!defined($read_kconfigs{$kconfig})) {
3657b9066f6cSSteven Rostedt	    $read_kconfigs{$kconfig} = 1;
3658b9066f6cSSteven Rostedt	    read_kconfig("$builddir/$kconfig");
3659b9066f6cSSteven Rostedt	}
3660b9066f6cSSteven Rostedt    }
3661b9066f6cSSteven Rostedt}
3662b9066f6cSSteven Rostedt
3663b9066f6cSSteven Rostedtsub read_depends {
3664b9066f6cSSteven Rostedt    # find out which arch this is by the kconfig file
3665b9066f6cSSteven Rostedt    open (IN, $output_config)
3666b9066f6cSSteven Rostedt	or dodie "Failed to read $output_config";
3667b9066f6cSSteven Rostedt    my $arch;
3668b9066f6cSSteven Rostedt    while (<IN>) {
3669b9066f6cSSteven Rostedt	if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3670b9066f6cSSteven Rostedt	    $arch = $1;
3671b9066f6cSSteven Rostedt	    last;
3672b9066f6cSSteven Rostedt	}
3673b9066f6cSSteven Rostedt    }
3674b9066f6cSSteven Rostedt    close IN;
3675b9066f6cSSteven Rostedt
3676b9066f6cSSteven Rostedt    if (!defined($arch)) {
3677b9066f6cSSteven Rostedt	doprint "Could not find arch from config file\n";
3678b9066f6cSSteven Rostedt	doprint "no dependencies used\n";
3679b9066f6cSSteven Rostedt	return;
3680b9066f6cSSteven Rostedt    }
3681b9066f6cSSteven Rostedt
3682b9066f6cSSteven Rostedt    # arch is really the subarch, we need to know
3683b9066f6cSSteven Rostedt    # what directory to look at.
3684b9066f6cSSteven Rostedt    if ($arch eq "i386" || $arch eq "x86_64") {
3685b9066f6cSSteven Rostedt	$arch = "x86";
3686b9066f6cSSteven Rostedt    } elsif ($arch =~ /^tile/) {
3687b9066f6cSSteven Rostedt	$arch = "tile";
3688b9066f6cSSteven Rostedt    }
3689b9066f6cSSteven Rostedt
3690b9066f6cSSteven Rostedt    my $kconfig = "$builddir/arch/$arch/Kconfig";
3691b9066f6cSSteven Rostedt
3692b9066f6cSSteven Rostedt    if (! -f $kconfig && $arch =~ /\d$/) {
3693b9066f6cSSteven Rostedt	my $orig = $arch;
3694b9066f6cSSteven Rostedt 	# some subarchs have numbers, truncate them
3695b9066f6cSSteven Rostedt	$arch =~ s/\d*$//;
3696b9066f6cSSteven Rostedt	$kconfig = "$builddir/arch/$arch/Kconfig";
3697b9066f6cSSteven Rostedt	if (! -f $kconfig) {
3698b9066f6cSSteven Rostedt	    doprint "No idea what arch dir $orig is for\n";
3699b9066f6cSSteven Rostedt	    doprint "no dependencies used\n";
3700b9066f6cSSteven Rostedt	    return;
3701b9066f6cSSteven Rostedt	}
3702b9066f6cSSteven Rostedt    }
3703b9066f6cSSteven Rostedt
3704b9066f6cSSteven Rostedt    read_kconfig($kconfig);
3705b9066f6cSSteven Rostedt}
3706b9066f6cSSteven Rostedt
37074c4ab120SSteven Rostedtsub make_new_config {
37084c4ab120SSteven Rostedt    my @configs = @_;
37094c4ab120SSteven Rostedt
37104c4ab120SSteven Rostedt    open (OUT, ">$output_config")
37114c4ab120SSteven Rostedt	or dodie "Failed to write $output_config";
37124c4ab120SSteven Rostedt
37134c4ab120SSteven Rostedt    foreach my $config (@configs) {
37144c4ab120SSteven Rostedt	print OUT "$config\n";
37154c4ab120SSteven Rostedt    }
37164c4ab120SSteven Rostedt    close OUT;
37174c4ab120SSteven Rostedt}
37184c4ab120SSteven Rostedt
3719ac6974c7SSteven Rostedtsub chomp_config {
3720ac6974c7SSteven Rostedt    my ($config) = @_;
3721ac6974c7SSteven Rostedt
3722ac6974c7SSteven Rostedt    $config =~ s/CONFIG_//;
3723ac6974c7SSteven Rostedt
3724ac6974c7SSteven Rostedt    return $config;
3725ac6974c7SSteven Rostedt}
3726ac6974c7SSteven Rostedt
3727b9066f6cSSteven Rostedtsub get_depends {
3728b9066f6cSSteven Rostedt    my ($dep) = @_;
3729b9066f6cSSteven Rostedt
3730ac6974c7SSteven Rostedt    my $kconfig = chomp_config $dep;
3731b9066f6cSSteven Rostedt
3732b9066f6cSSteven Rostedt    $dep = $depends{"$kconfig"};
3733b9066f6cSSteven Rostedt
3734b9066f6cSSteven Rostedt    # the dep string we have saves the dependencies as they
3735b9066f6cSSteven Rostedt    # were found, including expressions like ! && ||. We
3736b9066f6cSSteven Rostedt    # want to split this out into just an array of configs.
3737b9066f6cSSteven Rostedt
3738b9066f6cSSteven Rostedt    my $valid = "A-Za-z_0-9";
3739b9066f6cSSteven Rostedt
3740b9066f6cSSteven Rostedt    my @configs;
3741b9066f6cSSteven Rostedt
3742b9066f6cSSteven Rostedt    while ($dep =~ /[$valid]/) {
3743b9066f6cSSteven Rostedt
3744b9066f6cSSteven Rostedt	if ($dep =~ /^[^$valid]*([$valid]+)/) {
3745b9066f6cSSteven Rostedt	    my $conf = "CONFIG_" . $1;
3746b9066f6cSSteven Rostedt
3747b9066f6cSSteven Rostedt	    $configs[$#configs + 1] = $conf;
3748b9066f6cSSteven Rostedt
3749b9066f6cSSteven Rostedt	    $dep =~ s/^[^$valid]*[$valid]+//;
3750b9066f6cSSteven Rostedt	} else {
3751b9066f6cSSteven Rostedt	    die "this should never happen";
3752b9066f6cSSteven Rostedt	}
3753b9066f6cSSteven Rostedt    }
3754b9066f6cSSteven Rostedt
3755b9066f6cSSteven Rostedt    return @configs;
3756b9066f6cSSteven Rostedt}
3757b9066f6cSSteven Rostedt
3758b9066f6cSSteven Rostedtmy %min_configs;
3759b9066f6cSSteven Rostedtmy %keep_configs;
376043d1b651SSteven Rostedtmy %save_configs;
3761b9066f6cSSteven Rostedtmy %processed_configs;
3762b9066f6cSSteven Rostedtmy %nochange_config;
3763b9066f6cSSteven Rostedt
3764b9066f6cSSteven Rostedtsub test_this_config {
3765b9066f6cSSteven Rostedt    my ($config) = @_;
3766b9066f6cSSteven Rostedt
3767b9066f6cSSteven Rostedt    my $found;
3768b9066f6cSSteven Rostedt
3769b9066f6cSSteven Rostedt    # if we already processed this config, skip it
3770b9066f6cSSteven Rostedt    if (defined($processed_configs{$config})) {
3771b9066f6cSSteven Rostedt	return undef;
3772b9066f6cSSteven Rostedt    }
3773b9066f6cSSteven Rostedt    $processed_configs{$config} = 1;
3774b9066f6cSSteven Rostedt
3775b9066f6cSSteven Rostedt    # if this config failed during this round, skip it
3776b9066f6cSSteven Rostedt    if (defined($nochange_config{$config})) {
3777b9066f6cSSteven Rostedt	return undef;
3778b9066f6cSSteven Rostedt    }
3779b9066f6cSSteven Rostedt
3780ac6974c7SSteven Rostedt    my $kconfig = chomp_config $config;
3781b9066f6cSSteven Rostedt
3782b9066f6cSSteven Rostedt    # Test dependencies first
3783b9066f6cSSteven Rostedt    if (defined($depends{"$kconfig"})) {
3784b9066f6cSSteven Rostedt	my @parents = get_depends $config;
3785b9066f6cSSteven Rostedt	foreach my $parent (@parents) {
3786b9066f6cSSteven Rostedt	    # if the parent is in the min config, check it first
3787b9066f6cSSteven Rostedt	    next if (!defined($min_configs{$parent}));
3788b9066f6cSSteven Rostedt	    $found = test_this_config($parent);
3789b9066f6cSSteven Rostedt	    if (defined($found)) {
3790b9066f6cSSteven Rostedt		return $found;
3791b9066f6cSSteven Rostedt	    }
3792b9066f6cSSteven Rostedt	}
3793b9066f6cSSteven Rostedt    }
3794b9066f6cSSteven Rostedt
3795b9066f6cSSteven Rostedt    # Remove this config from the list of configs
3796fb16d891SAdam Lee    # do a make olddefconfig and then read the resulting
3797b9066f6cSSteven Rostedt    # .config to make sure it is missing the config that
3798b9066f6cSSteven Rostedt    # we had before
3799b9066f6cSSteven Rostedt    my %configs = %min_configs;
3800b9066f6cSSteven Rostedt    delete $configs{$config};
3801b9066f6cSSteven Rostedt    make_new_config ((values %configs), (values %keep_configs));
3802b9066f6cSSteven Rostedt    make_oldconfig;
3803b9066f6cSSteven Rostedt    undef %configs;
3804b9066f6cSSteven Rostedt    assign_configs \%configs, $output_config;
3805b9066f6cSSteven Rostedt
38069972fc0bSSteven Rostedt (Red Hat)    if (!defined($configs{$config}) || $configs{$config} =~ /^#/) {
38079972fc0bSSteven Rostedt (Red Hat)	return $config;
38089972fc0bSSteven Rostedt (Red Hat)    }
3809b9066f6cSSteven Rostedt
3810b9066f6cSSteven Rostedt    doprint "disabling config $config did not change .config\n";
3811b9066f6cSSteven Rostedt
3812b9066f6cSSteven Rostedt    $nochange_config{$config} = 1;
3813b9066f6cSSteven Rostedt
3814b9066f6cSSteven Rostedt    return undef;
3815b9066f6cSSteven Rostedt}
3816b9066f6cSSteven Rostedt
38174c4ab120SSteven Rostedtsub make_min_config {
38184c4ab120SSteven Rostedt    my ($i) = @_;
38194c4ab120SSteven Rostedt
3820ccc513b6SSteven Rostedt    my $type = $minconfig_type;
3821ccc513b6SSteven Rostedt    if ($type ne "boot" && $type ne "test") {
3822ccc513b6SSteven Rostedt	fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3823ccc513b6SSteven Rostedt	    " make_min_config works only with 'boot' and 'test'\n" and return;
3824ccc513b6SSteven Rostedt    }
3825ccc513b6SSteven Rostedt
38264c4ab120SSteven Rostedt    if (!defined($output_minconfig)) {
38274c4ab120SSteven Rostedt	fail "OUTPUT_MIN_CONFIG not defined" and return;
38284c4ab120SSteven Rostedt    }
382935ce5952SSteven Rostedt
383035ce5952SSteven Rostedt    # If output_minconfig exists, and the start_minconfig
383135ce5952SSteven Rostedt    # came from min_config, than ask if we should use
383235ce5952SSteven Rostedt    # that instead.
383335ce5952SSteven Rostedt    if (-f $output_minconfig && !$start_minconfig_defined) {
383435ce5952SSteven Rostedt	print "$output_minconfig exists\n";
383543de3316SSteven Rostedt	if (!defined($use_output_minconfig)) {
383635ce5952SSteven Rostedt	    if (read_yn " Use it as minconfig?") {
383735ce5952SSteven Rostedt		$start_minconfig = $output_minconfig;
383835ce5952SSteven Rostedt	    }
383943de3316SSteven Rostedt	} elsif ($use_output_minconfig > 0) {
384043de3316SSteven Rostedt	    doprint "Using $output_minconfig as MIN_CONFIG\n";
384143de3316SSteven Rostedt	    $start_minconfig = $output_minconfig;
384243de3316SSteven Rostedt	} else {
384343de3316SSteven Rostedt	    doprint "Set to still use MIN_CONFIG as starting point\n";
384443de3316SSteven Rostedt	}
384535ce5952SSteven Rostedt    }
384635ce5952SSteven Rostedt
38474c4ab120SSteven Rostedt    if (!defined($start_minconfig)) {
38484c4ab120SSteven Rostedt	fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
38494c4ab120SSteven Rostedt    }
38504c4ab120SSteven Rostedt
385135ce5952SSteven Rostedt    my $temp_config = "$tmpdir/temp_config";
385235ce5952SSteven Rostedt
38534c4ab120SSteven Rostedt    # First things first. We build an allnoconfig to find
38544c4ab120SSteven Rostedt    # out what the defaults are that we can't touch.
38554c4ab120SSteven Rostedt    # Some are selections, but we really can't handle selections.
38564c4ab120SSteven Rostedt
38574c4ab120SSteven Rostedt    my $save_minconfig = $minconfig;
38584c4ab120SSteven Rostedt    undef $minconfig;
38594c4ab120SSteven Rostedt
38604c4ab120SSteven Rostedt    run_command "$make allnoconfig" or return 0;
38614c4ab120SSteven Rostedt
3862b9066f6cSSteven Rostedt    read_depends;
3863b9066f6cSSteven Rostedt
38644c4ab120SSteven Rostedt    process_config_ignore $output_config;
3865b9066f6cSSteven Rostedt
386643d1b651SSteven Rostedt    undef %save_configs;
3867b9066f6cSSteven Rostedt    undef %min_configs;
38684c4ab120SSteven Rostedt
38694c4ab120SSteven Rostedt    if (defined($ignore_config)) {
38704c4ab120SSteven Rostedt	# make sure the file exists
38714c4ab120SSteven Rostedt	`touch $ignore_config`;
387243d1b651SSteven Rostedt	assign_configs \%save_configs, $ignore_config;
38734c4ab120SSteven Rostedt    }
38744c4ab120SSteven Rostedt
387543d1b651SSteven Rostedt    %keep_configs = %save_configs;
387643d1b651SSteven Rostedt
38774c4ab120SSteven Rostedt    doprint "Load initial configs from $start_minconfig\n";
38784c4ab120SSteven Rostedt
38794c4ab120SSteven Rostedt    # Look at the current min configs, and save off all the
38804c4ab120SSteven Rostedt    # ones that were set via the allnoconfig
38814c4ab120SSteven Rostedt    assign_configs \%min_configs, $start_minconfig;
38824c4ab120SSteven Rostedt
38834c4ab120SSteven Rostedt    my @config_keys = keys %min_configs;
38844c4ab120SSteven Rostedt
3885ac6974c7SSteven Rostedt    # All configs need a depcount
3886ac6974c7SSteven Rostedt    foreach my $config (@config_keys) {
3887ac6974c7SSteven Rostedt	my $kconfig = chomp_config $config;
3888ac6974c7SSteven Rostedt	if (!defined $depcount{$kconfig}) {
3889ac6974c7SSteven Rostedt		$depcount{$kconfig} = 0;
3890ac6974c7SSteven Rostedt	}
3891ac6974c7SSteven Rostedt    }
3892ac6974c7SSteven Rostedt
38934c4ab120SSteven Rostedt    # Remove anything that was set by the make allnoconfig
38944c4ab120SSteven Rostedt    # we shouldn't need them as they get set for us anyway.
38954c4ab120SSteven Rostedt    foreach my $config (@config_keys) {
38964c4ab120SSteven Rostedt	# Remove anything in the ignore_config
38974c4ab120SSteven Rostedt	if (defined($keep_configs{$config})) {
38984c4ab120SSteven Rostedt	    my $file = $ignore_config;
38994c4ab120SSteven Rostedt	    $file =~ s,.*/(.*?)$,$1,;
39004c4ab120SSteven Rostedt	    doprint "$config set by $file ... ignored\n";
39014c4ab120SSteven Rostedt	    delete $min_configs{$config};
39024c4ab120SSteven Rostedt	    next;
39034c4ab120SSteven Rostedt	}
39044c4ab120SSteven Rostedt	# But make sure the settings are the same. If a min config
39054c4ab120SSteven Rostedt	# sets a selection, we do not want to get rid of it if
39064c4ab120SSteven Rostedt	# it is not the same as what we have. Just move it into
39074c4ab120SSteven Rostedt	# the keep configs.
39084c4ab120SSteven Rostedt	if (defined($config_ignore{$config})) {
39094c4ab120SSteven Rostedt	    if ($config_ignore{$config} ne $min_configs{$config}) {
39104c4ab120SSteven Rostedt		doprint "$config is in allnoconfig as '$config_ignore{$config}'";
39114c4ab120SSteven Rostedt		doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
39124c4ab120SSteven Rostedt		$keep_configs{$config} = $min_configs{$config};
39134c4ab120SSteven Rostedt	    } else {
39144c4ab120SSteven Rostedt		doprint "$config set by allnoconfig ... ignored\n";
39154c4ab120SSteven Rostedt	    }
39164c4ab120SSteven Rostedt	    delete $min_configs{$config};
39174c4ab120SSteven Rostedt	}
39184c4ab120SSteven Rostedt    }
39194c4ab120SSteven Rostedt
39204c4ab120SSteven Rostedt    my $done = 0;
3921b9066f6cSSteven Rostedt    my $take_two = 0;
39224c4ab120SSteven Rostedt
39234c4ab120SSteven Rostedt    while (!$done) {
39244c4ab120SSteven Rostedt
39254c4ab120SSteven Rostedt	my $config;
39264c4ab120SSteven Rostedt	my $found;
39274c4ab120SSteven Rostedt
39284c4ab120SSteven Rostedt	# Now disable each config one by one and do a make oldconfig
39294c4ab120SSteven Rostedt	# till we find a config that changes our list.
39304c4ab120SSteven Rostedt
39314c4ab120SSteven Rostedt	my @test_configs = keys %min_configs;
3932ac6974c7SSteven Rostedt
3933ac6974c7SSteven Rostedt	# Sort keys by who is most dependent on
3934ac6974c7SSteven Rostedt	@test_configs = sort  { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3935ac6974c7SSteven Rostedt			  @test_configs ;
3936ac6974c7SSteven Rostedt
3937ac6974c7SSteven Rostedt	# Put configs that did not modify the config at the end.
39384c4ab120SSteven Rostedt	my $reset = 1;
39394c4ab120SSteven Rostedt	for (my $i = 0; $i < $#test_configs; $i++) {
39404c4ab120SSteven Rostedt	    if (!defined($nochange_config{$test_configs[0]})) {
39414c4ab120SSteven Rostedt		$reset = 0;
39424c4ab120SSteven Rostedt		last;
39434c4ab120SSteven Rostedt	    }
39444c4ab120SSteven Rostedt	    # This config didn't change the .config last time.
39454c4ab120SSteven Rostedt	    # Place it at the end
39464c4ab120SSteven Rostedt	    my $config = shift @test_configs;
39474c4ab120SSteven Rostedt	    push @test_configs, $config;
39484c4ab120SSteven Rostedt	}
39494c4ab120SSteven Rostedt
39504c4ab120SSteven Rostedt	# if every test config has failed to modify the .config file
39514c4ab120SSteven Rostedt	# in the past, then reset and start over.
39524c4ab120SSteven Rostedt	if ($reset) {
39534c4ab120SSteven Rostedt	    undef %nochange_config;
39544c4ab120SSteven Rostedt	}
39554c4ab120SSteven Rostedt
3956b9066f6cSSteven Rostedt	undef %processed_configs;
3957b9066f6cSSteven Rostedt
39584c4ab120SSteven Rostedt	foreach my $config (@test_configs) {
39594c4ab120SSteven Rostedt
3960b9066f6cSSteven Rostedt	    $found = test_this_config $config;
39614c4ab120SSteven Rostedt
3962b9066f6cSSteven Rostedt	    last if (defined($found));
39634c4ab120SSteven Rostedt
39644c4ab120SSteven Rostedt	    # oh well, try another config
39654c4ab120SSteven Rostedt	}
39664c4ab120SSteven Rostedt
39674c4ab120SSteven Rostedt	if (!defined($found)) {
3968b9066f6cSSteven Rostedt	    # we could have failed due to the nochange_config hash
3969b9066f6cSSteven Rostedt	    # reset and try again
3970b9066f6cSSteven Rostedt	    if (!$take_two) {
3971b9066f6cSSteven Rostedt		undef %nochange_config;
3972b9066f6cSSteven Rostedt		$take_two = 1;
3973b9066f6cSSteven Rostedt		next;
3974b9066f6cSSteven Rostedt	    }
39754c4ab120SSteven Rostedt	    doprint "No more configs found that we can disable\n";
39764c4ab120SSteven Rostedt	    $done = 1;
39774c4ab120SSteven Rostedt	    last;
39784c4ab120SSteven Rostedt	}
3979b9066f6cSSteven Rostedt	$take_two = 0;
39804c4ab120SSteven Rostedt
39814c4ab120SSteven Rostedt	$config = $found;
39824c4ab120SSteven Rostedt
39834c4ab120SSteven Rostedt	doprint "Test with $config disabled\n";
39844c4ab120SSteven Rostedt
39854c4ab120SSteven Rostedt	# set in_bisect to keep build and monitor from dieing
39864c4ab120SSteven Rostedt	$in_bisect = 1;
39874c4ab120SSteven Rostedt
39884c4ab120SSteven Rostedt	my $failed = 0;
3989bf1c95abSSteven Rostedt	build "oldconfig" or $failed = 1;
3990bf1c95abSSteven Rostedt	if (!$failed) {
399164d98283SSteven Rostedt (Red Hat)		start_monitor_and_install or $failed = 1;
3992ccc513b6SSteven Rostedt
3993ccc513b6SSteven Rostedt		if ($type eq "test" && !$failed) {
3994ccc513b6SSteven Rostedt		    do_run_test or $failed = 1;
3995ccc513b6SSteven Rostedt		}
3996ccc513b6SSteven Rostedt
39974c4ab120SSteven Rostedt		end_monitor;
3998bf1c95abSSteven Rostedt	}
39994c4ab120SSteven Rostedt
40004c4ab120SSteven Rostedt	$in_bisect = 0;
40014c4ab120SSteven Rostedt
40024c4ab120SSteven Rostedt	if ($failed) {
4003b9066f6cSSteven Rostedt	    doprint "$min_configs{$config} is needed to boot the box... keeping\n";
40044c4ab120SSteven Rostedt	    # this config is needed, add it to the ignore list.
40054c4ab120SSteven Rostedt	    $keep_configs{$config} = $min_configs{$config};
400643d1b651SSteven Rostedt	    $save_configs{$config} = $min_configs{$config};
40074c4ab120SSteven Rostedt	    delete $min_configs{$config};
400835ce5952SSteven Rostedt
400935ce5952SSteven Rostedt	    # update new ignore configs
401035ce5952SSteven Rostedt	    if (defined($ignore_config)) {
401135ce5952SSteven Rostedt		open (OUT, ">$temp_config")
401235ce5952SSteven Rostedt		    or die "Can't write to $temp_config";
401343d1b651SSteven Rostedt		foreach my $config (keys %save_configs) {
401443d1b651SSteven Rostedt		    print OUT "$save_configs{$config}\n";
401535ce5952SSteven Rostedt		}
401635ce5952SSteven Rostedt		close OUT;
401735ce5952SSteven Rostedt		run_command "mv $temp_config $ignore_config" or
401835ce5952SSteven Rostedt		    dodie "failed to copy update to $ignore_config";
401935ce5952SSteven Rostedt	    }
402035ce5952SSteven Rostedt
40214c4ab120SSteven Rostedt	} else {
40224c4ab120SSteven Rostedt	    # We booted without this config, remove it from the minconfigs.
40234c4ab120SSteven Rostedt	    doprint "$config is not needed, disabling\n";
40244c4ab120SSteven Rostedt
40254c4ab120SSteven Rostedt	    delete $min_configs{$config};
40264c4ab120SSteven Rostedt
40274c4ab120SSteven Rostedt	    # Also disable anything that is not enabled in this config
40284c4ab120SSteven Rostedt	    my %configs;
40294c4ab120SSteven Rostedt	    assign_configs \%configs, $output_config;
40304c4ab120SSteven Rostedt	    my @config_keys = keys %min_configs;
40314c4ab120SSteven Rostedt	    foreach my $config (@config_keys) {
40324c4ab120SSteven Rostedt		if (!defined($configs{$config})) {
40334c4ab120SSteven Rostedt		    doprint "$config is not set, disabling\n";
40344c4ab120SSteven Rostedt		    delete $min_configs{$config};
40354c4ab120SSteven Rostedt		}
40364c4ab120SSteven Rostedt	    }
40374c4ab120SSteven Rostedt
40384c4ab120SSteven Rostedt	    # Save off all the current mandidory configs
403935ce5952SSteven Rostedt	    open (OUT, ">$temp_config")
404035ce5952SSteven Rostedt		or die "Can't write to $temp_config";
40414c4ab120SSteven Rostedt	    foreach my $config (keys %keep_configs) {
40424c4ab120SSteven Rostedt		print OUT "$keep_configs{$config}\n";
40434c4ab120SSteven Rostedt	    }
40444c4ab120SSteven Rostedt	    foreach my $config (keys %min_configs) {
40454c4ab120SSteven Rostedt		print OUT "$min_configs{$config}\n";
40464c4ab120SSteven Rostedt	    }
40474c4ab120SSteven Rostedt	    close OUT;
404835ce5952SSteven Rostedt
404935ce5952SSteven Rostedt	    run_command "mv $temp_config $output_minconfig" or
405035ce5952SSteven Rostedt		dodie "failed to copy update to $output_minconfig";
40514c4ab120SSteven Rostedt	}
40524c4ab120SSteven Rostedt
40534c4ab120SSteven Rostedt	doprint "Reboot and wait $sleep_time seconds\n";
4054bc7c5803SSteven Rostedt	reboot_to_good $sleep_time;
40554c4ab120SSteven Rostedt    }
40564c4ab120SSteven Rostedt
40574c4ab120SSteven Rostedt    success $i;
40584c4ab120SSteven Rostedt    return 1;
40594c4ab120SSteven Rostedt}
40604c4ab120SSteven Rostedt
40614283b169SSteven Rostedt (Red Hat)sub make_warnings_file {
40624283b169SSteven Rostedt (Red Hat)    my ($i) = @_;
40634283b169SSteven Rostedt (Red Hat)
40644283b169SSteven Rostedt (Red Hat)    if (!defined($warnings_file)) {
40654283b169SSteven Rostedt (Red Hat)	dodie "Must define WARNINGS_FILE for make_warnings_file test";
40664283b169SSteven Rostedt (Red Hat)    }
40674283b169SSteven Rostedt (Red Hat)
40684283b169SSteven Rostedt (Red Hat)    if ($build_type eq "nobuild") {
40694283b169SSteven Rostedt (Red Hat)	dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
40704283b169SSteven Rostedt (Red Hat)    }
40714283b169SSteven Rostedt (Red Hat)
40724283b169SSteven Rostedt (Red Hat)    build $build_type or dodie "Failed to build";
40734283b169SSteven Rostedt (Red Hat)
40744283b169SSteven Rostedt (Red Hat)    open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
40754283b169SSteven Rostedt (Red Hat)
40764283b169SSteven Rostedt (Red Hat)    open(IN, $buildlog) or dodie "Can't open $buildlog";
40774283b169SSteven Rostedt (Red Hat)    while (<IN>) {
40784283b169SSteven Rostedt (Red Hat)
40794283b169SSteven Rostedt (Red Hat)	# Some compilers use UTF-8 extended for quotes
40804283b169SSteven Rostedt (Red Hat)	# for distcc heterogeneous systems, this causes issues
40814283b169SSteven Rostedt (Red Hat)	s/$utf8_quote/'/g;
40824283b169SSteven Rostedt (Red Hat)
40834283b169SSteven Rostedt (Red Hat)	if (/$check_build_re/) {
40844283b169SSteven Rostedt (Red Hat)	    print OUT;
40854283b169SSteven Rostedt (Red Hat)	}
40864283b169SSteven Rostedt (Red Hat)    }
40874283b169SSteven Rostedt (Red Hat)    close(IN);
40884283b169SSteven Rostedt (Red Hat)
40894283b169SSteven Rostedt (Red Hat)    close(OUT);
40904283b169SSteven Rostedt (Red Hat)
40914283b169SSteven Rostedt (Red Hat)    success $i;
40924283b169SSteven Rostedt (Red Hat)}
40934283b169SSteven Rostedt (Red Hat)
40945269faadSSatoru Takeuchi$#ARGV < 1 or die "ktest.pl version: $VERSION\n   usage: ktest.pl [config-file]\n";
40952545eb61SSteven Rostedt
40968d1491baSSteven Rostedtif ($#ARGV == 0) {
40978d1491baSSteven Rostedt    $ktest_config = $ARGV[0];
40988d1491baSSteven Rostedt    if (! -f $ktest_config) {
40998d1491baSSteven Rostedt	print "$ktest_config does not exist.\n";
410035ce5952SSteven Rostedt	if (!read_yn "Create it?") {
41018d1491baSSteven Rostedt	    exit 0;
41028d1491baSSteven Rostedt	}
41038d1491baSSteven Rostedt    }
41048d1491baSSteven Rostedt}
41058d1491baSSteven Rostedt
41068d1491baSSteven Rostedtif (! -f $ktest_config) {
4107dbd3783bSSteven Rostedt    $newconfig = 1;
4108c4261d0fSSteven Rostedt    get_test_case;
41098d1491baSSteven Rostedt    open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
41108d1491baSSteven Rostedt    print OUT << "EOF"
41118d1491baSSteven Rostedt# Generated by ktest.pl
41128d1491baSSteven Rostedt#
41130e7a22deSSteven Rostedt
41140e7a22deSSteven Rostedt# PWD is a ktest.pl variable that will result in the process working
41150e7a22deSSteven Rostedt# directory that ktest.pl is executed in.
41160e7a22deSSteven Rostedt
41170e7a22deSSteven Rostedt# THIS_DIR is automatically assigned the PWD of the path that generated
41180e7a22deSSteven Rostedt# the config file. It is best to use this variable when assigning other
41190e7a22deSSteven Rostedt# directory paths within this directory. This allows you to easily
41200e7a22deSSteven Rostedt# move the test cases to other locations or to other machines.
41210e7a22deSSteven Rostedt#
41220e7a22deSSteven RostedtTHIS_DIR := $variable{"PWD"}
41230e7a22deSSteven Rostedt
41248d1491baSSteven Rostedt# Define each test with TEST_START
41258d1491baSSteven Rostedt# The config options below it will override the defaults
41268d1491baSSteven RostedtTEST_START
4127c4261d0fSSteven RostedtTEST_TYPE = $default{"TEST_TYPE"}
41288d1491baSSteven Rostedt
41298d1491baSSteven RostedtDEFAULTS
41308d1491baSSteven RostedtEOF
41318d1491baSSteven Rostedt;
41328d1491baSSteven Rostedt    close(OUT);
41338d1491baSSteven Rostedt}
41348d1491baSSteven Rostedtread_config $ktest_config;
41358d1491baSSteven Rostedt
413623715c3cSSteven Rostedtif (defined($opt{"LOG_FILE"})) {
413704262be3SSteven Rostedt (Red Hat)    $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
413823715c3cSSteven Rostedt}
413923715c3cSSteven Rostedt
41408d1491baSSteven Rostedt# Append any configs entered in manually to the config file.
41418d1491baSSteven Rostedtmy @new_configs = keys %entered_configs;
41428d1491baSSteven Rostedtif ($#new_configs >= 0) {
41438d1491baSSteven Rostedt    print "\nAppending entered in configs to $ktest_config\n";
41448d1491baSSteven Rostedt    open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
41458d1491baSSteven Rostedt    foreach my $config (@new_configs) {
41468d1491baSSteven Rostedt	print OUT "$config = $entered_configs{$config}\n";
41470e7a22deSSteven Rostedt	$opt{$config} = process_variables($entered_configs{$config});
41488d1491baSSteven Rostedt    }
41498d1491baSSteven Rostedt}
41502545eb61SSteven Rostedt
41512b7d9b21SSteven Rostedtif ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
41522b7d9b21SSteven Rostedt    unlink $opt{"LOG_FILE"};
41532b7d9b21SSteven Rostedt}
41542545eb61SSteven Rostedt
41552b7d9b21SSteven Rostedtdoprint "\n\nSTARTING AUTOMATED TESTS\n\n";
41562b7d9b21SSteven Rostedt
4157a57419b3SSteven Rostedtfor (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
4158a57419b3SSteven Rostedt
4159a57419b3SSteven Rostedt    if (!$i) {
4160a57419b3SSteven Rostedt	doprint "DEFAULT OPTIONS:\n";
4161a57419b3SSteven Rostedt    } else {
4162a57419b3SSteven Rostedt	doprint "\nTEST $i OPTIONS";
4163a57419b3SSteven Rostedt	if (defined($repeat_tests{$i})) {
4164a57419b3SSteven Rostedt	    $repeat = $repeat_tests{$i};
4165a57419b3SSteven Rostedt	    doprint " ITERATE $repeat";
4166a57419b3SSteven Rostedt	}
4167a57419b3SSteven Rostedt	doprint "\n";
4168a57419b3SSteven Rostedt    }
4169a57419b3SSteven Rostedt
41702b7d9b21SSteven Rostedt    foreach my $option (sort keys %opt) {
4171a57419b3SSteven Rostedt
4172a57419b3SSteven Rostedt	if ($option =~ /\[(\d+)\]$/) {
4173a57419b3SSteven Rostedt	    next if ($i != $1);
4174a57419b3SSteven Rostedt	} else {
4175a57419b3SSteven Rostedt	    next if ($i);
4176a57419b3SSteven Rostedt	}
4177a57419b3SSteven Rostedt
41782b7d9b21SSteven Rostedt	doprint "$option = $opt{$option}\n";
41792b7d9b21SSteven Rostedt    }
4180a57419b3SSteven Rostedt}
41812545eb61SSteven Rostedt
418222c37a9aSSteven Rostedt (Red Hat)sub option_defined {
418322c37a9aSSteven Rostedt (Red Hat)    my ($option) = @_;
418422c37a9aSSteven Rostedt (Red Hat)
418522c37a9aSSteven Rostedt (Red Hat)    if (defined($opt{$option}) && $opt{$option} !~ /^\s*$/) {
418622c37a9aSSteven Rostedt (Red Hat)	return 1;
418722c37a9aSSteven Rostedt (Red Hat)    }
418822c37a9aSSteven Rostedt (Red Hat)
418922c37a9aSSteven Rostedt (Red Hat)    return 0;
419022c37a9aSSteven Rostedt (Red Hat)}
419122c37a9aSSteven Rostedt (Red Hat)
41922a62512bSSteven Rostedtsub __set_test_option {
41935a391fbfSSteven Rostedt    my ($name, $i) = @_;
41945a391fbfSSteven Rostedt
41955a391fbfSSteven Rostedt    my $option = "$name\[$i\]";
41965a391fbfSSteven Rostedt
419722c37a9aSSteven Rostedt (Red Hat)    if (option_defined($option)) {
41985a391fbfSSteven Rostedt	return $opt{$option};
41995a391fbfSSteven Rostedt    }
42005a391fbfSSteven Rostedt
4201a57419b3SSteven Rostedt    foreach my $test (keys %repeat_tests) {
4202a57419b3SSteven Rostedt	if ($i >= $test &&
4203a57419b3SSteven Rostedt	    $i < $test + $repeat_tests{$test}) {
4204a57419b3SSteven Rostedt	    $option = "$name\[$test\]";
420522c37a9aSSteven Rostedt (Red Hat)	    if (option_defined($option)) {
4206a57419b3SSteven Rostedt		return $opt{$option};
4207a57419b3SSteven Rostedt	    }
4208a57419b3SSteven Rostedt	}
4209a57419b3SSteven Rostedt    }
4210a57419b3SSteven Rostedt
421122c37a9aSSteven Rostedt (Red Hat)    if (option_defined($name)) {
42125a391fbfSSteven Rostedt	return $opt{$name};
42135a391fbfSSteven Rostedt    }
42145a391fbfSSteven Rostedt
42155a391fbfSSteven Rostedt    return undef;
42165a391fbfSSteven Rostedt}
42175a391fbfSSteven Rostedt
42182a62512bSSteven Rostedtsub set_test_option {
42192a62512bSSteven Rostedt    my ($name, $i) = @_;
42202a62512bSSteven Rostedt
42212a62512bSSteven Rostedt    my $option = __set_test_option($name, $i);
42222a62512bSSteven Rostedt    return $option if (!defined($option));
42232a62512bSSteven Rostedt
422404262be3SSteven Rostedt (Red Hat)    return eval_option($name, $option, $i);
42252a62512bSSteven Rostedt}
42262a62512bSSteven Rostedt
42272545eb61SSteven Rostedt# First we need to do is the builds
4228a75fececSSteven Rostedtfor (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
42292545eb61SSteven Rostedt
42304ab1cce5SSteven Rostedt    # Do not reboot on failing test options
42314ab1cce5SSteven Rostedt    $no_reboot = 1;
4232759a3cc6SSteven Rostedt    $reboot_success = 0;
42334ab1cce5SSteven Rostedt
4234683a3e64SSteven Rostedt    $have_version = 0;
4235683a3e64SSteven Rostedt
4236576f627cSSteven Rostedt    $iteration = $i;
4237576f627cSSteven Rostedt
423838fa3dc1SSteven Rostedt (Red Hat)    $build_time = 0;
423938fa3dc1SSteven Rostedt (Red Hat)    $install_time = 0;
424038fa3dc1SSteven Rostedt (Red Hat)    $reboot_time = 0;
424138fa3dc1SSteven Rostedt (Red Hat)    $test_time = 0;
424238fa3dc1SSteven Rostedt (Red Hat)
4243c1434dccSSteven Rostedt    undef %force_config;
4244c1434dccSSteven Rostedt
4245a75fececSSteven Rostedt    my $makecmd = set_test_option("MAKE_CMD", $i);
4246a75fececSSteven Rostedt
42478e80bf05SSteven Rostedt (Red Hat)    $outputdir = set_test_option("OUTPUT_DIR", $i);
42488e80bf05SSteven Rostedt (Red Hat)    $builddir = set_test_option("BUILD_DIR", $i);
42498e80bf05SSteven Rostedt (Red Hat)
42508e80bf05SSteven Rostedt (Red Hat)    chdir $builddir || die "can't change directory to $builddir";
42518e80bf05SSteven Rostedt (Red Hat)
42528e80bf05SSteven Rostedt (Red Hat)    if (!-d $outputdir) {
42538e80bf05SSteven Rostedt (Red Hat)	mkpath($outputdir) or
42548e80bf05SSteven Rostedt (Red Hat)	    die "can't create $outputdir";
42558e80bf05SSteven Rostedt (Red Hat)    }
42568e80bf05SSteven Rostedt (Red Hat)
42578e80bf05SSteven Rostedt (Red Hat)    $make = "$makecmd O=$outputdir";
42588e80bf05SSteven Rostedt (Red Hat)
42599cc9e091SSteven Rostedt    # Load all the options into their mapped variable names
42609cc9e091SSteven Rostedt    foreach my $opt (keys %option_map) {
42619cc9e091SSteven Rostedt	${$option_map{$opt}} = set_test_option($opt, $i);
42629cc9e091SSteven Rostedt    }
4263b5f4aea6SSteven Rostedt
426435ce5952SSteven Rostedt    $start_minconfig_defined = 1;
426535ce5952SSteven Rostedt
4266921ed4c7SSteven Rostedt    # The first test may override the PRE_KTEST option
4267921ed4c7SSteven Rostedt    if (defined($pre_ktest) && $i == 1) {
4268921ed4c7SSteven Rostedt	doprint "\n";
4269921ed4c7SSteven Rostedt	run_command $pre_ktest;
4270921ed4c7SSteven Rostedt    }
4271921ed4c7SSteven Rostedt
4272921ed4c7SSteven Rostedt    # Any test can override the POST_KTEST option
4273921ed4c7SSteven Rostedt    # The last test takes precedence.
4274921ed4c7SSteven Rostedt    if (defined($post_ktest)) {
4275921ed4c7SSteven Rostedt	$final_post_ktest = $post_ktest;
4276921ed4c7SSteven Rostedt    }
4277921ed4c7SSteven Rostedt
42784c4ab120SSteven Rostedt    if (!defined($start_minconfig)) {
427935ce5952SSteven Rostedt	$start_minconfig_defined = 0;
42804c4ab120SSteven Rostedt	$start_minconfig = $minconfig;
42814c4ab120SSteven Rostedt    }
42824c4ab120SSteven Rostedt
42838e80bf05SSteven Rostedt (Red Hat)    if (!-d $tmpdir) {
42848e80bf05SSteven Rostedt (Red Hat)	mkpath($tmpdir) or
42858e80bf05SSteven Rostedt (Red Hat)	    die "can't create $tmpdir";
4286a75fececSSteven Rostedt    }
4287a75fececSSteven Rostedt
4288e48c5293SSteven Rostedt    $ENV{"SSH_USER"} = $ssh_user;
4289e48c5293SSteven Rostedt    $ENV{"MACHINE"} = $machine;
4290e48c5293SSteven Rostedt
4291a75fececSSteven Rostedt    $buildlog = "$tmpdir/buildlog-$machine";
4292a9dd5d63SRabin Vincent    $testlog = "$tmpdir/testlog-$machine";
4293a75fececSSteven Rostedt    $dmesg = "$tmpdir/dmesg-$machine";
429451ad1dd1SSteven Rostedt    $output_config = "$outputdir/.config";
4295a75fececSSteven Rostedt
4296bb8474b1SSteven Rostedt    if (!$buildonly) {
4297bb8474b1SSteven Rostedt	$target = "$ssh_user\@$machine";
4298a75fececSSteven Rostedt	if ($reboot_type eq "grub") {
4299576f627cSSteven Rostedt	    dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4300a15ba913SSteven Rostedt	} elsif ($reboot_type eq "grub2") {
4301a15ba913SSteven Rostedt	    dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4302a15ba913SSteven Rostedt	    dodie "GRUB_FILE not defined" if (!defined($grub_file));
43037786954cSSteven Rostedt	} elsif ($reboot_type eq "syslinux") {
43047786954cSSteven Rostedt	    dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
4305a75fececSSteven Rostedt	}
4306bb8474b1SSteven Rostedt    }
4307a75fececSSteven Rostedt
4308a75fececSSteven Rostedt    my $run_type = $build_type;
4309a75fececSSteven Rostedt    if ($test_type eq "patchcheck") {
4310b5f4aea6SSteven Rostedt	$run_type = $patchcheck_type;
4311a75fececSSteven Rostedt    } elsif ($test_type eq "bisect") {
4312b5f4aea6SSteven Rostedt	$run_type = $bisect_type;
43130a05c769SSteven Rostedt    } elsif ($test_type eq "config_bisect") {
4314b5f4aea6SSteven Rostedt	$run_type = $config_bisect_type;
43154283b169SSteven Rostedt (Red Hat)    } elsif ($test_type eq "make_min_config") {
43164283b169SSteven Rostedt (Red Hat)	$run_type = "";
43174283b169SSteven Rostedt (Red Hat)    } elsif ($test_type eq "make_warnings_file") {
43184c4ab120SSteven Rostedt	$run_type = "";
43194c4ab120SSteven Rostedt    }
43204c4ab120SSteven Rostedt
4321a75fececSSteven Rostedt    # mistake in config file?
4322a75fececSSteven Rostedt    if (!defined($run_type)) {
4323a75fececSSteven Rostedt	$run_type = "ERROR";
4324a75fececSSteven Rostedt    }
43252545eb61SSteven Rostedt
4326e0a8742eSSteven Rostedt    my $installme = "";
4327e0a8742eSSteven Rostedt    $installme = " no_install" if ($no_install);
4328e0a8742eSSteven Rostedt
432918656c70SSteven Rostedt (Red Hat)    my $name = "";
433018656c70SSteven Rostedt (Red Hat)
433118656c70SSteven Rostedt (Red Hat)    if (defined($test_name)) {
433218656c70SSteven Rostedt (Red Hat)	$name = " ($test_name)";
433318656c70SSteven Rostedt (Red Hat)    }
433418656c70SSteven Rostedt (Red Hat)
43352545eb61SSteven Rostedt    doprint "\n\n";
433618656c70SSteven Rostedt (Red Hat)    doprint "RUNNING TEST $i of $opt{NUM_TESTS}$name with option $test_type $run_type$installme\n\n";
43377faafbd6SSteven Rostedt
4338921ed4c7SSteven Rostedt    if (defined($pre_test)) {
4339921ed4c7SSteven Rostedt	run_command $pre_test;
4340921ed4c7SSteven Rostedt    }
4341921ed4c7SSteven Rostedt
43427faafbd6SSteven Rostedt    unlink $dmesg;
43437faafbd6SSteven Rostedt    unlink $buildlog;
4344a9dd5d63SRabin Vincent    unlink $testlog;
43452545eb61SSteven Rostedt
4346250bae8bSSteven Rostedt    if (defined($addconfig)) {
4347250bae8bSSteven Rostedt	my $min = $minconfig;
43482b7d9b21SSteven Rostedt	if (!defined($minconfig)) {
4349250bae8bSSteven Rostedt	    $min = "";
4350250bae8bSSteven Rostedt	}
4351250bae8bSSteven Rostedt	run_command "cat $addconfig $min > $tmpdir/add_config" or
43522b7d9b21SSteven Rostedt	    dodie "Failed to create temp config";
43539be2e6b5SSteven Rostedt	$minconfig = "$tmpdir/add_config";
43542b7d9b21SSteven Rostedt    }
43552b7d9b21SSteven Rostedt
43566c5ee0beSSteven Rostedt    if (defined($checkout)) {
43576c5ee0beSSteven Rostedt	run_command "git checkout $checkout" or
43586c5ee0beSSteven Rostedt	    die "failed to checkout $checkout";
43596c5ee0beSSteven Rostedt    }
43606c5ee0beSSteven Rostedt
4361759a3cc6SSteven Rostedt    $no_reboot = 0;
4362759a3cc6SSteven Rostedt
4363648a182cSSteven Rostedt    # A test may opt to not reboot the box
4364648a182cSSteven Rostedt    if ($reboot_on_success) {
4365759a3cc6SSteven Rostedt	$reboot_success = 1;
4366648a182cSSteven Rostedt    }
43674ab1cce5SSteven Rostedt
4368a75fececSSteven Rostedt    if ($test_type eq "bisect") {
43695f9b6cedSSteven Rostedt	bisect $i;
43705f9b6cedSSteven Rostedt	next;
43710a05c769SSteven Rostedt    } elsif ($test_type eq "config_bisect") {
43720a05c769SSteven Rostedt	config_bisect $i;
43730a05c769SSteven Rostedt	next;
4374a75fececSSteven Rostedt    } elsif ($test_type eq "patchcheck") {
43756c5ee0beSSteven Rostedt	patchcheck $i;
43766c5ee0beSSteven Rostedt	next;
43774c4ab120SSteven Rostedt    } elsif ($test_type eq "make_min_config") {
43784c4ab120SSteven Rostedt	make_min_config $i;
43794c4ab120SSteven Rostedt	next;
43804283b169SSteven Rostedt (Red Hat)    } elsif ($test_type eq "make_warnings_file") {
43814283b169SSteven Rostedt (Red Hat)	$no_reboot = 1;
43824283b169SSteven Rostedt (Red Hat)	make_warnings_file $i;
43834283b169SSteven Rostedt (Red Hat)	next;
43845f9b6cedSSteven Rostedt    }
43855f9b6cedSSteven Rostedt
43867faafbd6SSteven Rostedt    if ($build_type ne "nobuild") {
43877faafbd6SSteven Rostedt	build $build_type or next;
43884283b169SSteven Rostedt (Red Hat)	check_buildlog or next;
43892545eb61SSteven Rostedt    }
43902545eb61SSteven Rostedt
4391cd8e368fSSteven Rostedt    if ($test_type eq "install") {
4392cd8e368fSSteven Rostedt	get_version;
4393cd8e368fSSteven Rostedt	install;
4394cd8e368fSSteven Rostedt	success $i;
4395cd8e368fSSteven Rostedt	next;
4396cd8e368fSSteven Rostedt    }
4397cd8e368fSSteven Rostedt
4398a75fececSSteven Rostedt    if ($test_type ne "build") {
43997faafbd6SSteven Rostedt	my $failed = 0;
440064d98283SSteven Rostedt (Red Hat)	start_monitor_and_install or $failed = 1;
4401a75fececSSteven Rostedt
4402a75fececSSteven Rostedt	if (!$failed && $test_type ne "boot" && defined($run_test)) {
44037faafbd6SSteven Rostedt	    do_run_test or $failed = 1;
44045a391fbfSSteven Rostedt	}
44057faafbd6SSteven Rostedt	end_monitor;
440638fa3dc1SSteven Rostedt (Red Hat)	if ($failed) {
440738fa3dc1SSteven Rostedt (Red Hat)	    print_times;
440838fa3dc1SSteven Rostedt (Red Hat)	    next;
4409a75fececSSteven Rostedt	}
441038fa3dc1SSteven Rostedt (Red Hat)    }
441138fa3dc1SSteven Rostedt (Red Hat)
441238fa3dc1SSteven Rostedt (Red Hat)    print_times;
44135a391fbfSSteven Rostedt
44145f9b6cedSSteven Rostedt    success $i;
441575c3fda7SSteven Rostedt}
44162545eb61SSteven Rostedt
4417921ed4c7SSteven Rostedtif (defined($final_post_ktest)) {
4418921ed4c7SSteven Rostedt    run_command $final_post_ktest;
4419921ed4c7SSteven Rostedt}
4420921ed4c7SSteven Rostedt
44215c42fc5bSSteven Rostedtif ($opt{"POWEROFF_ON_SUCCESS"}) {
442275c3fda7SSteven Rostedt    halt;
4423759a3cc6SSteven Rostedt} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
4424bc7c5803SSteven Rostedt    reboot_to_good;
4425648a182cSSteven Rostedt} elsif (defined($switch_to_good)) {
4426648a182cSSteven Rostedt    # still need to get to the good kernel
4427648a182cSSteven Rostedt    run_command $switch_to_good;
44285c42fc5bSSteven Rostedt}
442975c3fda7SSteven Rostedt
4430648a182cSSteven Rostedt
4431e48c5293SSteven Rostedtdoprint "\n    $successes of $opt{NUM_TESTS} tests were successful\n\n";
4432e48c5293SSteven Rostedt
44332545eb61SSteven Rostedtexit 0;
4434