xref: /openbmc/linux/tools/testing/ktest/ktest.pl (revision 1cb9e64298e9af6b6a8962d43abefdf0b8a635f9)
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;
1822545eb61SSteven Rostedt
183b5f4aea6SSteven Rostedtmy $bisect_good;
184b5f4aea6SSteven Rostedtmy $bisect_bad;
185b5f4aea6SSteven Rostedtmy $bisect_type;
186b5f4aea6SSteven Rostedtmy $bisect_start;
187b5f4aea6SSteven Rostedtmy $bisect_replay;
188b5f4aea6SSteven Rostedtmy $bisect_files;
189b5f4aea6SSteven Rostedtmy $bisect_reverse;
190b5f4aea6SSteven Rostedtmy $bisect_check;
191b5f4aea6SSteven Rostedt
192b5f4aea6SSteven Rostedtmy $config_bisect;
193b5f4aea6SSteven Rostedtmy $config_bisect_type;
194b0918612SSteven Rostedtmy $config_bisect_check;
195b5f4aea6SSteven Rostedt
196b5f4aea6SSteven Rostedtmy $patchcheck_type;
197b5f4aea6SSteven Rostedtmy $patchcheck_start;
19823a0e161SSteven Rostedt (Red Hat)my $patchcheck_cherry;
199b5f4aea6SSteven Rostedtmy $patchcheck_end;
200b5f4aea6SSteven Rostedt
20138fa3dc1SSteven Rostedt (Red Hat)my $build_time;
20238fa3dc1SSteven Rostedt (Red Hat)my $install_time;
20338fa3dc1SSteven Rostedt (Red Hat)my $reboot_time;
20438fa3dc1SSteven Rostedt (Red Hat)my $test_time;
20538fa3dc1SSteven Rostedt (Red Hat)
206165708b2SSteven Rostedt# set when a test is something other that just building or install
207bb8474b1SSteven Rostedt# which would require more options.
208bb8474b1SSteven Rostedtmy $buildonly = 1;
209bb8474b1SSteven Rostedt
2104283b169SSteven Rostedt (Red Hat)# tell build not to worry about warnings, even when WARNINGS_FILE is set
2114283b169SSteven Rostedt (Red Hat)my $warnings_ok = 0;
2124283b169SSteven Rostedt (Red Hat)
213dbd3783bSSteven Rostedt# set when creating a new config
214dbd3783bSSteven Rostedtmy $newconfig = 0;
215dbd3783bSSteven Rostedt
2168d1491baSSteven Rostedtmy %entered_configs;
2178d1491baSSteven Rostedtmy %config_help;
21877d942ceSSteven Rostedtmy %variable;
219cf79fab6SSteven Rostedt
220cf79fab6SSteven Rostedt# force_config is the list of configs that we force enabled (or disabled)
221cf79fab6SSteven Rostedt# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
222fcb3f16aSSteven Rostedtmy %force_config;
2238d1491baSSteven Rostedt
2244ab1cce5SSteven Rostedt# do not force reboots on config problems
2254ab1cce5SSteven Rostedtmy $no_reboot = 1;
2264ab1cce5SSteven Rostedt
227759a3cc6SSteven Rostedt# reboot on success
228759a3cc6SSteven Rostedtmy $reboot_success = 0;
229759a3cc6SSteven Rostedt
2309cc9e091SSteven Rostedtmy %option_map = (
2319cc9e091SSteven Rostedt    "MACHINE"			=> \$machine,
2329cc9e091SSteven Rostedt    "SSH_USER"			=> \$ssh_user,
2339cc9e091SSteven Rostedt    "TMP_DIR"			=> \$tmpdir,
2349cc9e091SSteven Rostedt    "OUTPUT_DIR"		=> \$outputdir,
2359cc9e091SSteven Rostedt    "BUILD_DIR"			=> \$builddir,
2369cc9e091SSteven Rostedt    "TEST_TYPE"			=> \$test_type,
237921ed4c7SSteven Rostedt    "PRE_KTEST"			=> \$pre_ktest,
238921ed4c7SSteven Rostedt    "POST_KTEST"		=> \$post_ktest,
239921ed4c7SSteven Rostedt    "PRE_TEST"			=> \$pre_test,
240921ed4c7SSteven Rostedt    "POST_TEST"			=> \$post_test,
2419cc9e091SSteven Rostedt    "BUILD_TYPE"		=> \$build_type,
2429cc9e091SSteven Rostedt    "BUILD_OPTIONS"		=> \$build_options,
2439cc9e091SSteven Rostedt    "PRE_BUILD"			=> \$pre_build,
2449cc9e091SSteven Rostedt    "POST_BUILD"		=> \$post_build,
2459cc9e091SSteven Rostedt    "PRE_BUILD_DIE"		=> \$pre_build_die,
2469cc9e091SSteven Rostedt    "POST_BUILD_DIE"		=> \$post_build_die,
2479cc9e091SSteven Rostedt    "POWER_CYCLE"		=> \$power_cycle,
2489cc9e091SSteven Rostedt    "REBOOT"			=> \$reboot,
2499cc9e091SSteven Rostedt    "BUILD_NOCLEAN"		=> \$noclean,
2509cc9e091SSteven Rostedt    "MIN_CONFIG"		=> \$minconfig,
2519cc9e091SSteven Rostedt    "OUTPUT_MIN_CONFIG"		=> \$output_minconfig,
2529cc9e091SSteven Rostedt    "START_MIN_CONFIG"		=> \$start_minconfig,
253ccc513b6SSteven Rostedt    "MIN_CONFIG_TYPE"		=> \$minconfig_type,
25443de3316SSteven Rostedt    "USE_OUTPUT_MIN_CONFIG"	=> \$use_output_minconfig,
2554283b169SSteven Rostedt (Red Hat)    "WARNINGS_FILE"		=> \$warnings_file,
2569cc9e091SSteven Rostedt    "IGNORE_CONFIG"		=> \$ignore_config,
2579cc9e091SSteven Rostedt    "TEST"			=> \$run_test,
2589cc9e091SSteven Rostedt    "ADD_CONFIG"		=> \$addconfig,
2599cc9e091SSteven Rostedt    "REBOOT_TYPE"		=> \$reboot_type,
2609cc9e091SSteven Rostedt    "GRUB_MENU"			=> \$grub_menu,
261a15ba913SSteven Rostedt    "GRUB_FILE"			=> \$grub_file,
262a15ba913SSteven Rostedt    "GRUB_REBOOT"		=> \$grub_reboot,
2637786954cSSteven Rostedt    "SYSLINUX"			=> \$syslinux,
2647786954cSSteven Rostedt    "SYSLINUX_PATH"		=> \$syslinux_path,
2657786954cSSteven Rostedt    "SYSLINUX_LABEL"		=> \$syslinux_label,
266e5c2ec11SSteven Rostedt    "PRE_INSTALL"		=> \$pre_install,
2679cc9e091SSteven Rostedt    "POST_INSTALL"		=> \$post_install,
2689cc9e091SSteven Rostedt    "NO_INSTALL"		=> \$no_install,
2699cc9e091SSteven Rostedt    "REBOOT_SCRIPT"		=> \$reboot_script,
2709cc9e091SSteven Rostedt    "REBOOT_ON_ERROR"		=> \$reboot_on_error,
2719cc9e091SSteven Rostedt    "SWITCH_TO_GOOD"		=> \$switch_to_good,
2729cc9e091SSteven Rostedt    "SWITCH_TO_TEST"		=> \$switch_to_test,
2739cc9e091SSteven Rostedt    "POWEROFF_ON_ERROR"		=> \$poweroff_on_error,
274648a182cSSteven Rostedt    "REBOOT_ON_SUCCESS"		=> \$reboot_on_success,
2759cc9e091SSteven Rostedt    "DIE_ON_FAILURE"		=> \$die_on_failure,
2769cc9e091SSteven Rostedt    "POWER_OFF"			=> \$power_off,
2779cc9e091SSteven Rostedt    "POWERCYCLE_AFTER_REBOOT"	=> \$powercycle_after_reboot,
2789cc9e091SSteven Rostedt    "POWEROFF_AFTER_HALT"	=> \$poweroff_after_halt,
279407b95b7SSteven Rostedt    "MAX_MONITOR_WAIT"		=> \$max_monitor_wait,
2809cc9e091SSteven Rostedt    "SLEEP_TIME"		=> \$sleep_time,
2819cc9e091SSteven Rostedt    "BISECT_SLEEP_TIME"		=> \$bisect_sleep_time,
2829cc9e091SSteven Rostedt    "PATCHCHECK_SLEEP_TIME"	=> \$patchcheck_sleep_time,
2839cc9e091SSteven Rostedt    "IGNORE_WARNINGS"		=> \$ignore_warnings,
284be405f95SSteven Rostedt    "IGNORE_ERRORS"		=> \$ignore_errors,
2859cc9e091SSteven Rostedt    "BISECT_MANUAL"		=> \$bisect_manual,
2869cc9e091SSteven Rostedt    "BISECT_SKIP"		=> \$bisect_skip,
287961d9cacSSteven Rostedt (Red Hat)    "BISECT_TRIES"		=> \$bisect_tries,
2889cc9e091SSteven Rostedt    "CONFIG_BISECT_GOOD"	=> \$config_bisect_good,
2899cc9e091SSteven Rostedt    "BISECT_RET_GOOD"		=> \$bisect_ret_good,
2909cc9e091SSteven Rostedt    "BISECT_RET_BAD"		=> \$bisect_ret_bad,
2919cc9e091SSteven Rostedt    "BISECT_RET_SKIP"		=> \$bisect_ret_skip,
2929cc9e091SSteven Rostedt    "BISECT_RET_ABORT"		=> \$bisect_ret_abort,
2939cc9e091SSteven Rostedt    "BISECT_RET_DEFAULT"	=> \$bisect_ret_default,
2949cc9e091SSteven Rostedt    "STORE_FAILURES"		=> \$store_failures,
2959cc9e091SSteven Rostedt    "STORE_SUCCESSES"		=> \$store_successes,
2969cc9e091SSteven Rostedt    "TEST_NAME"			=> \$test_name,
2979cc9e091SSteven Rostedt    "TIMEOUT"			=> \$timeout,
2989cc9e091SSteven Rostedt    "BOOTED_TIMEOUT"		=> \$booted_timeout,
2999cc9e091SSteven Rostedt    "CONSOLE"			=> \$console,
3005a5d8e48SSatoru Takeuchi    "CLOSE_CONSOLE_SIGNAL"	=> \$close_console_signal,
3019cc9e091SSteven Rostedt    "DETECT_TRIPLE_FAULT"	=> \$detect_triplefault,
3029cc9e091SSteven Rostedt    "SUCCESS_LINE"		=> \$success_line,
3039cc9e091SSteven Rostedt    "REBOOT_SUCCESS_LINE"	=> \$reboot_success_line,
3049cc9e091SSteven Rostedt    "STOP_AFTER_SUCCESS"	=> \$stop_after_success,
3059cc9e091SSteven Rostedt    "STOP_AFTER_FAILURE"	=> \$stop_after_failure,
3069cc9e091SSteven Rostedt    "STOP_TEST_AFTER"		=> \$stop_test_after,
3079cc9e091SSteven Rostedt    "BUILD_TARGET"		=> \$build_target,
3089cc9e091SSteven Rostedt    "SSH_EXEC"			=> \$ssh_exec,
3099cc9e091SSteven Rostedt    "SCP_TO_TARGET"		=> \$scp_to_target,
31002ad2617SSteven Rostedt    "SCP_TO_TARGET_INSTALL"	=> \$scp_to_target_install,
3119cc9e091SSteven Rostedt    "CHECKOUT"			=> \$checkout,
3129cc9e091SSteven Rostedt    "TARGET_IMAGE"		=> \$target_image,
3139cc9e091SSteven Rostedt    "LOCALVERSION"		=> \$localversion,
3149cc9e091SSteven Rostedt
3159cc9e091SSteven Rostedt    "BISECT_GOOD"		=> \$bisect_good,
3169cc9e091SSteven Rostedt    "BISECT_BAD"		=> \$bisect_bad,
3179cc9e091SSteven Rostedt    "BISECT_TYPE"		=> \$bisect_type,
3189cc9e091SSteven Rostedt    "BISECT_START"		=> \$bisect_start,
3199cc9e091SSteven Rostedt    "BISECT_REPLAY"		=> \$bisect_replay,
3209cc9e091SSteven Rostedt    "BISECT_FILES"		=> \$bisect_files,
3219cc9e091SSteven Rostedt    "BISECT_REVERSE"		=> \$bisect_reverse,
3229cc9e091SSteven Rostedt    "BISECT_CHECK"		=> \$bisect_check,
3239cc9e091SSteven Rostedt
3249cc9e091SSteven Rostedt    "CONFIG_BISECT"		=> \$config_bisect,
3259cc9e091SSteven Rostedt    "CONFIG_BISECT_TYPE"	=> \$config_bisect_type,
326b0918612SSteven Rostedt    "CONFIG_BISECT_CHECK"	=> \$config_bisect_check,
3279cc9e091SSteven Rostedt
3289cc9e091SSteven Rostedt    "PATCHCHECK_TYPE"		=> \$patchcheck_type,
3299cc9e091SSteven Rostedt    "PATCHCHECK_START"		=> \$patchcheck_start,
33023a0e161SSteven Rostedt (Red Hat)    "PATCHCHECK_CHERRY"		=> \$patchcheck_cherry,
3319cc9e091SSteven Rostedt    "PATCHCHECK_END"		=> \$patchcheck_end,
3329cc9e091SSteven Rostedt);
3339cc9e091SSteven Rostedt
3349cc9e091SSteven Rostedt# Options may be used by other options, record them.
3359cc9e091SSteven Rostedtmy %used_options;
3369cc9e091SSteven Rostedt
3377bf51073SSteven Rostedt# default variables that can be used
3387bf51073SSteven Rostedtchomp ($variable{"PWD"} = `pwd`);
3397bf51073SSteven Rostedt
3408d1491baSSteven Rostedt$config_help{"MACHINE"} = << "EOF"
3418d1491baSSteven Rostedt The machine hostname that you will test.
342bb8474b1SSteven Rostedt For build only tests, it is still needed to differentiate log files.
3438d1491baSSteven RostedtEOF
3448d1491baSSteven Rostedt    ;
3458d1491baSSteven Rostedt$config_help{"SSH_USER"} = << "EOF"
3468d1491baSSteven Rostedt The box is expected to have ssh on normal bootup, provide the user
3478d1491baSSteven Rostedt  (most likely root, since you need privileged operations)
3488d1491baSSteven RostedtEOF
3498d1491baSSteven Rostedt    ;
3508d1491baSSteven Rostedt$config_help{"BUILD_DIR"} = << "EOF"
3518d1491baSSteven Rostedt The directory that contains the Linux source code (full path).
3520e7a22deSSteven Rostedt You can use \${PWD} that will be the path where ktest.pl is run, or use
3530e7a22deSSteven Rostedt \${THIS_DIR} which is assigned \${PWD} but may be changed later.
3548d1491baSSteven RostedtEOF
3558d1491baSSteven Rostedt    ;
3568d1491baSSteven Rostedt$config_help{"OUTPUT_DIR"} = << "EOF"
3578d1491baSSteven Rostedt The directory that the objects will be built (full path).
3588d1491baSSteven Rostedt (can not be same as BUILD_DIR)
3590e7a22deSSteven Rostedt You can use \${PWD} that will be the path where ktest.pl is run, or use
3600e7a22deSSteven Rostedt \${THIS_DIR} which is assigned \${PWD} but may be changed later.
3618d1491baSSteven RostedtEOF
3628d1491baSSteven Rostedt    ;
3638d1491baSSteven Rostedt$config_help{"BUILD_TARGET"} = << "EOF"
3648d1491baSSteven Rostedt The location of the compiled file to copy to the target.
3658d1491baSSteven Rostedt (relative to OUTPUT_DIR)
3668d1491baSSteven RostedtEOF
3678d1491baSSteven Rostedt    ;
368dbd3783bSSteven Rostedt$config_help{"BUILD_OPTIONS"} = << "EOF"
369dbd3783bSSteven Rostedt Options to add to \"make\" when building.
370dbd3783bSSteven Rostedt i.e.  -j20
371dbd3783bSSteven RostedtEOF
372dbd3783bSSteven Rostedt    ;
3738d1491baSSteven Rostedt$config_help{"TARGET_IMAGE"} = << "EOF"
3748d1491baSSteven Rostedt The place to put your image on the test machine.
3758d1491baSSteven RostedtEOF
3768d1491baSSteven Rostedt    ;
3778d1491baSSteven Rostedt$config_help{"POWER_CYCLE"} = << "EOF"
3788d1491baSSteven Rostedt A script or command to reboot the box.
3798d1491baSSteven Rostedt
3808d1491baSSteven Rostedt Here is a digital loggers power switch example
3818d1491baSSteven Rostedt POWER_CYCLE = wget --no-proxy -O /dev/null -q  --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
3828d1491baSSteven Rostedt
3838d1491baSSteven Rostedt Here is an example to reboot a virtual box on the current host
3848d1491baSSteven Rostedt with the name "Guest".
3858d1491baSSteven Rostedt POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
3868d1491baSSteven RostedtEOF
3878d1491baSSteven Rostedt    ;
3888d1491baSSteven Rostedt$config_help{"CONSOLE"} = << "EOF"
3898d1491baSSteven Rostedt The script or command that reads the console
3908d1491baSSteven Rostedt
3918d1491baSSteven Rostedt  If you use ttywatch server, something like the following would work.
3928d1491baSSteven RostedtCONSOLE = nc -d localhost 3001
3938d1491baSSteven Rostedt
3948d1491baSSteven Rostedt For a virtual machine with guest name "Guest".
3958d1491baSSteven RostedtCONSOLE =  virsh console Guest
3968d1491baSSteven RostedtEOF
3978d1491baSSteven Rostedt    ;
3988d1491baSSteven Rostedt$config_help{"LOCALVERSION"} = << "EOF"
3998d1491baSSteven Rostedt Required version ending to differentiate the test
4008d1491baSSteven Rostedt from other linux builds on the system.
4018d1491baSSteven RostedtEOF
4028d1491baSSteven Rostedt    ;
4038d1491baSSteven Rostedt$config_help{"REBOOT_TYPE"} = << "EOF"
4048d1491baSSteven Rostedt Way to reboot the box to the test kernel.
4057786954cSSteven Rostedt Only valid options so far are "grub", "grub2", "syslinux", and "script".
4068d1491baSSteven Rostedt
4078d1491baSSteven Rostedt If you specify grub, it will assume grub version 1
4088d1491baSSteven Rostedt and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
4098d1491baSSteven Rostedt and select that target to reboot to the kernel. If this is not
4108d1491baSSteven Rostedt your setup, then specify "script" and have a command or script
4118d1491baSSteven Rostedt specified in REBOOT_SCRIPT to boot to the target.
4128d1491baSSteven Rostedt
4138d1491baSSteven Rostedt The entry in /boot/grub/menu.lst must be entered in manually.
4148d1491baSSteven Rostedt The test will not modify that file.
415a15ba913SSteven Rostedt
416a15ba913SSteven Rostedt If you specify grub2, then you also need to specify both \$GRUB_MENU
417a15ba913SSteven Rostedt and \$GRUB_FILE.
4187786954cSSteven Rostedt
4197786954cSSteven Rostedt If you specify syslinux, then you may use SYSLINUX to define the syslinux
4207786954cSSteven Rostedt command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
4217786954cSSteven Rostedt the syslinux install (defaults to /boot/extlinux). But you have to specify
4227786954cSSteven Rostedt SYSLINUX_LABEL to define the label to boot to for the test kernel.
4238d1491baSSteven RostedtEOF
4248d1491baSSteven Rostedt    ;
4258d1491baSSteven Rostedt$config_help{"GRUB_MENU"} = << "EOF"
4268d1491baSSteven Rostedt The grub title name for the test kernel to boot
427a15ba913SSteven Rostedt (Only mandatory if REBOOT_TYPE = grub or grub2)
4288d1491baSSteven Rostedt
4298d1491baSSteven Rostedt Note, ktest.pl will not update the grub menu.lst, you need to
4308d1491baSSteven Rostedt manually add an option for the test. ktest.pl will search
4318d1491baSSteven Rostedt the grub menu.lst for this option to find what kernel to
4328d1491baSSteven Rostedt reboot into.
4338d1491baSSteven Rostedt
4348d1491baSSteven Rostedt For example, if in the /boot/grub/menu.lst the test kernel title has:
4358d1491baSSteven Rostedt title Test Kernel
4368d1491baSSteven Rostedt kernel vmlinuz-test
4378d1491baSSteven Rostedt GRUB_MENU = Test Kernel
438a15ba913SSteven Rostedt
439a15ba913SSteven Rostedt For grub2, a search of \$GRUB_FILE is performed for the lines
440a15ba913SSteven Rostedt that begin with "menuentry". It will not detect submenus. The
441a15ba913SSteven Rostedt menu must be a non-nested menu. Add the quotes used in the menu
442a15ba913SSteven Rostedt to guarantee your selection, as the first menuentry with the content
443a15ba913SSteven Rostedt of \$GRUB_MENU that is found will be used.
444a15ba913SSteven RostedtEOF
445a15ba913SSteven Rostedt    ;
446a15ba913SSteven Rostedt$config_help{"GRUB_FILE"} = << "EOF"
447a15ba913SSteven Rostedt If grub2 is used, the full path for the grub.cfg file is placed
448a15ba913SSteven Rostedt here. Use something like /boot/grub2/grub.cfg to search.
4498d1491baSSteven RostedtEOF
4508d1491baSSteven Rostedt    ;
4517786954cSSteven Rostedt$config_help{"SYSLINUX_LABEL"} = << "EOF"
4527786954cSSteven Rostedt If syslinux is used, the label that boots the target kernel must
4537786954cSSteven Rostedt be specified with SYSLINUX_LABEL.
4547786954cSSteven RostedtEOF
4557786954cSSteven Rostedt    ;
4568d1491baSSteven Rostedt$config_help{"REBOOT_SCRIPT"} = << "EOF"
4578d1491baSSteven Rostedt A script to reboot the target into the test kernel
4588d1491baSSteven Rostedt (Only mandatory if REBOOT_TYPE = script)
4598d1491baSSteven RostedtEOF
4608d1491baSSteven Rostedt    ;
4618d1491baSSteven Rostedt
462c75d22d9SSteven Rostedt (Red Hat)sub _logit {
463c75d22d9SSteven Rostedt (Red Hat)    if (defined($opt{"LOG_FILE"})) {
464c75d22d9SSteven Rostedt (Red Hat)	open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
465c75d22d9SSteven Rostedt (Red Hat)	print OUT @_;
466c75d22d9SSteven Rostedt (Red Hat)	close(OUT);
467c75d22d9SSteven Rostedt (Red Hat)    }
468c75d22d9SSteven Rostedt (Red Hat)}
469c75d22d9SSteven Rostedt (Red Hat)
470c75d22d9SSteven Rostedt (Red Hat)sub logit {
471c75d22d9SSteven Rostedt (Red Hat)    if (defined($opt{"LOG_FILE"})) {
472c75d22d9SSteven Rostedt (Red Hat)	_logit @_;
473c75d22d9SSteven Rostedt (Red Hat)    } else {
474c75d22d9SSteven Rostedt (Red Hat)	print @_;
475c75d22d9SSteven Rostedt (Red Hat)    }
476c75d22d9SSteven Rostedt (Red Hat)}
477c75d22d9SSteven Rostedt (Red Hat)
478c75d22d9SSteven Rostedt (Red Hat)sub doprint {
479c75d22d9SSteven Rostedt (Red Hat)    print @_;
480c75d22d9SSteven Rostedt (Red Hat)    _logit @_;
481c75d22d9SSteven Rostedt (Red Hat)}
482c75d22d9SSteven Rostedt (Red Hat)
483dad98754SSteven Rostedtsub read_prompt {
484dad98754SSteven Rostedt    my ($cancel, $prompt) = @_;
48535ce5952SSteven Rostedt
48635ce5952SSteven Rostedt    my $ans;
48735ce5952SSteven Rostedt
48835ce5952SSteven Rostedt    for (;;) {
489dad98754SSteven Rostedt	if ($cancel) {
490dad98754SSteven Rostedt	    print "$prompt [y/n/C] ";
491dad98754SSteven Rostedt	} else {
49235ce5952SSteven Rostedt	    print "$prompt [Y/n] ";
493dad98754SSteven Rostedt	}
49435ce5952SSteven Rostedt	$ans = <STDIN>;
49535ce5952SSteven Rostedt	chomp $ans;
49635ce5952SSteven Rostedt	if ($ans =~ /^\s*$/) {
497dad98754SSteven Rostedt	    if ($cancel) {
498dad98754SSteven Rostedt		$ans = "c";
499dad98754SSteven Rostedt	    } else {
50035ce5952SSteven Rostedt		$ans = "y";
50135ce5952SSteven Rostedt	    }
502dad98754SSteven Rostedt	}
50335ce5952SSteven Rostedt	last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
504dad98754SSteven Rostedt	if ($cancel) {
505dad98754SSteven Rostedt	    last if ($ans =~ /^c$/i);
506dad98754SSteven Rostedt	    print "Please answer either 'y', 'n' or 'c'.\n";
507dad98754SSteven Rostedt	} else {
50835ce5952SSteven Rostedt	    print "Please answer either 'y' or 'n'.\n";
50935ce5952SSteven Rostedt	}
510dad98754SSteven Rostedt    }
511dad98754SSteven Rostedt    if ($ans =~ /^c/i) {
512dad98754SSteven Rostedt	exit;
513dad98754SSteven Rostedt    }
51435ce5952SSteven Rostedt    if ($ans !~ /^y$/i) {
51535ce5952SSteven Rostedt	return 0;
51635ce5952SSteven Rostedt    }
51735ce5952SSteven Rostedt    return 1;
51835ce5952SSteven Rostedt}
5198d1491baSSteven Rostedt
520dad98754SSteven Rostedtsub read_yn {
521dad98754SSteven Rostedt    my ($prompt) = @_;
522dad98754SSteven Rostedt
523dad98754SSteven Rostedt    return read_prompt 0, $prompt;
524dad98754SSteven Rostedt}
525dad98754SSteven Rostedt
526dad98754SSteven Rostedtsub read_ync {
527dad98754SSteven Rostedt    my ($prompt) = @_;
528dad98754SSteven Rostedt
529dad98754SSteven Rostedt    return read_prompt 1, $prompt;
530dad98754SSteven Rostedt}
531dad98754SSteven Rostedt
5325269faadSSatoru Takeuchisub get_mandatory_config {
5338d1491baSSteven Rostedt    my ($config) = @_;
534815e2bd7SSteven Rostedt    my $ans;
5358d1491baSSteven Rostedt
5368d1491baSSteven Rostedt    return if (defined($opt{$config}));
5378d1491baSSteven Rostedt
5388d1491baSSteven Rostedt    if (defined($config_help{$config})) {
5398d1491baSSteven Rostedt	print "\n";
5408d1491baSSteven Rostedt	print $config_help{$config};
5418d1491baSSteven Rostedt    }
5428d1491baSSteven Rostedt
5438d1491baSSteven Rostedt    for (;;) {
5448d1491baSSteven Rostedt	print "$config = ";
545dbd3783bSSteven Rostedt	if (defined($default{$config}) && length($default{$config})) {
5468d1491baSSteven Rostedt	    print "\[$default{$config}\] ";
5478d1491baSSteven Rostedt	}
548815e2bd7SSteven Rostedt	$ans = <STDIN>;
549815e2bd7SSteven Rostedt	$ans =~ s/^\s*(.*\S)\s*$/$1/;
550815e2bd7SSteven Rostedt	if ($ans =~ /^\s*$/) {
5518d1491baSSteven Rostedt	    if ($default{$config}) {
552815e2bd7SSteven Rostedt		$ans = $default{$config};
5538d1491baSSteven Rostedt	    } else {
5548d1491baSSteven Rostedt		print "Your answer can not be blank\n";
5558d1491baSSteven Rostedt		next;
5568d1491baSSteven Rostedt	    }
5578d1491baSSteven Rostedt	}
5580e7a22deSSteven Rostedt	$entered_configs{$config} = ${ans};
5598d1491baSSteven Rostedt	last;
5608d1491baSSteven Rostedt    }
5618d1491baSSteven Rostedt}
5628d1491baSSteven Rostedt
56338fa3dc1SSteven Rostedt (Red Hat)sub show_time {
56438fa3dc1SSteven Rostedt (Red Hat)    my ($time) = @_;
56538fa3dc1SSteven Rostedt (Red Hat)
56638fa3dc1SSteven Rostedt (Red Hat)    my $hours = 0;
56738fa3dc1SSteven Rostedt (Red Hat)    my $minutes = 0;
56838fa3dc1SSteven Rostedt (Red Hat)
56938fa3dc1SSteven Rostedt (Red Hat)    if ($time > 3600) {
57038fa3dc1SSteven Rostedt (Red Hat)	$hours = int($time / 3600);
57138fa3dc1SSteven Rostedt (Red Hat)	$time -= $hours * 3600;
57238fa3dc1SSteven Rostedt (Red Hat)    }
57338fa3dc1SSteven Rostedt (Red Hat)    if ($time > 60) {
57438fa3dc1SSteven Rostedt (Red Hat)	$minutes = int($time / 60);
57538fa3dc1SSteven Rostedt (Red Hat)	$time -= $minutes * 60;
57638fa3dc1SSteven Rostedt (Red Hat)    }
57738fa3dc1SSteven Rostedt (Red Hat)
57838fa3dc1SSteven Rostedt (Red Hat)    if ($hours > 0) {
57938fa3dc1SSteven Rostedt (Red Hat)	doprint "$hours hour";
58038fa3dc1SSteven Rostedt (Red Hat)	doprint "s" if ($hours > 1);
58138fa3dc1SSteven Rostedt (Red Hat)	doprint " ";
58238fa3dc1SSteven Rostedt (Red Hat)    }
58338fa3dc1SSteven Rostedt (Red Hat)
58438fa3dc1SSteven Rostedt (Red Hat)    if ($minutes > 0) {
58538fa3dc1SSteven Rostedt (Red Hat)	doprint "$minutes minute";
58638fa3dc1SSteven Rostedt (Red Hat)	doprint "s" if ($minutes > 1);
58738fa3dc1SSteven Rostedt (Red Hat)	doprint " ";
58838fa3dc1SSteven Rostedt (Red Hat)    }
58938fa3dc1SSteven Rostedt (Red Hat)
59038fa3dc1SSteven Rostedt (Red Hat)    doprint "$time second";
59138fa3dc1SSteven Rostedt (Red Hat)    doprint "s" if ($time != 1);
59238fa3dc1SSteven Rostedt (Red Hat)}
59338fa3dc1SSteven Rostedt (Red Hat)
59438fa3dc1SSteven Rostedt (Red Hat)sub print_times {
59538fa3dc1SSteven Rostedt (Red Hat)    doprint "\n";
59638fa3dc1SSteven Rostedt (Red Hat)    if ($build_time) {
59738fa3dc1SSteven Rostedt (Red Hat)	doprint "Build time:   ";
59838fa3dc1SSteven Rostedt (Red Hat)	show_time($build_time);
59938fa3dc1SSteven Rostedt (Red Hat)	doprint "\n";
60038fa3dc1SSteven Rostedt (Red Hat)    }
60138fa3dc1SSteven Rostedt (Red Hat)    if ($install_time) {
60238fa3dc1SSteven Rostedt (Red Hat)	doprint "Install time: ";
60338fa3dc1SSteven Rostedt (Red Hat)	show_time($install_time);
60438fa3dc1SSteven Rostedt (Red Hat)	doprint "\n";
60538fa3dc1SSteven Rostedt (Red Hat)    }
60638fa3dc1SSteven Rostedt (Red Hat)    if ($reboot_time) {
60738fa3dc1SSteven Rostedt (Red Hat)	doprint "Reboot time:  ";
60838fa3dc1SSteven Rostedt (Red Hat)	show_time($reboot_time);
60938fa3dc1SSteven Rostedt (Red Hat)	doprint "\n";
61038fa3dc1SSteven Rostedt (Red Hat)    }
61138fa3dc1SSteven Rostedt (Red Hat)    if ($test_time) {
61238fa3dc1SSteven Rostedt (Red Hat)	doprint "Test time:    ";
61338fa3dc1SSteven Rostedt (Red Hat)	show_time($test_time);
61438fa3dc1SSteven Rostedt (Red Hat)	doprint "\n";
61538fa3dc1SSteven Rostedt (Red Hat)    }
61638fa3dc1SSteven Rostedt (Red Hat)    # reset for iterations like bisect
61738fa3dc1SSteven Rostedt (Red Hat)    $build_time = 0;
61838fa3dc1SSteven Rostedt (Red Hat)    $install_time = 0;
61938fa3dc1SSteven Rostedt (Red Hat)    $reboot_time = 0;
62038fa3dc1SSteven Rostedt (Red Hat)    $test_time = 0;
62138fa3dc1SSteven Rostedt (Red Hat)}
62238fa3dc1SSteven Rostedt (Red Hat)
6235269faadSSatoru Takeuchisub get_mandatory_configs {
6245269faadSSatoru Takeuchi    get_mandatory_config("MACHINE");
6255269faadSSatoru Takeuchi    get_mandatory_config("BUILD_DIR");
6265269faadSSatoru Takeuchi    get_mandatory_config("OUTPUT_DIR");
627bb8474b1SSteven Rostedt
628dbd3783bSSteven Rostedt    if ($newconfig) {
6295269faadSSatoru Takeuchi	get_mandatory_config("BUILD_OPTIONS");
630dbd3783bSSteven Rostedt    }
631dbd3783bSSteven Rostedt
632bb8474b1SSteven Rostedt    # options required for other than just building a kernel
633bb8474b1SSteven Rostedt    if (!$buildonly) {
6345269faadSSatoru Takeuchi	get_mandatory_config("POWER_CYCLE");
6355269faadSSatoru Takeuchi	get_mandatory_config("CONSOLE");
636165708b2SSteven Rostedt    }
637165708b2SSteven Rostedt
638165708b2SSteven Rostedt    # options required for install and more
639165708b2SSteven Rostedt    if ($buildonly != 1) {
6405269faadSSatoru Takeuchi	get_mandatory_config("SSH_USER");
6415269faadSSatoru Takeuchi	get_mandatory_config("BUILD_TARGET");
6425269faadSSatoru Takeuchi	get_mandatory_config("TARGET_IMAGE");
643bb8474b1SSteven Rostedt    }
644bb8474b1SSteven Rostedt
6455269faadSSatoru Takeuchi    get_mandatory_config("LOCALVERSION");
6468d1491baSSteven Rostedt
647bb8474b1SSteven Rostedt    return if ($buildonly);
648bb8474b1SSteven Rostedt
6498d1491baSSteven Rostedt    my $rtype = $opt{"REBOOT_TYPE"};
6508d1491baSSteven Rostedt
6518d1491baSSteven Rostedt    if (!defined($rtype)) {
6528d1491baSSteven Rostedt	if (!defined($opt{"GRUB_MENU"})) {
6535269faadSSatoru Takeuchi	    get_mandatory_config("REBOOT_TYPE");
6548d1491baSSteven Rostedt	    $rtype = $entered_configs{"REBOOT_TYPE"};
6558d1491baSSteven Rostedt	} else {
6568d1491baSSteven Rostedt	    $rtype = "grub";
6578d1491baSSteven Rostedt	}
6588d1491baSSteven Rostedt    }
6598d1491baSSteven Rostedt
6608d1491baSSteven Rostedt    if ($rtype eq "grub") {
6615269faadSSatoru Takeuchi	get_mandatory_config("GRUB_MENU");
6628d1491baSSteven Rostedt    }
663a15ba913SSteven Rostedt
664a15ba913SSteven Rostedt    if ($rtype eq "grub2") {
6655269faadSSatoru Takeuchi	get_mandatory_config("GRUB_MENU");
6665269faadSSatoru Takeuchi	get_mandatory_config("GRUB_FILE");
667a15ba913SSteven Rostedt    }
6687786954cSSteven Rostedt
6697786954cSSteven Rostedt    if ($rtype eq "syslinux") {
6705269faadSSatoru Takeuchi	get_mandatory_config("SYSLINUX_LABEL");
6717786954cSSteven Rostedt    }
6728d1491baSSteven Rostedt}
6738d1491baSSteven Rostedt
67477d942ceSSteven Rostedtsub process_variables {
6758d735212SSteven Rostedt    my ($value, $remove_undef) = @_;
67677d942ceSSteven Rostedt    my $retval = "";
67777d942ceSSteven Rostedt
67877d942ceSSteven Rostedt    # We want to check for '\', and it is just easier
67977d942ceSSteven Rostedt    # to check the previous characet of '$' and not need
68077d942ceSSteven Rostedt    # to worry if '$' is the first character. By adding
68177d942ceSSteven Rostedt    # a space to $value, we can just check [^\\]\$ and
68277d942ceSSteven Rostedt    # it will still work.
68377d942ceSSteven Rostedt    $value = " $value";
68477d942ceSSteven Rostedt
68577d942ceSSteven Rostedt    while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
68677d942ceSSteven Rostedt	my $begin = $1;
68777d942ceSSteven Rostedt	my $var = $2;
68877d942ceSSteven Rostedt	my $end = $3;
68977d942ceSSteven Rostedt	# append beginning of value to retval
69077d942ceSSteven Rostedt	$retval = "$retval$begin";
69177d942ceSSteven Rostedt	if (defined($variable{$var})) {
69277d942ceSSteven Rostedt	    $retval = "$retval$variable{$var}";
6938d735212SSteven Rostedt	} elsif (defined($remove_undef) && $remove_undef) {
6948d735212SSteven Rostedt	    # for if statements, any variable that is not defined,
6958d735212SSteven Rostedt	    # we simple convert to 0
6968d735212SSteven Rostedt	    $retval = "${retval}0";
69777d942ceSSteven Rostedt	} else {
69877d942ceSSteven Rostedt	    # put back the origin piece.
69977d942ceSSteven Rostedt	    $retval = "$retval\$\{$var\}";
7009cc9e091SSteven Rostedt	    # This could be an option that is used later, save
7019cc9e091SSteven Rostedt	    # it so we don't warn if this option is not one of
7029cc9e091SSteven Rostedt	    # ktests options.
7039cc9e091SSteven Rostedt	    $used_options{$var} = 1;
70477d942ceSSteven Rostedt	}
70577d942ceSSteven Rostedt	$value = $end;
70677d942ceSSteven Rostedt    }
70777d942ceSSteven Rostedt    $retval = "$retval$value";
70877d942ceSSteven Rostedt
70977d942ceSSteven Rostedt    # remove the space added in the beginning
71077d942ceSSteven Rostedt    $retval =~ s/ //;
71177d942ceSSteven Rostedt
71277d942ceSSteven Rostedt    return "$retval"
71377d942ceSSteven Rostedt}
71477d942ceSSteven Rostedt
715a57419b3SSteven Rostedtsub set_value {
7163d1cc414SSteven Rostedt    my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
7172545eb61SSteven Rostedt
718cad96669SSteven Rostedt    my $prvalue = process_variables($rvalue);
719cad96669SSteven Rostedt
720cad96669SSteven Rostedt    if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
721bb8474b1SSteven Rostedt	# Note if a test is something other than build, then we
722bb8474b1SSteven Rostedt	# will need other manditory options.
723cad96669SSteven Rostedt	if ($prvalue ne "install") {
724319ab14fSSteven Rostedt (Red Hat)	    # for bisect, we need to check BISECT_TYPE
725319ab14fSSteven Rostedt (Red Hat)	    if ($prvalue ne "bisect") {
726319ab14fSSteven Rostedt (Red Hat)		$buildonly = 0;
727319ab14fSSteven Rostedt (Red Hat)	    }
728319ab14fSSteven Rostedt (Red Hat)	} else {
729319ab14fSSteven Rostedt (Red Hat)	    # install still limits some manditory options.
730319ab14fSSteven Rostedt (Red Hat)	    $buildonly = 2;
731319ab14fSSteven Rostedt (Red Hat)	}
732319ab14fSSteven Rostedt (Red Hat)    }
733319ab14fSSteven Rostedt (Red Hat)
734319ab14fSSteven Rostedt (Red Hat)    if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
735319ab14fSSteven Rostedt (Red Hat)	if ($prvalue ne "install") {
736bb8474b1SSteven Rostedt	    $buildonly = 0;
737165708b2SSteven Rostedt	} else {
738165708b2SSteven Rostedt	    # install still limits some manditory options.
739165708b2SSteven Rostedt	    $buildonly = 2;
740165708b2SSteven Rostedt	}
741bb8474b1SSteven Rostedt    }
742bb8474b1SSteven Rostedt
743a75fececSSteven Rostedt    if (defined($opt{$lvalue})) {
7443d1cc414SSteven Rostedt	if (!$override || defined(${$overrides}{$lvalue})) {
7453d1cc414SSteven Rostedt	    my $extra = "";
7463d1cc414SSteven Rostedt	    if ($override) {
7473d1cc414SSteven Rostedt		$extra = "In the same override section!\n";
7483d1cc414SSteven Rostedt	    }
7493d1cc414SSteven Rostedt	    die "$name: $.: Option $lvalue defined more than once!\n$extra";
7503d1cc414SSteven Rostedt	}
751cad96669SSteven Rostedt	${$overrides}{$lvalue} = $prvalue;
752a75fececSSteven Rostedt    }
75322c37a9aSSteven Rostedt (Red Hat)
754cad96669SSteven Rostedt    $opt{$lvalue} = $prvalue;
75521a9679fSSteven Rostedt}
756a57419b3SSteven Rostedt
757c75d22d9SSteven Rostedt (Red Hat)sub set_eval {
758c75d22d9SSteven Rostedt (Red Hat)    my ($lvalue, $rvalue, $name) = @_;
759c75d22d9SSteven Rostedt (Red Hat)
760c75d22d9SSteven Rostedt (Red Hat)    my $prvalue = process_variables($rvalue);
761c75d22d9SSteven Rostedt (Red Hat)    my $arr;
762c75d22d9SSteven Rostedt (Red Hat)
763c75d22d9SSteven Rostedt (Red Hat)    if (defined($evals{$lvalue})) {
764c75d22d9SSteven Rostedt (Red Hat)	$arr = $evals{$lvalue};
765c75d22d9SSteven Rostedt (Red Hat)    } else {
766c75d22d9SSteven Rostedt (Red Hat)	$arr = [];
767c75d22d9SSteven Rostedt (Red Hat)	$evals{$lvalue} = $arr;
768c75d22d9SSteven Rostedt (Red Hat)    }
769c75d22d9SSteven Rostedt (Red Hat)
770c75d22d9SSteven Rostedt (Red Hat)    push @{$arr}, $rvalue;
771c75d22d9SSteven Rostedt (Red Hat)}
772c75d22d9SSteven Rostedt (Red Hat)
77377d942ceSSteven Rostedtsub set_variable {
77477d942ceSSteven Rostedt    my ($lvalue, $rvalue) = @_;
77577d942ceSSteven Rostedt
77677d942ceSSteven Rostedt    if ($rvalue =~ /^\s*$/) {
77777d942ceSSteven Rostedt	delete $variable{$lvalue};
77877d942ceSSteven Rostedt    } else {
77977d942ceSSteven Rostedt	$rvalue = process_variables($rvalue);
78077d942ceSSteven Rostedt	$variable{$lvalue} = $rvalue;
78177d942ceSSteven Rostedt    }
78277d942ceSSteven Rostedt}
78377d942ceSSteven Rostedt
784ab7a3f52SSteven Rostedtsub process_compare {
785ab7a3f52SSteven Rostedt    my ($lval, $cmp, $rval) = @_;
786ab7a3f52SSteven Rostedt
787ab7a3f52SSteven Rostedt    # remove whitespace
788ab7a3f52SSteven Rostedt
789ab7a3f52SSteven Rostedt    $lval =~ s/^\s*//;
790ab7a3f52SSteven Rostedt    $lval =~ s/\s*$//;
791ab7a3f52SSteven Rostedt
792ab7a3f52SSteven Rostedt    $rval =~ s/^\s*//;
793ab7a3f52SSteven Rostedt    $rval =~ s/\s*$//;
794ab7a3f52SSteven Rostedt
795ab7a3f52SSteven Rostedt    if ($cmp eq "==") {
796ab7a3f52SSteven Rostedt	return $lval eq $rval;
797ab7a3f52SSteven Rostedt    } elsif ($cmp eq "!=") {
798ab7a3f52SSteven Rostedt	return $lval ne $rval;
7998fddbe9bSSteven Rostedt    } elsif ($cmp eq "=~") {
8008fddbe9bSSteven Rostedt	return $lval =~ m/$rval/;
8018fddbe9bSSteven Rostedt    } elsif ($cmp eq "!~") {
8028fddbe9bSSteven Rostedt	return $lval !~ m/$rval/;
803ab7a3f52SSteven Rostedt    }
804ab7a3f52SSteven Rostedt
805ab7a3f52SSteven Rostedt    my $statement = "$lval $cmp $rval";
806ab7a3f52SSteven Rostedt    my $ret = eval $statement;
807ab7a3f52SSteven Rostedt
808ab7a3f52SSteven Rostedt    # $@ stores error of eval
809ab7a3f52SSteven Rostedt    if ($@) {
810ab7a3f52SSteven Rostedt	return -1;
811ab7a3f52SSteven Rostedt    }
812ab7a3f52SSteven Rostedt
813ab7a3f52SSteven Rostedt    return $ret;
814ab7a3f52SSteven Rostedt}
815ab7a3f52SSteven Rostedt
8169900b5dcSSteven Rostedtsub value_defined {
8179900b5dcSSteven Rostedt    my ($val) = @_;
8189900b5dcSSteven Rostedt
8199900b5dcSSteven Rostedt    return defined($variable{$2}) ||
8209900b5dcSSteven Rostedt	defined($opt{$2});
8219900b5dcSSteven Rostedt}
8229900b5dcSSteven Rostedt
8238d735212SSteven Rostedtmy $d = 0;
8248d735212SSteven Rostedtsub process_expression {
8258d735212SSteven Rostedt    my ($name, $val) = @_;
82645d73a5dSSteven Rostedt
8278d735212SSteven Rostedt    my $c = $d++;
8288d735212SSteven Rostedt
8298d735212SSteven Rostedt    while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
8308d735212SSteven Rostedt	my $express = $1;
8318d735212SSteven Rostedt
8328d735212SSteven Rostedt	if (process_expression($name, $express)) {
8338d735212SSteven Rostedt	    $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
8348d735212SSteven Rostedt	} else {
8358d735212SSteven Rostedt	    $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
8368d735212SSteven Rostedt	}
8378d735212SSteven Rostedt    }
8388d735212SSteven Rostedt
8398d735212SSteven Rostedt    $d--;
8408d735212SSteven Rostedt    my $OR = "\\|\\|";
8418d735212SSteven Rostedt    my $AND = "\\&\\&";
8428d735212SSteven Rostedt
8438d735212SSteven Rostedt    while ($val =~ s/^(.*?)($OR|$AND)//) {
8448d735212SSteven Rostedt	my $express = $1;
8458d735212SSteven Rostedt	my $op = $2;
8468d735212SSteven Rostedt
8478d735212SSteven Rostedt	if (process_expression($name, $express)) {
8488d735212SSteven Rostedt	    if ($op eq "||") {
8498d735212SSteven Rostedt		return 1;
8508d735212SSteven Rostedt	    }
8518d735212SSteven Rostedt	} else {
8528d735212SSteven Rostedt	    if ($op eq "&&") {
8538d735212SSteven Rostedt		return 0;
8548d735212SSteven Rostedt	    }
8558d735212SSteven Rostedt	}
8568d735212SSteven Rostedt    }
85745d73a5dSSteven Rostedt
8588fddbe9bSSteven Rostedt    if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
859ab7a3f52SSteven Rostedt	my $ret = process_compare($1, $2, $3);
860ab7a3f52SSteven Rostedt	if ($ret < 0) {
861ab7a3f52SSteven Rostedt	    die "$name: $.: Unable to process comparison\n";
862ab7a3f52SSteven Rostedt	}
863ab7a3f52SSteven Rostedt	return $ret;
864ab7a3f52SSteven Rostedt    }
865ab7a3f52SSteven Rostedt
8669900b5dcSSteven Rostedt    if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
8679900b5dcSSteven Rostedt	if (defined $1) {
8689900b5dcSSteven Rostedt	    return !value_defined($2);
8699900b5dcSSteven Rostedt	} else {
8709900b5dcSSteven Rostedt	    return value_defined($2);
8719900b5dcSSteven Rostedt	}
8729900b5dcSSteven Rostedt    }
8739900b5dcSSteven Rostedt
87445d73a5dSSteven Rostedt    if ($val =~ /^\s*0\s*$/) {
87545d73a5dSSteven Rostedt	return 0;
87645d73a5dSSteven Rostedt    } elsif ($val =~ /^\s*\d+\s*$/) {
87745d73a5dSSteven Rostedt	return 1;
87845d73a5dSSteven Rostedt    }
87945d73a5dSSteven Rostedt
8809900b5dcSSteven Rostedt    die ("$name: $.: Undefined content $val in if statement\n");
8818d735212SSteven Rostedt}
8828d735212SSteven Rostedt
8838d735212SSteven Rostedtsub process_if {
8848d735212SSteven Rostedt    my ($name, $value) = @_;
8858d735212SSteven Rostedt
8868d735212SSteven Rostedt    # Convert variables and replace undefined ones with 0
8878d735212SSteven Rostedt    my $val = process_variables($value, 1);
8888d735212SSteven Rostedt    my $ret = process_expression $name, $val;
8898d735212SSteven Rostedt
8908d735212SSteven Rostedt    return $ret;
89145d73a5dSSteven Rostedt}
89245d73a5dSSteven Rostedt
8932ed3b161SSteven Rostedtsub __read_config {
8942ed3b161SSteven Rostedt    my ($config, $current_test_num) = @_;
895a57419b3SSteven Rostedt
8962ed3b161SSteven Rostedt    my $in;
8972ed3b161SSteven Rostedt    open($in, $config) || die "can't read file $config";
898a57419b3SSteven Rostedt
899a57419b3SSteven Rostedt    my $name = $config;
900a57419b3SSteven Rostedt    $name =~ s,.*/(.*),$1,;
901a57419b3SSteven Rostedt
9022ed3b161SSteven Rostedt    my $test_num = $$current_test_num;
903a57419b3SSteven Rostedt    my $default = 1;
904a57419b3SSteven Rostedt    my $repeat = 1;
905a57419b3SSteven Rostedt    my $num_tests_set = 0;
906a57419b3SSteven Rostedt    my $skip = 0;
907a57419b3SSteven Rostedt    my $rest;
908a9f84424SSteven Rostedt    my $line;
9090df213caSSteven Rostedt    my $test_case = 0;
91045d73a5dSSteven Rostedt    my $if = 0;
91145d73a5dSSteven Rostedt    my $if_set = 0;
9123d1cc414SSteven Rostedt    my $override = 0;
9133d1cc414SSteven Rostedt
9143d1cc414SSteven Rostedt    my %overrides;
915a57419b3SSteven Rostedt
9162ed3b161SSteven Rostedt    while (<$in>) {
917a57419b3SSteven Rostedt
918a57419b3SSteven Rostedt	# ignore blank lines and comments
919a57419b3SSteven Rostedt	next if (/^\s*$/ || /\s*\#/);
920a57419b3SSteven Rostedt
9210050b6bbSSteven Rostedt	if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
922a57419b3SSteven Rostedt
9230050b6bbSSteven Rostedt	    my $type = $1;
9240050b6bbSSteven Rostedt	    $rest = $2;
925a9f84424SSteven Rostedt	    $line = $2;
9260050b6bbSSteven Rostedt
9270050b6bbSSteven Rostedt	    my $old_test_num;
9280050b6bbSSteven Rostedt	    my $old_repeat;
9293d1cc414SSteven Rostedt	    $override = 0;
9300050b6bbSSteven Rostedt
9310050b6bbSSteven Rostedt	    if ($type eq "TEST_START") {
932a57419b3SSteven Rostedt
933a57419b3SSteven Rostedt		if ($num_tests_set) {
934a57419b3SSteven Rostedt		    die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
935a57419b3SSteven Rostedt		}
936a57419b3SSteven Rostedt
9370050b6bbSSteven Rostedt		$old_test_num = $test_num;
9380050b6bbSSteven Rostedt		$old_repeat = $repeat;
939a57419b3SSteven Rostedt
940a57419b3SSteven Rostedt		$test_num += $repeat;
941a57419b3SSteven Rostedt		$default = 0;
942a57419b3SSteven Rostedt		$repeat = 1;
9430050b6bbSSteven Rostedt	    } else {
9440050b6bbSSteven Rostedt		$default = 1;
9450050b6bbSSteven Rostedt	    }
946a57419b3SSteven Rostedt
947a9f84424SSteven Rostedt	    # If SKIP is anywhere in the line, the command will be skipped
948a9f84424SSteven Rostedt	    if ($rest =~ s/\s+SKIP\b//) {
949a57419b3SSteven Rostedt		$skip = 1;
950a57419b3SSteven Rostedt	    } else {
9510df213caSSteven Rostedt		$test_case = 1;
952a57419b3SSteven Rostedt		$skip = 0;
953a57419b3SSteven Rostedt	    }
954a57419b3SSteven Rostedt
955a9f84424SSteven Rostedt	    if ($rest =~ s/\sELSE\b//) {
956a9f84424SSteven Rostedt		if (!$if) {
957a9f84424SSteven Rostedt		    die "$name: $.: ELSE found with out matching IF section\n$_";
958a57419b3SSteven Rostedt		}
959a9f84424SSteven Rostedt		$if = 0;
960a9f84424SSteven Rostedt
961a9f84424SSteven Rostedt		if ($if_set) {
962a9f84424SSteven Rostedt		    $skip = 1;
963a9f84424SSteven Rostedt		} else {
964a9f84424SSteven Rostedt		    $skip = 0;
9653d1cc414SSteven Rostedt		}
9663d1cc414SSteven Rostedt	    }
967a57419b3SSteven Rostedt
968a9f84424SSteven Rostedt	    if ($rest =~ s/\sIF\s+(.*)//) {
96945d73a5dSSteven Rostedt		if (process_if($name, $1)) {
97045d73a5dSSteven Rostedt		    $if_set = 1;
97145d73a5dSSteven Rostedt		} else {
972a57419b3SSteven Rostedt		    $skip = 1;
973a57419b3SSteven Rostedt		}
97445d73a5dSSteven Rostedt		$if = 1;
97545d73a5dSSteven Rostedt	    } else {
97645d73a5dSSteven Rostedt		$if = 0;
977a9f84424SSteven Rostedt		$if_set = 0;
97845d73a5dSSteven Rostedt	    }
979a57419b3SSteven Rostedt
980a9f84424SSteven Rostedt	    if (!$skip) {
981a9f84424SSteven Rostedt		if ($type eq "TEST_START") {
982a9f84424SSteven Rostedt		    if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
983a9f84424SSteven Rostedt			$repeat = $1;
984a9f84424SSteven Rostedt			$repeat_tests{"$test_num"} = $repeat;
985a9f84424SSteven Rostedt		    }
986a9f84424SSteven Rostedt		} elsif ($rest =~ s/\sOVERRIDE\b//) {
987a9f84424SSteven Rostedt		    # DEFAULT only
988a9f84424SSteven Rostedt		    $override = 1;
989a9f84424SSteven Rostedt		    # Clear previous overrides
990a9f84424SSteven Rostedt		    %overrides = ();
991a9f84424SSteven Rostedt		}
992a9f84424SSteven Rostedt	    }
993a9f84424SSteven Rostedt
994a9f84424SSteven Rostedt	    if (!$skip && $rest !~ /^\s*$/) {
9950050b6bbSSteven Rostedt		die "$name: $.: Gargbage found after $type\n$_";
996a57419b3SSteven Rostedt	    }
997a57419b3SSteven Rostedt
9980050b6bbSSteven Rostedt	    if ($skip && $type eq "TEST_START") {
999a57419b3SSteven Rostedt		$test_num = $old_test_num;
1000e48c5293SSteven Rostedt		$repeat = $old_repeat;
1001a57419b3SSteven Rostedt	    }
1002a57419b3SSteven Rostedt
1003ab7a3f52SSteven Rostedt	} elsif (/^\s*ELSE\b(.*)$/) {
100445d73a5dSSteven Rostedt	    if (!$if) {
100545d73a5dSSteven Rostedt		die "$name: $.: ELSE found with out matching IF section\n$_";
100645d73a5dSSteven Rostedt	    }
100745d73a5dSSteven Rostedt	    $rest = $1;
100845d73a5dSSteven Rostedt	    if ($if_set) {
100945d73a5dSSteven Rostedt		$skip = 1;
1010ab7a3f52SSteven Rostedt		$rest = "";
101145d73a5dSSteven Rostedt	    } else {
101245d73a5dSSteven Rostedt		$skip = 0;
101345d73a5dSSteven Rostedt
1014ab7a3f52SSteven Rostedt		if ($rest =~ /\sIF\s+(.*)/) {
101545d73a5dSSteven Rostedt		    # May be a ELSE IF section.
101695f57838SSteven Rostedt		    if (process_if($name, $1)) {
101795f57838SSteven Rostedt			$if_set = 1;
101895f57838SSteven Rostedt		    } else {
101945d73a5dSSteven Rostedt			$skip = 1;
102045d73a5dSSteven Rostedt		    }
1021ab7a3f52SSteven Rostedt		    $rest = "";
102245d73a5dSSteven Rostedt		} else {
102345d73a5dSSteven Rostedt		    $if = 0;
102445d73a5dSSteven Rostedt		}
102545d73a5dSSteven Rostedt	    }
102645d73a5dSSteven Rostedt
1027ab7a3f52SSteven Rostedt	    if ($rest !~ /^\s*$/) {
1028ab7a3f52SSteven Rostedt		die "$name: $.: Gargbage found after DEFAULTS\n$_";
1029ab7a3f52SSteven Rostedt	    }
1030ab7a3f52SSteven Rostedt
10312ed3b161SSteven Rostedt	} elsif (/^\s*INCLUDE\s+(\S+)/) {
10322ed3b161SSteven Rostedt
10332ed3b161SSteven Rostedt	    next if ($skip);
10342ed3b161SSteven Rostedt
10352ed3b161SSteven Rostedt	    if (!$default) {
10362ed3b161SSteven Rostedt		die "$name: $.: INCLUDE can only be done in default sections\n$_";
10372ed3b161SSteven Rostedt	    }
10382ed3b161SSteven Rostedt
10392ed3b161SSteven Rostedt	    my $file = process_variables($1);
10402ed3b161SSteven Rostedt
10412ed3b161SSteven Rostedt	    if ($file !~ m,^/,) {
10422ed3b161SSteven Rostedt		# check the path of the config file first
10432ed3b161SSteven Rostedt		if ($config =~ m,(.*)/,) {
10442ed3b161SSteven Rostedt		    if (-f "$1/$file") {
10452ed3b161SSteven Rostedt			$file = "$1/$file";
10462ed3b161SSteven Rostedt		    }
10472ed3b161SSteven Rostedt		}
10482ed3b161SSteven Rostedt	    }
10492ed3b161SSteven Rostedt
10502ed3b161SSteven Rostedt	    if ( ! -r $file ) {
10512ed3b161SSteven Rostedt		die "$name: $.: Can't read file $file\n$_";
10522ed3b161SSteven Rostedt	    }
10532ed3b161SSteven Rostedt
10542ed3b161SSteven Rostedt	    if (__read_config($file, \$test_num)) {
10552ed3b161SSteven Rostedt		$test_case = 1;
10562ed3b161SSteven Rostedt	    }
10572ed3b161SSteven Rostedt
1058c75d22d9SSteven Rostedt (Red Hat)	} elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
1059c75d22d9SSteven Rostedt (Red Hat)
1060c75d22d9SSteven Rostedt (Red Hat)	    next if ($skip);
1061c75d22d9SSteven Rostedt (Red Hat)
1062c75d22d9SSteven Rostedt (Red Hat)	    my $lvalue = $1;
1063c75d22d9SSteven Rostedt (Red Hat)	    my $rvalue = $2;
1064c75d22d9SSteven Rostedt (Red Hat)
1065c75d22d9SSteven Rostedt (Red Hat)	    if ($default || $lvalue =~ /\[\d+\]$/) {
1066c75d22d9SSteven Rostedt (Red Hat)		set_eval($lvalue, $rvalue, $name);
1067c75d22d9SSteven Rostedt (Red Hat)	    } else {
1068c75d22d9SSteven Rostedt (Red Hat)		my $val = "$lvalue\[$test_num\]";
1069c75d22d9SSteven Rostedt (Red Hat)		set_eval($val, $rvalue, $name);
1070c75d22d9SSteven Rostedt (Red Hat)	    }
1071c75d22d9SSteven Rostedt (Red Hat)
1072a57419b3SSteven Rostedt	} elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1073a57419b3SSteven Rostedt
1074a57419b3SSteven Rostedt	    next if ($skip);
1075a57419b3SSteven Rostedt
1076a57419b3SSteven Rostedt	    my $lvalue = $1;
1077a57419b3SSteven Rostedt	    my $rvalue = $2;
1078a57419b3SSteven Rostedt
1079a57419b3SSteven Rostedt	    if (!$default &&
1080a57419b3SSteven Rostedt		($lvalue eq "NUM_TESTS" ||
1081a57419b3SSteven Rostedt		 $lvalue eq "LOG_FILE" ||
1082a57419b3SSteven Rostedt		 $lvalue eq "CLEAR_LOG")) {
1083a57419b3SSteven Rostedt		die "$name: $.: $lvalue must be set in DEFAULTS section\n";
1084a57419b3SSteven Rostedt	    }
1085a57419b3SSteven Rostedt
1086a57419b3SSteven Rostedt	    if ($lvalue eq "NUM_TESTS") {
1087a57419b3SSteven Rostedt		if ($test_num) {
1088a57419b3SSteven Rostedt		    die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
1089a57419b3SSteven Rostedt		}
1090a57419b3SSteven Rostedt		if (!$default) {
1091a57419b3SSteven Rostedt		    die "$name: $.: NUM_TESTS must be set in default section\n";
1092a57419b3SSteven Rostedt		}
1093a57419b3SSteven Rostedt		$num_tests_set = 1;
1094a57419b3SSteven Rostedt	    }
1095a57419b3SSteven Rostedt
1096a57419b3SSteven Rostedt	    if ($default || $lvalue =~ /\[\d+\]$/) {
10973d1cc414SSteven Rostedt		set_value($lvalue, $rvalue, $override, \%overrides, $name);
1098a57419b3SSteven Rostedt	    } else {
1099a57419b3SSteven Rostedt		my $val = "$lvalue\[$test_num\]";
11003d1cc414SSteven Rostedt		set_value($val, $rvalue, $override, \%overrides, $name);
1101a57419b3SSteven Rostedt
1102a57419b3SSteven Rostedt		if ($repeat > 1) {
1103a57419b3SSteven Rostedt		    $repeats{$val} = $repeat;
1104a57419b3SSteven Rostedt		}
1105a57419b3SSteven Rostedt	    }
110677d942ceSSteven Rostedt	} elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
110777d942ceSSteven Rostedt	    next if ($skip);
110877d942ceSSteven Rostedt
110977d942ceSSteven Rostedt	    my $lvalue = $1;
111077d942ceSSteven Rostedt	    my $rvalue = $2;
111177d942ceSSteven Rostedt
111277d942ceSSteven Rostedt	    # process config variables.
111377d942ceSSteven Rostedt	    # Config variables are only active while reading the
111477d942ceSSteven Rostedt	    # config and can be defined anywhere. They also ignore
111577d942ceSSteven Rostedt	    # TEST_START and DEFAULTS, but are skipped if they are in
111677d942ceSSteven Rostedt	    # on of these sections that have SKIP defined.
111777d942ceSSteven Rostedt	    # The save variable can be
111877d942ceSSteven Rostedt	    # defined multiple times and the new one simply overrides
111977d942ceSSteven Rostedt	    # the prevous one.
112077d942ceSSteven Rostedt	    set_variable($lvalue, $rvalue);
112177d942ceSSteven Rostedt
1122a57419b3SSteven Rostedt	} else {
1123a57419b3SSteven Rostedt	    die "$name: $.: Garbage found in config\n$_";
1124a57419b3SSteven Rostedt	}
11252545eb61SSteven Rostedt    }
11262545eb61SSteven Rostedt
1127a57419b3SSteven Rostedt    if ($test_num) {
1128a57419b3SSteven Rostedt	$test_num += $repeat - 1;
1129a57419b3SSteven Rostedt	$opt{"NUM_TESTS"} = $test_num;
1130a57419b3SSteven Rostedt    }
1131a57419b3SSteven Rostedt
11322ed3b161SSteven Rostedt    close($in);
11332ed3b161SSteven Rostedt
11342ed3b161SSteven Rostedt    $$current_test_num = $test_num;
11352ed3b161SSteven Rostedt
11362ed3b161SSteven Rostedt    return $test_case;
11372ed3b161SSteven Rostedt}
11382ed3b161SSteven Rostedt
1139c4261d0fSSteven Rostedtsub get_test_case {
1140c4261d0fSSteven Rostedt	print "What test case would you like to run?\n";
1141c4261d0fSSteven Rostedt	print " (build, install or boot)\n";
1142c4261d0fSSteven Rostedt	print " Other tests are available but require editing the config file\n";
1143c4261d0fSSteven Rostedt	my $ans = <STDIN>;
1144c4261d0fSSteven Rostedt	chomp $ans;
1145c4261d0fSSteven Rostedt	$default{"TEST_TYPE"} = $ans;
1146c4261d0fSSteven Rostedt}
1147c4261d0fSSteven Rostedt
11482ed3b161SSteven Rostedtsub read_config {
11492ed3b161SSteven Rostedt    my ($config) = @_;
11502ed3b161SSteven Rostedt
11512ed3b161SSteven Rostedt    my $test_case;
11522ed3b161SSteven Rostedt    my $test_num = 0;
11532ed3b161SSteven Rostedt
11542ed3b161SSteven Rostedt    $test_case = __read_config $config, \$test_num;
11552ed3b161SSteven Rostedt
11568d1491baSSteven Rostedt    # make sure we have all mandatory configs
11575269faadSSatoru Takeuchi    get_mandatory_configs;
11588d1491baSSteven Rostedt
11590df213caSSteven Rostedt    # was a test specified?
11600df213caSSteven Rostedt    if (!$test_case) {
11610df213caSSteven Rostedt	print "No test case specified.\n";
1162c4261d0fSSteven Rostedt	get_test_case;
11630df213caSSteven Rostedt    }
11640df213caSSteven Rostedt
1165a75fececSSteven Rostedt    # set any defaults
1166a75fececSSteven Rostedt
1167a75fececSSteven Rostedt    foreach my $default (keys %default) {
1168a75fececSSteven Rostedt	if (!defined($opt{$default})) {
1169a75fececSSteven Rostedt	    $opt{$default} = $default{$default};
1170a75fececSSteven Rostedt	}
1171a75fececSSteven Rostedt    }
11729cc9e091SSteven Rostedt
11739cc9e091SSteven Rostedt    if ($opt{"IGNORE_UNUSED"} == 1) {
11749cc9e091SSteven Rostedt	return;
11759cc9e091SSteven Rostedt    }
11769cc9e091SSteven Rostedt
11779cc9e091SSteven Rostedt    my %not_used;
11789cc9e091SSteven Rostedt
11799cc9e091SSteven Rostedt    # check if there are any stragglers (typos?)
11809cc9e091SSteven Rostedt    foreach my $option (keys %opt) {
11819cc9e091SSteven Rostedt	my $op = $option;
11829cc9e091SSteven Rostedt	# remove per test labels.
11839cc9e091SSteven Rostedt	$op =~ s/\[.*\]//;
11849cc9e091SSteven Rostedt	if (!exists($option_map{$op}) &&
11859cc9e091SSteven Rostedt	    !exists($default{$op}) &&
11869cc9e091SSteven Rostedt	    !exists($used_options{$op})) {
11879cc9e091SSteven Rostedt	    $not_used{$op} = 1;
11889cc9e091SSteven Rostedt	}
11899cc9e091SSteven Rostedt    }
11909cc9e091SSteven Rostedt
11919cc9e091SSteven Rostedt    if (%not_used) {
11929cc9e091SSteven Rostedt	my $s = "s are";
11939cc9e091SSteven Rostedt	$s = " is" if (keys %not_used == 1);
11949cc9e091SSteven Rostedt	print "The following option$s not used; could be a typo:\n";
11959cc9e091SSteven Rostedt	foreach my $option (keys %not_used) {
11969cc9e091SSteven Rostedt	    print "$option\n";
11979cc9e091SSteven Rostedt	}
11989cc9e091SSteven Rostedt	print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
11999cc9e091SSteven Rostedt	if (!read_yn "Do you want to continue?") {
12009cc9e091SSteven Rostedt	    exit -1;
12019cc9e091SSteven Rostedt	}
12029cc9e091SSteven Rostedt    }
12032545eb61SSteven Rostedt}
12042545eb61SSteven Rostedt
120523715c3cSSteven Rostedtsub __eval_option {
120604262be3SSteven Rostedt (Red Hat)    my ($name, $option, $i) = @_;
120723715c3cSSteven Rostedt
120823715c3cSSteven Rostedt    # Add space to evaluate the character before $
120923715c3cSSteven Rostedt    $option = " $option";
121023715c3cSSteven Rostedt    my $retval = "";
1211f9dfb65bSRabin Vincent    my $repeated = 0;
1212f9dfb65bSRabin Vincent    my $parent = 0;
1213f9dfb65bSRabin Vincent
1214f9dfb65bSRabin Vincent    foreach my $test (keys %repeat_tests) {
1215f9dfb65bSRabin Vincent	if ($i >= $test &&
1216f9dfb65bSRabin Vincent	    $i < $test + $repeat_tests{$test}) {
1217f9dfb65bSRabin Vincent
1218f9dfb65bSRabin Vincent	    $repeated = 1;
1219f9dfb65bSRabin Vincent	    $parent = $test;
1220f9dfb65bSRabin Vincent	    last;
1221f9dfb65bSRabin Vincent	}
1222f9dfb65bSRabin Vincent    }
122323715c3cSSteven Rostedt
122423715c3cSSteven Rostedt    while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
122523715c3cSSteven Rostedt	my $start = $1;
122623715c3cSSteven Rostedt	my $var = $2;
122723715c3cSSteven Rostedt	my $end = $3;
122823715c3cSSteven Rostedt
122923715c3cSSteven Rostedt	# Append beginning of line
123023715c3cSSteven Rostedt	$retval = "$retval$start";
123123715c3cSSteven Rostedt
123223715c3cSSteven Rostedt	# If the iteration option OPT[$i] exists, then use that.
123323715c3cSSteven Rostedt	# otherwise see if the default OPT (without [$i]) exists.
123423715c3cSSteven Rostedt
123523715c3cSSteven Rostedt	my $o = "$var\[$i\]";
1236f9dfb65bSRabin Vincent	my $parento = "$var\[$parent\]";
123723715c3cSSteven Rostedt
123804262be3SSteven Rostedt (Red Hat)	# If a variable contains itself, use the default var
123904262be3SSteven Rostedt (Red Hat)	if (($var eq $name) && defined($opt{$var})) {
124004262be3SSteven Rostedt (Red Hat)	    $o = $opt{$var};
124104262be3SSteven Rostedt (Red Hat)	    $retval = "$retval$o";
124204262be3SSteven Rostedt (Red Hat)	} elsif (defined($opt{$o})) {
124323715c3cSSteven Rostedt	    $o = $opt{$o};
124423715c3cSSteven Rostedt	    $retval = "$retval$o";
1245f9dfb65bSRabin Vincent	} elsif ($repeated && defined($opt{$parento})) {
1246f9dfb65bSRabin Vincent	    $o = $opt{$parento};
1247f9dfb65bSRabin Vincent	    $retval = "$retval$o";
124823715c3cSSteven Rostedt	} elsif (defined($opt{$var})) {
124923715c3cSSteven Rostedt	    $o = $opt{$var};
125023715c3cSSteven Rostedt	    $retval = "$retval$o";
12518e80bf05SSteven Rostedt (Red Hat)	} elsif ($var eq "KERNEL_VERSION" && defined($make)) {
12528e80bf05SSteven Rostedt (Red Hat)	    # special option KERNEL_VERSION uses kernel version
12538e80bf05SSteven Rostedt (Red Hat)	    get_version();
12548e80bf05SSteven Rostedt (Red Hat)	    $retval = "$retval$version";
125523715c3cSSteven Rostedt	} else {
125623715c3cSSteven Rostedt	    $retval = "$retval\$\{$var\}";
125723715c3cSSteven Rostedt	}
125823715c3cSSteven Rostedt
125923715c3cSSteven Rostedt	$option = $end;
126023715c3cSSteven Rostedt    }
126123715c3cSSteven Rostedt
126223715c3cSSteven Rostedt    $retval = "$retval$option";
126323715c3cSSteven Rostedt
126423715c3cSSteven Rostedt    $retval =~ s/^ //;
126523715c3cSSteven Rostedt
126623715c3cSSteven Rostedt    return $retval;
126723715c3cSSteven Rostedt}
126823715c3cSSteven Rostedt
1269c75d22d9SSteven Rostedt (Red Hat)sub process_evals {
1270c75d22d9SSteven Rostedt (Red Hat)    my ($name, $option, $i) = @_;
1271c75d22d9SSteven Rostedt (Red Hat)
1272c75d22d9SSteven Rostedt (Red Hat)    my $option_name = "$name\[$i\]";
1273c75d22d9SSteven Rostedt (Red Hat)    my $ev;
1274c75d22d9SSteven Rostedt (Red Hat)
1275c75d22d9SSteven Rostedt (Red Hat)    my $old_option = $option;
1276c75d22d9SSteven Rostedt (Red Hat)
1277c75d22d9SSteven Rostedt (Red Hat)    if (defined($evals{$option_name})) {
1278c75d22d9SSteven Rostedt (Red Hat)	$ev = $evals{$option_name};
1279c75d22d9SSteven Rostedt (Red Hat)    } elsif (defined($evals{$name})) {
1280c75d22d9SSteven Rostedt (Red Hat)	$ev = $evals{$name};
1281c75d22d9SSteven Rostedt (Red Hat)    } else {
1282c75d22d9SSteven Rostedt (Red Hat)	return $option;
1283c75d22d9SSteven Rostedt (Red Hat)    }
1284c75d22d9SSteven Rostedt (Red Hat)
1285c75d22d9SSteven Rostedt (Red Hat)    for my $e (@{$ev}) {
1286c75d22d9SSteven Rostedt (Red Hat)	eval "\$option =~ $e";
1287c75d22d9SSteven Rostedt (Red Hat)    }
1288c75d22d9SSteven Rostedt (Red Hat)
1289c75d22d9SSteven Rostedt (Red Hat)    if ($option ne $old_option) {
1290c75d22d9SSteven Rostedt (Red Hat)	doprint("$name changed from '$old_option' to '$option'\n");
1291c75d22d9SSteven Rostedt (Red Hat)    }
1292c75d22d9SSteven Rostedt (Red Hat)
1293c75d22d9SSteven Rostedt (Red Hat)    return $option;
1294c75d22d9SSteven Rostedt (Red Hat)}
1295c75d22d9SSteven Rostedt (Red Hat)
129623715c3cSSteven Rostedtsub eval_option {
129704262be3SSteven Rostedt (Red Hat)    my ($name, $option, $i) = @_;
129823715c3cSSteven Rostedt
129923715c3cSSteven Rostedt    my $prev = "";
130023715c3cSSteven Rostedt
130123715c3cSSteven Rostedt    # Since an option can evaluate to another option,
130223715c3cSSteven Rostedt    # keep iterating until we do not evaluate any more
130323715c3cSSteven Rostedt    # options.
130423715c3cSSteven Rostedt    my $r = 0;
130523715c3cSSteven Rostedt    while ($prev ne $option) {
130623715c3cSSteven Rostedt	# Check for recursive evaluations.
130723715c3cSSteven Rostedt	# 100 deep should be more than enough.
130823715c3cSSteven Rostedt	if ($r++ > 100) {
130923715c3cSSteven Rostedt	    die "Over 100 evaluations accurred with $option\n" .
131023715c3cSSteven Rostedt		"Check for recursive variables\n";
131123715c3cSSteven Rostedt	}
131223715c3cSSteven Rostedt	$prev = $option;
131304262be3SSteven Rostedt (Red Hat)	$option = __eval_option($name, $option, $i);
131423715c3cSSteven Rostedt    }
131523715c3cSSteven Rostedt
1316c75d22d9SSteven Rostedt (Red Hat)    $option = process_evals($name, $option, $i);
1317c75d22d9SSteven Rostedt (Red Hat)
131823715c3cSSteven Rostedt    return $option;
131923715c3cSSteven Rostedt}
132023715c3cSSteven Rostedt
13217faafbd6SSteven Rostedtsub run_command;
13222728be41SAndrew Jonessub start_monitor;
13232728be41SAndrew Jonessub end_monitor;
13242728be41SAndrew Jonessub wait_for_monitor;
13257faafbd6SSteven Rostedt
13267faafbd6SSteven Rostedtsub reboot {
13272728be41SAndrew Jones    my ($time) = @_;
13282728be41SAndrew Jones
1329a4968722SSteven Rostedt    # Make sure everything has been written to disk
1330a4968722SSteven Rostedt    run_ssh("sync");
1331a4968722SSteven Rostedt
13322b803365SSteven Rostedt    if (defined($time)) {
13332b803365SSteven Rostedt	start_monitor;
13342b803365SSteven Rostedt	# flush out current monitor
13352b803365SSteven Rostedt	# May contain the reboot success line
13362b803365SSteven Rostedt	wait_for_monitor 1;
13372b803365SSteven Rostedt    }
13382b803365SSteven Rostedt
13397faafbd6SSteven Rostedt    # try to reboot normally
1340e48c5293SSteven Rostedt    if (run_command $reboot) {
1341576f627cSSteven Rostedt	if (defined($powercycle_after_reboot)) {
1342576f627cSSteven Rostedt	    sleep $powercycle_after_reboot;
1343576f627cSSteven Rostedt	    run_command "$power_cycle";
1344576f627cSSteven Rostedt	}
1345576f627cSSteven Rostedt    } else {
13467faafbd6SSteven Rostedt	# nope? power cycle it.
1347a75fececSSteven Rostedt	run_command "$power_cycle";
13487faafbd6SSteven Rostedt    }
13492728be41SAndrew Jones
13502728be41SAndrew Jones    if (defined($time)) {
13514c0b67a2SSteven Rostedt (Red Hat)
13524c0b67a2SSteven Rostedt (Red Hat)	# We only want to get to the new kernel, don't fail
13534c0b67a2SSteven Rostedt (Red Hat)	# if we stumble over a call trace.
13544c0b67a2SSteven Rostedt (Red Hat)	my $save_ignore_errors = $ignore_errors;
13554c0b67a2SSteven Rostedt (Red Hat)	$ignore_errors = 1;
13564c0b67a2SSteven Rostedt (Red Hat)
1357d6845536SSteven Rostedt (Red Hat)	# Look for the good kernel to boot
1358d6845536SSteven Rostedt (Red Hat)	if (wait_for_monitor($time, "Linux version")) {
1359407b95b7SSteven Rostedt	    # reboot got stuck?
13608a80c727SSteven Rostedt	    doprint "Reboot did not finish. Forcing power cycle\n";
1361407b95b7SSteven Rostedt	    run_command "$power_cycle";
1362407b95b7SSteven Rostedt	}
1363d6845536SSteven Rostedt (Red Hat)
13644c0b67a2SSteven Rostedt (Red Hat)	$ignore_errors = $save_ignore_errors;
13654c0b67a2SSteven Rostedt (Red Hat)
1366d6845536SSteven Rostedt (Red Hat)	# Still need to wait for the reboot to finish
1367d6845536SSteven Rostedt (Red Hat)	wait_for_monitor($time, $reboot_success_line);
1368d6845536SSteven Rostedt (Red Hat)
13692728be41SAndrew Jones	end_monitor;
13702728be41SAndrew Jones    }
13717faafbd6SSteven Rostedt}
13727faafbd6SSteven Rostedt
1373bc7c5803SSteven Rostedtsub reboot_to_good {
1374bc7c5803SSteven Rostedt    my ($time) = @_;
1375bc7c5803SSteven Rostedt
1376bc7c5803SSteven Rostedt    if (defined($switch_to_good)) {
1377bc7c5803SSteven Rostedt	run_command $switch_to_good;
1378bc7c5803SSteven Rostedt    }
1379bc7c5803SSteven Rostedt
1380bc7c5803SSteven Rostedt    reboot $time;
1381bc7c5803SSteven Rostedt}
1382bc7c5803SSteven Rostedt
1383576f627cSSteven Rostedtsub do_not_reboot {
1384576f627cSSteven Rostedt    my $i = $iteration;
1385576f627cSSteven Rostedt
13864ab1cce5SSteven Rostedt    return $test_type eq "build" || $no_reboot ||
1387576f627cSSteven Rostedt	($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1388576f627cSSteven Rostedt	($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1389576f627cSSteven Rostedt}
1390576f627cSSteven Rostedt
13915c42fc5bSSteven Rostedtsub dodie {
13925a391fbfSSteven Rostedt    doprint "CRITICAL FAILURE... ", @_, "\n";
13935c42fc5bSSteven Rostedt
1394576f627cSSteven Rostedt    my $i = $iteration;
1395576f627cSSteven Rostedt
1396576f627cSSteven Rostedt    if ($reboot_on_error && !do_not_reboot) {
1397576f627cSSteven Rostedt
139875c3fda7SSteven Rostedt	doprint "REBOOTING\n";
1399bc7c5803SSteven Rostedt	reboot_to_good;
140075c3fda7SSteven Rostedt
1401a75fececSSteven Rostedt    } elsif ($poweroff_on_error && defined($power_off)) {
14025c42fc5bSSteven Rostedt	doprint "POWERING OFF\n";
1403a75fececSSteven Rostedt	`$power_off`;
14045c42fc5bSSteven Rostedt    }
140575c3fda7SSteven Rostedt
1406f80802cbSSteven Rostedt    if (defined($opt{"LOG_FILE"})) {
1407f80802cbSSteven Rostedt	print " See $opt{LOG_FILE} for more info.\n";
1408f80802cbSSteven Rostedt    }
1409f80802cbSSteven Rostedt
1410*1cb9e642SJosh Poimboeuf    if ($monitor_cnt) {
1411*1cb9e642SJosh Poimboeuf	    # restore terminal settings
1412*1cb9e642SJosh Poimboeuf	    system("stty $stty_orig");
1413*1cb9e642SJosh Poimboeuf    }
1414*1cb9e642SJosh Poimboeuf
1415576f627cSSteven Rostedt    die @_, "\n";
14165c42fc5bSSteven Rostedt}
14175c42fc5bSSteven Rostedt
14189f2cdcbbSJosh Poimboeufsub create_pty {
14199f2cdcbbSJosh Poimboeuf    my ($ptm, $pts) = @_;
14209f2cdcbbSJosh Poimboeuf    my $tmp;
14219f2cdcbbSJosh Poimboeuf    my $TIOCSPTLCK = 0x40045431;
14229f2cdcbbSJosh Poimboeuf    my $TIOCGPTN = 0x80045430;
14237faafbd6SSteven Rostedt
14249f2cdcbbSJosh Poimboeuf    sysopen($ptm, "/dev/ptmx", O_RDWR | O_NONBLOCK) or
14259f2cdcbbSJosh Poimboeuf	dodie "Cant open /dev/ptmx";
14269f2cdcbbSJosh Poimboeuf
14279f2cdcbbSJosh Poimboeuf    # unlockpt()
14289f2cdcbbSJosh Poimboeuf    $tmp = pack("i", 0);
14299f2cdcbbSJosh Poimboeuf    ioctl($ptm, $TIOCSPTLCK, $tmp) or
14309f2cdcbbSJosh Poimboeuf	dodie "ioctl TIOCSPTLCK for /dev/ptmx failed";
14319f2cdcbbSJosh Poimboeuf
14329f2cdcbbSJosh Poimboeuf    # ptsname()
14339f2cdcbbSJosh Poimboeuf    ioctl($ptm, $TIOCGPTN, $tmp) or
14349f2cdcbbSJosh Poimboeuf	dodie "ioctl TIOCGPTN for /dev/ptmx failed";
14359f2cdcbbSJosh Poimboeuf    $tmp = unpack("i", $tmp);
14369f2cdcbbSJosh Poimboeuf
14379f2cdcbbSJosh Poimboeuf    sysopen($pts, "/dev/pts/$tmp", O_RDWR | O_NONBLOCK) or
14389f2cdcbbSJosh Poimboeuf	dodie "Can't open /dev/pts/$tmp";
14399f2cdcbbSJosh Poimboeuf}
14409f2cdcbbSJosh Poimboeuf
14419f2cdcbbSJosh Poimboeufsub exec_console {
14429f2cdcbbSJosh Poimboeuf    my ($ptm, $pts) = @_;
14439f2cdcbbSJosh Poimboeuf
14449f2cdcbbSJosh Poimboeuf    close($ptm);
14459f2cdcbbSJosh Poimboeuf
14469f2cdcbbSJosh Poimboeuf    close(\*STDIN);
14479f2cdcbbSJosh Poimboeuf    close(\*STDOUT);
14489f2cdcbbSJosh Poimboeuf    close(\*STDERR);
14499f2cdcbbSJosh Poimboeuf
14509f2cdcbbSJosh Poimboeuf    open(\*STDIN, '<&', $pts);
14519f2cdcbbSJosh Poimboeuf    open(\*STDOUT, '>&', $pts);
14529f2cdcbbSJosh Poimboeuf    open(\*STDERR, '>&', $pts);
14539f2cdcbbSJosh Poimboeuf
14549f2cdcbbSJosh Poimboeuf    close($pts);
14559f2cdcbbSJosh Poimboeuf
14569f2cdcbbSJosh Poimboeuf    exec $console or
1457*1cb9e642SJosh Poimboeuf	die "Can't open console $console";
14589f2cdcbbSJosh Poimboeuf}
14599f2cdcbbSJosh Poimboeuf
14609f2cdcbbSJosh Poimboeufsub open_console {
14619f2cdcbbSJosh Poimboeuf    my ($ptm) = @_;
14629f2cdcbbSJosh Poimboeuf    my $pts = \*PTSFD;
14639f2cdcbbSJosh Poimboeuf    my $pid;
14647faafbd6SSteven Rostedt
146598842782SJosh Poimboeuf    # save terminal settings
14669d2f7f05SJosh Poimboeuf    $stty_orig = `stty -g`;
14679d2f7f05SJosh Poimboeuf
14689d2f7f05SJosh Poimboeuf    # place terminal in cbreak mode so that stdin can be read one character at
14699d2f7f05SJosh Poimboeuf    # a time without having to wait for a newline
14709d2f7f05SJosh Poimboeuf    system("stty -icanon -echo -icrnl");
147198842782SJosh Poimboeuf
14729f2cdcbbSJosh Poimboeuf    create_pty($ptm, $pts);
14737faafbd6SSteven Rostedt
14749f2cdcbbSJosh Poimboeuf    $pid = fork;
14759f2cdcbbSJosh Poimboeuf
14769f2cdcbbSJosh Poimboeuf    if (!$pid) {
14779f2cdcbbSJosh Poimboeuf	# child
14789f2cdcbbSJosh Poimboeuf	exec_console($ptm, $pts)
14799f2cdcbbSJosh Poimboeuf    }
14809f2cdcbbSJosh Poimboeuf
14819f2cdcbbSJosh Poimboeuf    # parent
14829f2cdcbbSJosh Poimboeuf    close($pts);
14837faafbd6SSteven Rostedt
14847faafbd6SSteven Rostedt    return $pid;
14859f2cdcbbSJosh Poimboeuf
14869f2cdcbbSJosh Poimboeuf    open(PTSFD, "Stop perl from warning about single use of PTSFD");
14877faafbd6SSteven Rostedt}
14887faafbd6SSteven Rostedt
14897faafbd6SSteven Rostedtsub close_console {
14907faafbd6SSteven Rostedt    my ($fp, $pid) = @_;
14917faafbd6SSteven Rostedt
14927faafbd6SSteven Rostedt    doprint "kill child process $pid\n";
14935a5d8e48SSatoru Takeuchi    kill $close_console_signal, $pid;
14947faafbd6SSteven Rostedt
14957faafbd6SSteven Rostedt    print "closing!\n";
14967faafbd6SSteven Rostedt    close($fp);
149798842782SJosh Poimboeuf
149898842782SJosh Poimboeuf    # restore terminal settings
14999d2f7f05SJosh Poimboeuf    system("stty $stty_orig");
15007faafbd6SSteven Rostedt}
15017faafbd6SSteven Rostedt
15027faafbd6SSteven Rostedtsub start_monitor {
15037faafbd6SSteven Rostedt    if ($monitor_cnt++) {
15047faafbd6SSteven Rostedt	return;
15057faafbd6SSteven Rostedt    }
15067faafbd6SSteven Rostedt    $monitor_fp = \*MONFD;
15077faafbd6SSteven Rostedt    $monitor_pid = open_console $monitor_fp;
1508a75fececSSteven Rostedt
1509a75fececSSteven Rostedt    return;
1510a75fececSSteven Rostedt
1511a75fececSSteven Rostedt    open(MONFD, "Stop perl from warning about single use of MONFD");
15127faafbd6SSteven Rostedt}
15137faafbd6SSteven Rostedt
15147faafbd6SSteven Rostedtsub end_monitor {
1515319ab14fSSteven Rostedt (Red Hat)    return if (!defined $console);
15167faafbd6SSteven Rostedt    if (--$monitor_cnt) {
15177faafbd6SSteven Rostedt	return;
15187faafbd6SSteven Rostedt    }
15197faafbd6SSteven Rostedt    close_console($monitor_fp, $monitor_pid);
15207faafbd6SSteven Rostedt}
15217faafbd6SSteven Rostedt
15227faafbd6SSteven Rostedtsub wait_for_monitor {
15232b803365SSteven Rostedt    my ($time, $stop) = @_;
15242b803365SSteven Rostedt    my $full_line = "";
15257faafbd6SSteven Rostedt    my $line;
15262b803365SSteven Rostedt    my $booted = 0;
1527407b95b7SSteven Rostedt    my $start_time = time;
15288a80c727SSteven Rostedt    my $skip_call_trace = 0;
15298a80c727SSteven Rostedt    my $bug = 0;
15308a80c727SSteven Rostedt    my $bug_ignored = 0;
1531407b95b7SSteven Rostedt    my $now;
15327faafbd6SSteven Rostedt
1533a75fececSSteven Rostedt    doprint "** Wait for monitor to settle down **\n";
15347faafbd6SSteven Rostedt
15357faafbd6SSteven Rostedt    # read the monitor and wait for the system to calm down
15362b803365SSteven Rostedt    while (!$booted) {
15377faafbd6SSteven Rostedt	$line = wait_for_input($monitor_fp, $time);
15382b803365SSteven Rostedt	last if (!defined($line));
15392b803365SSteven Rostedt	print "$line";
15402b803365SSteven Rostedt	$full_line .= $line;
15412b803365SSteven Rostedt
15422b803365SSteven Rostedt	if (defined($stop) && $full_line =~ /$stop/) {
15432b803365SSteven Rostedt	    doprint "wait for monitor detected $stop\n";
15442b803365SSteven Rostedt	    $booted = 1;
15452b803365SSteven Rostedt	}
15462b803365SSteven Rostedt
15478a80c727SSteven Rostedt	if ($full_line =~ /\[ backtrace testing \]/) {
15488a80c727SSteven Rostedt	    $skip_call_trace = 1;
15498a80c727SSteven Rostedt	}
15508a80c727SSteven Rostedt
15518a80c727SSteven Rostedt	if ($full_line =~ /call trace:/i) {
15528a80c727SSteven Rostedt	    if (!$bug && !$skip_call_trace) {
15538a80c727SSteven Rostedt		if ($ignore_errors) {
15548a80c727SSteven Rostedt		    $bug_ignored = 1;
15558a80c727SSteven Rostedt		} else {
15568a80c727SSteven Rostedt		    $bug = 1;
15578a80c727SSteven Rostedt		}
15588a80c727SSteven Rostedt	    }
15598a80c727SSteven Rostedt	}
15608a80c727SSteven Rostedt
15618a80c727SSteven Rostedt	if ($full_line =~ /\[ end of backtrace testing \]/) {
15628a80c727SSteven Rostedt	    $skip_call_trace = 0;
15638a80c727SSteven Rostedt	}
15648a80c727SSteven Rostedt
15658a80c727SSteven Rostedt	if ($full_line =~ /Kernel panic -/) {
15668a80c727SSteven Rostedt	    $bug = 1;
15678a80c727SSteven Rostedt	}
15688a80c727SSteven Rostedt
15692b803365SSteven Rostedt	if ($line =~ /\n/) {
15702b803365SSteven Rostedt	    $full_line = "";
15712b803365SSteven Rostedt	}
1572407b95b7SSteven Rostedt	$now = time;
1573407b95b7SSteven Rostedt	if ($now - $start_time >= $max_monitor_wait) {
1574407b95b7SSteven Rostedt	    doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1575407b95b7SSteven Rostedt	    return 1;
1576407b95b7SSteven Rostedt	}
15772b803365SSteven Rostedt    }
1578a75fececSSteven Rostedt    print "** Monitor flushed **\n";
1579995bc431SSteven Rostedt (Red Hat)
1580995bc431SSteven Rostedt (Red Hat)    # if stop is defined but wasn't hit, return error
1581995bc431SSteven Rostedt (Red Hat)    # used by reboot (which wants to see a reboot)
1582995bc431SSteven Rostedt (Red Hat)    if (defined($stop) && !$booted) {
1583995bc431SSteven Rostedt (Red Hat)	$bug = 1;
1584995bc431SSteven Rostedt (Red Hat)    }
15858a80c727SSteven Rostedt    return $bug;
15867faafbd6SSteven Rostedt}
15877faafbd6SSteven Rostedt
1588de5b6e3bSRabin Vincentsub save_logs {
1589de5b6e3bSRabin Vincent	my ($result, $basedir) = @_;
1590de5b6e3bSRabin Vincent	my @t = localtime;
1591de5b6e3bSRabin Vincent	my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1592de5b6e3bSRabin Vincent		1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1593de5b6e3bSRabin Vincent
1594de5b6e3bSRabin Vincent	my $type = $build_type;
1595de5b6e3bSRabin Vincent	if ($type =~ /useconfig/) {
1596de5b6e3bSRabin Vincent	    $type = "useconfig";
1597de5b6e3bSRabin Vincent	}
1598de5b6e3bSRabin Vincent
1599de5b6e3bSRabin Vincent	my $dir = "$machine-$test_type-$type-$result-$date";
1600de5b6e3bSRabin Vincent
1601de5b6e3bSRabin Vincent	$dir = "$basedir/$dir";
1602de5b6e3bSRabin Vincent
1603de5b6e3bSRabin Vincent	if (!-d $dir) {
1604de5b6e3bSRabin Vincent	    mkpath($dir) or
1605de5b6e3bSRabin Vincent		die "can't create $dir";
1606de5b6e3bSRabin Vincent	}
1607de5b6e3bSRabin Vincent
1608de5b6e3bSRabin Vincent	my %files = (
1609de5b6e3bSRabin Vincent		"config" => $output_config,
1610de5b6e3bSRabin Vincent		"buildlog" => $buildlog,
1611de5b6e3bSRabin Vincent		"dmesg" => $dmesg,
1612de5b6e3bSRabin Vincent		"testlog" => $testlog,
1613de5b6e3bSRabin Vincent	);
1614de5b6e3bSRabin Vincent
1615de5b6e3bSRabin Vincent	while (my ($name, $source) = each(%files)) {
1616de5b6e3bSRabin Vincent		if (-f "$source") {
1617de5b6e3bSRabin Vincent			cp "$source", "$dir/$name" or
1618de5b6e3bSRabin Vincent				die "failed to copy $source";
1619de5b6e3bSRabin Vincent		}
1620de5b6e3bSRabin Vincent	}
1621de5b6e3bSRabin Vincent
1622de5b6e3bSRabin Vincent	doprint "*** Saved info to $dir ***\n";
1623de5b6e3bSRabin Vincent}
1624de5b6e3bSRabin Vincent
16252b7d9b21SSteven Rostedtsub fail {
16262b7d9b21SSteven Rostedt
1627921ed4c7SSteven Rostedt	if (defined($post_test)) {
1628921ed4c7SSteven Rostedt		run_command $post_test;
1629921ed4c7SSteven Rostedt	}
1630921ed4c7SSteven Rostedt
1631a75fececSSteven Rostedt	if ($die_on_failure) {
16322b7d9b21SSteven Rostedt		dodie @_;
16332b7d9b21SSteven Rostedt	}
16342b7d9b21SSteven Rostedt
1635a75fececSSteven Rostedt	doprint "FAILED\n";
16367faafbd6SSteven Rostedt
1637576f627cSSteven Rostedt	my $i = $iteration;
1638576f627cSSteven Rostedt
1639a75fececSSteven Rostedt	# no need to reboot for just building.
1640576f627cSSteven Rostedt	if (!do_not_reboot) {
16417faafbd6SSteven Rostedt	    doprint "REBOOTING\n";
1642bc7c5803SSteven Rostedt	    reboot_to_good $sleep_time;
1643a75fececSSteven Rostedt	}
16447faafbd6SSteven Rostedt
16459064af52SSteven Rostedt	my $name = "";
16469064af52SSteven Rostedt
16479064af52SSteven Rostedt	if (defined($test_name)) {
16489064af52SSteven Rostedt	    $name = " ($test_name)";
16499064af52SSteven Rostedt	}
16509064af52SSteven Rostedt
16514bf6e1fcSSteven Rostedt (Red Hat)	print_times;
16524bf6e1fcSSteven Rostedt (Red Hat)
1653576f627cSSteven Rostedt	doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1654576f627cSSteven Rostedt	doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
16559064af52SSteven Rostedt	doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1656576f627cSSteven Rostedt	doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1657576f627cSSteven Rostedt	doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1658a75fececSSteven Rostedt
1659de5b6e3bSRabin Vincent	if (defined($store_failures)) {
1660de5b6e3bSRabin Vincent	    save_logs "fail", $store_failures;
1661cccae1a6SSteven Rostedt        }
1662cccae1a6SSteven Rostedt
16632b7d9b21SSteven Rostedt	return 1;
16642b7d9b21SSteven Rostedt}
16652b7d9b21SSteven Rostedt
16662545eb61SSteven Rostedtsub run_command {
1667f983a2bcSSatoru Takeuchi    my ($command, $redirect) = @_;
1668b53486e0SSteven Rostedt (Red Hat)    my $start_time;
1669b53486e0SSteven Rostedt (Red Hat)    my $end_time;
1670d6ce2a0bSSteven Rostedt    my $dolog = 0;
1671d6ce2a0bSSteven Rostedt    my $dord = 0;
1672d6ce2a0bSSteven Rostedt    my $pid;
1673d6ce2a0bSSteven Rostedt
1674b53486e0SSteven Rostedt (Red Hat)    $start_time = time;
1675b53486e0SSteven Rostedt (Red Hat)
1676e48c5293SSteven Rostedt    $command =~ s/\$SSH_USER/$ssh_user/g;
1677e48c5293SSteven Rostedt    $command =~ s/\$MACHINE/$machine/g;
1678e48c5293SSteven Rostedt
1679d6ce2a0bSSteven Rostedt    doprint("$command ... ");
1680d6ce2a0bSSteven Rostedt
1681d6ce2a0bSSteven Rostedt    $pid = open(CMD, "$command 2>&1 |") or
16822b7d9b21SSteven Rostedt	(fail "unable to exec $command" and return 0);
16832545eb61SSteven Rostedt
16842545eb61SSteven Rostedt    if (defined($opt{"LOG_FILE"})) {
1685d6ce2a0bSSteven Rostedt	open(LOG, ">>$opt{LOG_FILE}") or
1686d6ce2a0bSSteven Rostedt	    dodie "failed to write to log";
1687d6ce2a0bSSteven Rostedt	$dolog = 1;
16886c5ee0beSSteven Rostedt    }
16896c5ee0beSSteven Rostedt
16906c5ee0beSSteven Rostedt    if (defined($redirect)) {
1691d6ce2a0bSSteven Rostedt	open (RD, ">$redirect") or
1692d6ce2a0bSSteven Rostedt	    dodie "failed to write to redirect $redirect";
1693d6ce2a0bSSteven Rostedt	$dord = 1;
16942545eb61SSteven Rostedt    }
16952545eb61SSteven Rostedt
1696d6ce2a0bSSteven Rostedt    while (<CMD>) {
1697d6ce2a0bSSteven Rostedt	print LOG if ($dolog);
1698d6ce2a0bSSteven Rostedt	print RD  if ($dord);
1699d6ce2a0bSSteven Rostedt    }
17002545eb61SSteven Rostedt
1701d6ce2a0bSSteven Rostedt    waitpid($pid, 0);
17022545eb61SSteven Rostedt    my $failed = $?;
17032545eb61SSteven Rostedt
1704d6ce2a0bSSteven Rostedt    close(CMD);
1705d6ce2a0bSSteven Rostedt    close(LOG) if ($dolog);
1706d6ce2a0bSSteven Rostedt    close(RD)  if ($dord);
1707d6ce2a0bSSteven Rostedt
1708b53486e0SSteven Rostedt (Red Hat)    $end_time = time;
1709b53486e0SSteven Rostedt (Red Hat)    my $delta = $end_time - $start_time;
1710b53486e0SSteven Rostedt (Red Hat)
1711b53486e0SSteven Rostedt (Red Hat)    if ($delta == 1) {
1712b53486e0SSteven Rostedt (Red Hat)	doprint "[1 second] ";
1713b53486e0SSteven Rostedt (Red Hat)    } else {
1714b53486e0SSteven Rostedt (Red Hat)	doprint "[$delta seconds] ";
1715b53486e0SSteven Rostedt (Red Hat)    }
1716b53486e0SSteven Rostedt (Red Hat)
17172545eb61SSteven Rostedt    if ($failed) {
17182545eb61SSteven Rostedt	doprint "FAILED!\n";
17192545eb61SSteven Rostedt    } else {
17202545eb61SSteven Rostedt	doprint "SUCCESS\n";
17212545eb61SSteven Rostedt    }
17222545eb61SSteven Rostedt
17235f9b6cedSSteven Rostedt    return !$failed;
17245f9b6cedSSteven Rostedt}
17255f9b6cedSSteven Rostedt
1726e48c5293SSteven Rostedtsub run_ssh {
1727e48c5293SSteven Rostedt    my ($cmd) = @_;
1728e48c5293SSteven Rostedt    my $cp_exec = $ssh_exec;
1729e48c5293SSteven Rostedt
1730e48c5293SSteven Rostedt    $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1731e48c5293SSteven Rostedt    return run_command "$cp_exec";
1732e48c5293SSteven Rostedt}
1733e48c5293SSteven Rostedt
1734e48c5293SSteven Rostedtsub run_scp {
173502ad2617SSteven Rostedt    my ($src, $dst, $cp_scp) = @_;
1736e48c5293SSteven Rostedt
1737e48c5293SSteven Rostedt    $cp_scp =~ s/\$SRC_FILE/$src/g;
1738e48c5293SSteven Rostedt    $cp_scp =~ s/\$DST_FILE/$dst/g;
1739e48c5293SSteven Rostedt
1740e48c5293SSteven Rostedt    return run_command "$cp_scp";
1741e48c5293SSteven Rostedt}
1742e48c5293SSteven Rostedt
174302ad2617SSteven Rostedtsub run_scp_install {
174402ad2617SSteven Rostedt    my ($src, $dst) = @_;
174502ad2617SSteven Rostedt
174602ad2617SSteven Rostedt    my $cp_scp = $scp_to_target_install;
174702ad2617SSteven Rostedt
174802ad2617SSteven Rostedt    return run_scp($src, $dst, $cp_scp);
174902ad2617SSteven Rostedt}
175002ad2617SSteven Rostedt
175102ad2617SSteven Rostedtsub run_scp_mod {
175202ad2617SSteven Rostedt    my ($src, $dst) = @_;
175302ad2617SSteven Rostedt
175402ad2617SSteven Rostedt    my $cp_scp = $scp_to_target;
175502ad2617SSteven Rostedt
175602ad2617SSteven Rostedt    return run_scp($src, $dst, $cp_scp);
175702ad2617SSteven Rostedt}
175802ad2617SSteven Rostedt
1759a15ba913SSteven Rostedtsub get_grub2_index {
1760a15ba913SSteven Rostedt
1761752d9665SSteven Rostedt (Red Hat)    return if (defined($grub_number) && defined($last_grub_menu) &&
1762df5f7c66SSteven Rostedt (Red Hat)	       $last_grub_menu eq $grub_menu && defined($last_machine) &&
1763df5f7c66SSteven Rostedt (Red Hat)	       $last_machine eq $machine);
1764a15ba913SSteven Rostedt
1765a15ba913SSteven Rostedt    doprint "Find grub2 menu ... ";
1766a15ba913SSteven Rostedt    $grub_number = -1;
1767a15ba913SSteven Rostedt
1768a15ba913SSteven Rostedt    my $ssh_grub = $ssh_exec;
1769a15ba913SSteven Rostedt    $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1770a15ba913SSteven Rostedt
1771a15ba913SSteven Rostedt    open(IN, "$ssh_grub |")
1772a15ba913SSteven Rostedt	or die "unable to get $grub_file";
1773a15ba913SSteven Rostedt
1774a15ba913SSteven Rostedt    my $found = 0;
1775a15ba913SSteven Rostedt
1776a15ba913SSteven Rostedt    while (<IN>) {
1777a15ba913SSteven Rostedt	if (/^menuentry.*$grub_menu/) {
1778a15ba913SSteven Rostedt	    $grub_number++;
1779a15ba913SSteven Rostedt	    $found = 1;
1780a15ba913SSteven Rostedt	    last;
1781a15ba913SSteven Rostedt	} elsif (/^menuentry\s/) {
1782a15ba913SSteven Rostedt	    $grub_number++;
1783a15ba913SSteven Rostedt	}
1784a15ba913SSteven Rostedt    }
1785a15ba913SSteven Rostedt    close(IN);
1786a15ba913SSteven Rostedt
1787a15ba913SSteven Rostedt    die "Could not find '$grub_menu' in $grub_file on $machine"
1788a15ba913SSteven Rostedt	if (!$found);
1789a15ba913SSteven Rostedt    doprint "$grub_number\n";
1790752d9665SSteven Rostedt (Red Hat)    $last_grub_menu = $grub_menu;
1791df5f7c66SSteven Rostedt (Red Hat)    $last_machine = $machine;
1792a15ba913SSteven Rostedt}
1793a15ba913SSteven Rostedt
17945f9b6cedSSteven Rostedtsub get_grub_index {
17955f9b6cedSSteven Rostedt
1796a15ba913SSteven Rostedt    if ($reboot_type eq "grub2") {
1797a15ba913SSteven Rostedt	get_grub2_index;
1798a15ba913SSteven Rostedt	return;
1799a15ba913SSteven Rostedt    }
1800a15ba913SSteven Rostedt
1801a75fececSSteven Rostedt    if ($reboot_type ne "grub") {
1802a75fececSSteven Rostedt	return;
1803a75fececSSteven 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);
18075f9b6cedSSteven Rostedt
18085f9b6cedSSteven Rostedt    doprint "Find grub menu ... ";
18095f9b6cedSSteven Rostedt    $grub_number = -1;
1810e48c5293SSteven Rostedt
1811e48c5293SSteven Rostedt    my $ssh_grub = $ssh_exec;
1812e48c5293SSteven Rostedt    $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1813e48c5293SSteven Rostedt
1814e48c5293SSteven Rostedt    open(IN, "$ssh_grub |")
18155f9b6cedSSteven Rostedt	or die "unable to get menu.lst";
1816e48c5293SSteven Rostedt
1817eaa1fe25SSteven Rostedt    my $found = 0;
1818eaa1fe25SSteven Rostedt
18195f9b6cedSSteven Rostedt    while (<IN>) {
1820a75fececSSteven Rostedt	if (/^\s*title\s+$grub_menu\s*$/) {
18215f9b6cedSSteven Rostedt	    $grub_number++;
1822eaa1fe25SSteven Rostedt	    $found = 1;
18235f9b6cedSSteven Rostedt	    last;
18245f9b6cedSSteven Rostedt	} elsif (/^\s*title\s/) {
18255f9b6cedSSteven Rostedt	    $grub_number++;
18265f9b6cedSSteven Rostedt	}
18275f9b6cedSSteven Rostedt    }
18285f9b6cedSSteven Rostedt    close(IN);
18295f9b6cedSSteven Rostedt
1830a75fececSSteven Rostedt    die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1831eaa1fe25SSteven Rostedt	if (!$found);
18325f9b6cedSSteven Rostedt    doprint "$grub_number\n";
1833752d9665SSteven Rostedt (Red Hat)    $last_grub_menu = $grub_menu;
1834df5f7c66SSteven Rostedt (Red Hat)    $last_machine = $machine;
18352545eb61SSteven Rostedt}
18362545eb61SSteven Rostedt
18372545eb61SSteven Rostedtsub wait_for_input
18382545eb61SSteven Rostedt{
18392545eb61SSteven Rostedt    my ($fp, $time) = @_;
18402545eb61SSteven Rostedt    my $rin;
18419d2f7f05SJosh Poimboeuf    my $rout;
18429d2f7f05SJosh Poimboeuf    my $nr;
18439d2f7f05SJosh Poimboeuf    my $buf;
18442545eb61SSteven Rostedt    my $line;
18452545eb61SSteven Rostedt    my $ch;
18462545eb61SSteven Rostedt
18472545eb61SSteven Rostedt    if (!defined($time)) {
18482545eb61SSteven Rostedt	$time = $timeout;
18492545eb61SSteven Rostedt    }
18502545eb61SSteven Rostedt
18512545eb61SSteven Rostedt    $rin = '';
18522545eb61SSteven Rostedt    vec($rin, fileno($fp), 1) = 1;
18539d2f7f05SJosh Poimboeuf    vec($rin, fileno(\*STDIN), 1) = 1;
18549d2f7f05SJosh Poimboeuf
18559d2f7f05SJosh Poimboeuf    while (1) {
18569d2f7f05SJosh Poimboeuf	$nr = select($rout=$rin, undef, undef, $time);
18579d2f7f05SJosh Poimboeuf
18589d2f7f05SJosh Poimboeuf	if ($nr <= 0) {
18599d2f7f05SJosh Poimboeuf	    return undef;
18609d2f7f05SJosh Poimboeuf	}
18619d2f7f05SJosh Poimboeuf
18629d2f7f05SJosh Poimboeuf	# copy data from stdin to the console
18639d2f7f05SJosh Poimboeuf	if (vec($rout, fileno(\*STDIN), 1) == 1) {
18649d2f7f05SJosh Poimboeuf	    sysread(\*STDIN, $buf, 1000);
18659d2f7f05SJosh Poimboeuf	    syswrite($fp, $buf, 1000);
18669d2f7f05SJosh Poimboeuf	    next;
18679d2f7f05SJosh Poimboeuf	}
18682545eb61SSteven Rostedt
18692545eb61SSteven Rostedt	$line = "";
18702545eb61SSteven Rostedt
18712545eb61SSteven Rostedt	# try to read one char at a time
18722545eb61SSteven Rostedt	while (sysread $fp, $ch, 1) {
18732545eb61SSteven Rostedt	    $line .= $ch;
18742545eb61SSteven Rostedt	    last if ($ch eq "\n");
18752545eb61SSteven Rostedt	}
18762545eb61SSteven Rostedt
18772545eb61SSteven Rostedt	if (!length($line)) {
18782545eb61SSteven Rostedt	    return undef;
18792545eb61SSteven Rostedt	}
18802545eb61SSteven Rostedt
18812545eb61SSteven Rostedt	return $line;
18822545eb61SSteven Rostedt    }
18839d2f7f05SJosh Poimboeuf}
18842545eb61SSteven Rostedt
188575c3fda7SSteven Rostedtsub reboot_to {
1886bc7c5803SSteven Rostedt    if (defined($switch_to_test)) {
1887bc7c5803SSteven Rostedt	run_command $switch_to_test;
1888bc7c5803SSteven Rostedt    }
1889bc7c5803SSteven Rostedt
1890a75fececSSteven Rostedt    if ($reboot_type eq "grub") {
1891c54367f9SSteven Rostedt	run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1892a15ba913SSteven Rostedt    } elsif ($reboot_type eq "grub2") {
1893a15ba913SSteven Rostedt	run_ssh "$grub_reboot $grub_number";
18947786954cSSteven Rostedt    } elsif ($reboot_type eq "syslinux") {
18957786954cSSteven Rostedt	run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
189696f6a0dfSSteven Rostedt    } elsif (defined $reboot_script) {
1897a75fececSSteven Rostedt	run_command "$reboot_script";
18982545eb61SSteven Rostedt    }
189996f6a0dfSSteven Rostedt    reboot;
190096f6a0dfSSteven Rostedt}
19012545eb61SSteven Rostedt
1902a57419b3SSteven Rostedtsub get_sha1 {
1903a57419b3SSteven Rostedt    my ($commit) = @_;
1904a57419b3SSteven Rostedt
1905a57419b3SSteven Rostedt    doprint "git rev-list --max-count=1 $commit ... ";
1906a57419b3SSteven Rostedt    my $sha1 = `git rev-list --max-count=1 $commit`;
1907a57419b3SSteven Rostedt    my $ret = $?;
1908a57419b3SSteven Rostedt
1909a57419b3SSteven Rostedt    logit $sha1;
1910a57419b3SSteven Rostedt
1911a57419b3SSteven Rostedt    if ($ret) {
1912a57419b3SSteven Rostedt	doprint "FAILED\n";
1913a57419b3SSteven Rostedt	dodie "Failed to get git $commit";
1914a57419b3SSteven Rostedt    }
1915a57419b3SSteven Rostedt
1916a57419b3SSteven Rostedt    print "SUCCESS\n";
1917a57419b3SSteven Rostedt
1918a57419b3SSteven Rostedt    chomp $sha1;
1919a57419b3SSteven Rostedt
1920a57419b3SSteven Rostedt    return $sha1;
1921a57419b3SSteven Rostedt}
1922a57419b3SSteven Rostedt
19235a391fbfSSteven Rostedtsub monitor {
19242545eb61SSteven Rostedt    my $booted = 0;
19252545eb61SSteven Rostedt    my $bug = 0;
19266ca996ccSSteven Rostedt    my $bug_ignored = 0;
19275c42fc5bSSteven Rostedt    my $skip_call_trace = 0;
19282b7d9b21SSteven Rostedt    my $loops;
19292545eb61SSteven Rostedt
193038fa3dc1SSteven Rostedt (Red Hat)    my $start_time = time;
193138fa3dc1SSteven Rostedt (Red Hat)
19327faafbd6SSteven Rostedt    wait_for_monitor 5;
19332545eb61SSteven Rostedt
19342545eb61SSteven Rostedt    my $line;
19352545eb61SSteven Rostedt    my $full_line = "";
19362545eb61SSteven Rostedt
19377faafbd6SSteven Rostedt    open(DMESG, "> $dmesg") or
19387faafbd6SSteven Rostedt	die "unable to write to $dmesg";
19392545eb61SSteven Rostedt
194075c3fda7SSteven Rostedt    reboot_to;
19412545eb61SSteven Rostedt
19421c8a617aSSteven Rostedt    my $success_start;
19431c8a617aSSteven Rostedt    my $failure_start;
19442d01b26aSSteven Rostedt    my $monitor_start = time;
19452d01b26aSSteven Rostedt    my $done = 0;
1946f1a5b962SSteven Rostedt    my $version_found = 0;
19471c8a617aSSteven Rostedt
19482d01b26aSSteven Rostedt    while (!$done) {
19492545eb61SSteven Rostedt
1950ecaf8e52SSteven Rostedt	if ($bug && defined($stop_after_failure) &&
1951ecaf8e52SSteven Rostedt	    $stop_after_failure >= 0) {
1952ecaf8e52SSteven Rostedt	    my $time = $stop_after_failure - (time - $failure_start);
1953ecaf8e52SSteven Rostedt	    $line = wait_for_input($monitor_fp, $time);
1954ecaf8e52SSteven Rostedt	    if (!defined($line)) {
1955ecaf8e52SSteven Rostedt		doprint "bug timed out after $booted_timeout seconds\n";
1956ecaf8e52SSteven Rostedt		doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1957ecaf8e52SSteven Rostedt		last;
1958ecaf8e52SSteven Rostedt	    }
1959ecaf8e52SSteven Rostedt	} elsif ($booted) {
1960a75fececSSteven Rostedt	    $line = wait_for_input($monitor_fp, $booted_timeout);
1961cd4f1d53SSteven Rostedt	    if (!defined($line)) {
1962cd4f1d53SSteven Rostedt		my $s = $booted_timeout == 1 ? "" : "s";
1963cd4f1d53SSteven Rostedt		doprint "Successful boot found: break after $booted_timeout second$s\n";
1964cd4f1d53SSteven Rostedt		last;
1965cd4f1d53SSteven Rostedt	    }
19662b7d9b21SSteven Rostedt	} else {
19677faafbd6SSteven Rostedt	    $line = wait_for_input($monitor_fp);
1968cd4f1d53SSteven Rostedt	    if (!defined($line)) {
1969cd4f1d53SSteven Rostedt		my $s = $timeout == 1 ? "" : "s";
1970cd4f1d53SSteven Rostedt		doprint "Timed out after $timeout second$s\n";
1971cd4f1d53SSteven Rostedt		last;
19722b7d9b21SSteven Rostedt	    }
1973cd4f1d53SSteven Rostedt	}
19742545eb61SSteven Rostedt
19752545eb61SSteven Rostedt	doprint $line;
19767faafbd6SSteven Rostedt	print DMESG $line;
19772545eb61SSteven Rostedt
19782545eb61SSteven Rostedt	# we are not guaranteed to get a full line
19792545eb61SSteven Rostedt	$full_line .= $line;
19802545eb61SSteven Rostedt
1981a75fececSSteven Rostedt	if ($full_line =~ /$success_line/) {
19822545eb61SSteven Rostedt	    $booted = 1;
19831c8a617aSSteven Rostedt	    $success_start = time;
19841c8a617aSSteven Rostedt	}
19851c8a617aSSteven Rostedt
19861c8a617aSSteven Rostedt	if ($booted && defined($stop_after_success) &&
19871c8a617aSSteven Rostedt	    $stop_after_success >= 0) {
19881c8a617aSSteven Rostedt	    my $now = time;
19891c8a617aSSteven Rostedt	    if ($now - $success_start >= $stop_after_success) {
19901c8a617aSSteven Rostedt		doprint "Test forced to stop after $stop_after_success seconds after success\n";
19911c8a617aSSteven Rostedt		last;
19921c8a617aSSteven Rostedt	    }
19932545eb61SSteven Rostedt	}
19942545eb61SSteven Rostedt
19955c42fc5bSSteven Rostedt	if ($full_line =~ /\[ backtrace testing \]/) {
19965c42fc5bSSteven Rostedt	    $skip_call_trace = 1;
19975c42fc5bSSteven Rostedt	}
19985c42fc5bSSteven Rostedt
19992545eb61SSteven Rostedt	if ($full_line =~ /call trace:/i) {
20006ca996ccSSteven Rostedt	    if (!$bug && !$skip_call_trace) {
20016ca996ccSSteven Rostedt		if ($ignore_errors) {
20026ca996ccSSteven Rostedt		    $bug_ignored = 1;
20036ca996ccSSteven Rostedt		} else {
20041c8a617aSSteven Rostedt		    $bug = 1;
20051c8a617aSSteven Rostedt		    $failure_start = time;
20061c8a617aSSteven Rostedt		}
20071c8a617aSSteven Rostedt	    }
20086ca996ccSSteven Rostedt	}
20091c8a617aSSteven Rostedt
20101c8a617aSSteven Rostedt	if ($bug && defined($stop_after_failure) &&
20111c8a617aSSteven Rostedt	    $stop_after_failure >= 0) {
20121c8a617aSSteven Rostedt	    my $now = time;
20131c8a617aSSteven Rostedt	    if ($now - $failure_start >= $stop_after_failure) {
20141c8a617aSSteven Rostedt		doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
20151c8a617aSSteven Rostedt		last;
20161c8a617aSSteven Rostedt	    }
20175c42fc5bSSteven Rostedt	}
20185c42fc5bSSteven Rostedt
20195c42fc5bSSteven Rostedt	if ($full_line =~ /\[ end of backtrace testing \]/) {
20205c42fc5bSSteven Rostedt	    $skip_call_trace = 0;
20215c42fc5bSSteven Rostedt	}
20225c42fc5bSSteven Rostedt
20235c42fc5bSSteven Rostedt	if ($full_line =~ /Kernel panic -/) {
202410abf118SSteven Rostedt	    $failure_start = time;
20252545eb61SSteven Rostedt	    $bug = 1;
20262545eb61SSteven Rostedt	}
20272545eb61SSteven Rostedt
2028f1a5b962SSteven Rostedt	# Detect triple faults by testing the banner
2029f1a5b962SSteven Rostedt	if ($full_line =~ /\bLinux version (\S+).*\n/) {
2030f1a5b962SSteven Rostedt	    if ($1 eq $version) {
2031f1a5b962SSteven Rostedt		$version_found = 1;
2032f1a5b962SSteven Rostedt	    } elsif ($version_found && $detect_triplefault) {
2033f1a5b962SSteven Rostedt		# We already booted into the kernel we are testing,
2034f1a5b962SSteven Rostedt		# but now we booted into another kernel?
2035f1a5b962SSteven Rostedt		# Consider this a triple fault.
20368b513d0cSMasanari Iida		doprint "Already booted in Linux kernel $version, but now\n";
2037f1a5b962SSteven Rostedt		doprint "we booted into Linux kernel $1.\n";
2038f1a5b962SSteven Rostedt		doprint "Assuming that this is a triple fault.\n";
2039f1a5b962SSteven Rostedt		doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
2040f1a5b962SSteven Rostedt		last;
2041f1a5b962SSteven Rostedt	    }
2042f1a5b962SSteven Rostedt	}
2043f1a5b962SSteven Rostedt
20442545eb61SSteven Rostedt	if ($line =~ /\n/) {
20452545eb61SSteven Rostedt	    $full_line = "";
20462545eb61SSteven Rostedt	}
20472d01b26aSSteven Rostedt
20482d01b26aSSteven Rostedt	if ($stop_test_after > 0 && !$booted && !$bug) {
20492d01b26aSSteven Rostedt	    if (time - $monitor_start > $stop_test_after) {
20504d62bf51SSteven Rostedt		doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
20512d01b26aSSteven Rostedt		$done = 1;
20522d01b26aSSteven Rostedt	    }
20532d01b26aSSteven Rostedt	}
20542545eb61SSteven Rostedt    }
20552545eb61SSteven Rostedt
205638fa3dc1SSteven Rostedt (Red Hat)    my $end_time = time;
205738fa3dc1SSteven Rostedt (Red Hat)    $reboot_time = $end_time - $start_time;
205838fa3dc1SSteven Rostedt (Red Hat)
20597faafbd6SSteven Rostedt    close(DMESG);
20602545eb61SSteven Rostedt
20612545eb61SSteven Rostedt    if ($bug) {
20622b7d9b21SSteven Rostedt	return 0 if ($in_bisect);
2063576f627cSSteven Rostedt	fail "failed - got a bug report" and return 0;
20642545eb61SSteven Rostedt    }
20655f9b6cedSSteven Rostedt
2066a75fececSSteven Rostedt    if (!$booted) {
2067a75fececSSteven Rostedt	return 0 if ($in_bisect);
2068576f627cSSteven Rostedt	fail "failed - never got a boot prompt." and return 0;
2069a75fececSSteven Rostedt    }
2070a75fececSSteven Rostedt
20716ca996ccSSteven Rostedt    if ($bug_ignored) {
20726ca996ccSSteven Rostedt	doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
20736ca996ccSSteven Rostedt    }
20746ca996ccSSteven Rostedt
20752b7d9b21SSteven Rostedt    return 1;
20762545eb61SSteven Rostedt}
20772545eb61SSteven Rostedt
20782b29b2f8SSteven Rostedtsub eval_kernel_version {
20792b29b2f8SSteven Rostedt    my ($option) = @_;
20802b29b2f8SSteven Rostedt
20812b29b2f8SSteven Rostedt    $option =~ s/\$KERNEL_VERSION/$version/g;
20822b29b2f8SSteven Rostedt
20832b29b2f8SSteven Rostedt    return $option;
20842b29b2f8SSteven Rostedt}
20852b29b2f8SSteven Rostedt
2086db05cfefSSteven Rostedtsub do_post_install {
2087db05cfefSSteven Rostedt
2088db05cfefSSteven Rostedt    return if (!defined($post_install));
2089db05cfefSSteven Rostedt
20902b29b2f8SSteven Rostedt    my $cp_post_install = eval_kernel_version $post_install;
2091db05cfefSSteven Rostedt    run_command "$cp_post_install" or
2092db05cfefSSteven Rostedt	dodie "Failed to run post install";
2093db05cfefSSteven Rostedt}
2094db05cfefSSteven Rostedt
2095e1a6c3d7SSteven Rostedt# Sometimes the reboot fails, and will hang. We try to ssh to the box
2096e1a6c3d7SSteven Rostedt# and if we fail, we force another reboot, that should powercycle it.
2097e1a6c3d7SSteven Rostedtsub test_booted {
2098e1a6c3d7SSteven Rostedt    if (!run_ssh "echo testing connection") {
2099e1a6c3d7SSteven Rostedt	reboot $sleep_time;
2100e1a6c3d7SSteven Rostedt    }
2101e1a6c3d7SSteven Rostedt}
2102e1a6c3d7SSteven Rostedt
21032545eb61SSteven Rostedtsub install {
21042545eb61SSteven Rostedt
2105e0a8742eSSteven Rostedt    return if ($no_install);
2106e0a8742eSSteven Rostedt
210738fa3dc1SSteven Rostedt (Red Hat)    my $start_time = time;
210838fa3dc1SSteven Rostedt (Red Hat)
2109e5c2ec11SSteven Rostedt    if (defined($pre_install)) {
2110e5c2ec11SSteven Rostedt	my $cp_pre_install = eval_kernel_version $pre_install;
2111e5c2ec11SSteven Rostedt	run_command "$cp_pre_install" or
2112e5c2ec11SSteven Rostedt	    dodie "Failed to run pre install";
2113e5c2ec11SSteven Rostedt    }
2114e5c2ec11SSteven Rostedt
21152b29b2f8SSteven Rostedt    my $cp_target = eval_kernel_version $target_image;
21162b29b2f8SSteven Rostedt
2117e1a6c3d7SSteven Rostedt    test_booted;
2118e1a6c3d7SSteven Rostedt
211902ad2617SSteven Rostedt    run_scp_install "$outputdir/$build_target", "$cp_target" or
21205c42fc5bSSteven Rostedt	dodie "failed to copy image";
21215f9b6cedSSteven Rostedt
21225f9b6cedSSteven Rostedt    my $install_mods = 0;
21235f9b6cedSSteven Rostedt
21245f9b6cedSSteven Rostedt    # should we process modules?
21255f9b6cedSSteven Rostedt    $install_mods = 0;
212651ad1dd1SSteven Rostedt    open(IN, "$output_config") or dodie("Can't read config file");
21275f9b6cedSSteven Rostedt    while (<IN>) {
21285f9b6cedSSteven Rostedt	if (/CONFIG_MODULES(=y)?/) {
21298bc5e4eaSSteven Rostedt	    if (defined($1)) {
21308bc5e4eaSSteven Rostedt		$install_mods = 1;
21315f9b6cedSSteven Rostedt		last;
21325f9b6cedSSteven Rostedt	    }
21335f9b6cedSSteven Rostedt	}
21348bc5e4eaSSteven Rostedt    }
21355f9b6cedSSteven Rostedt    close(IN);
21365f9b6cedSSteven Rostedt
21375f9b6cedSSteven Rostedt    if (!$install_mods) {
2138db05cfefSSteven Rostedt	do_post_install;
21395f9b6cedSSteven Rostedt	doprint "No modules needed\n";
214038fa3dc1SSteven Rostedt (Red Hat)	my $end_time = time;
214138fa3dc1SSteven Rostedt (Red Hat)	$install_time = $end_time - $start_time;
21425f9b6cedSSteven Rostedt	return;
21432545eb61SSteven Rostedt    }
21442545eb61SSteven Rostedt
2145627977d8SSteven Rostedt    run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
21465f9b6cedSSteven Rostedt	dodie "Failed to install modules";
21475f9b6cedSSteven Rostedt
21482545eb61SSteven Rostedt    my $modlib = "/lib/modules/$version";
2149a57419b3SSteven Rostedt    my $modtar = "ktest-mods.tar.bz2";
21502545eb61SSteven Rostedt
2151e48c5293SSteven Rostedt    run_ssh "rm -rf $modlib" or
21525c42fc5bSSteven Rostedt	dodie "failed to remove old mods: $modlib";
21532545eb61SSteven Rostedt
21545c42fc5bSSteven Rostedt    # would be nice if scp -r did not follow symbolic links
2155a75fececSSteven Rostedt    run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
21565c42fc5bSSteven Rostedt	dodie "making tarball";
21575c42fc5bSSteven Rostedt
215802ad2617SSteven Rostedt    run_scp_mod "$tmpdir/$modtar", "/tmp" or
21595c42fc5bSSteven Rostedt	dodie "failed to copy modules";
21605c42fc5bSSteven Rostedt
2161a75fececSSteven Rostedt    unlink "$tmpdir/$modtar";
21625c42fc5bSSteven Rostedt
2163e7b13441SSteven Rostedt    run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
21645c42fc5bSSteven Rostedt	dodie "failed to tar modules";
21655c42fc5bSSteven Rostedt
2166e48c5293SSteven Rostedt    run_ssh "rm -f /tmp/$modtar";
21678b37ca8cSSteven Rostedt
2168db05cfefSSteven Rostedt    do_post_install;
216938fa3dc1SSteven Rostedt (Red Hat)
217038fa3dc1SSteven Rostedt (Red Hat)    my $end_time = time;
217138fa3dc1SSteven Rostedt (Red Hat)    $install_time = $end_time - $start_time;
21722545eb61SSteven Rostedt}
21732545eb61SSteven Rostedt
2174ddf607e5SSteven Rostedtsub get_version {
2175ddf607e5SSteven Rostedt    # get the release name
2176683a3e64SSteven Rostedt    return if ($have_version);
2177ddf607e5SSteven Rostedt    doprint "$make kernelrelease ... ";
217817150fefSSteven Rostedt (Red Hat)    $version = `$make -s kernelrelease | tail -1`;
2179ddf607e5SSteven Rostedt    chomp($version);
2180ddf607e5SSteven Rostedt    doprint "$version\n";
2181683a3e64SSteven Rostedt    $have_version = 1;
2182ddf607e5SSteven Rostedt}
2183ddf607e5SSteven Rostedt
218464d98283SSteven Rostedt (Red Hat)sub start_monitor_and_install {
21859f7424ccSSteven Rostedt    # Make sure the stable kernel has finished booting
2186319ab14fSSteven Rostedt (Red Hat)
2187319ab14fSSteven Rostedt (Red Hat)    # Install bisects, don't need console
2188319ab14fSSteven Rostedt (Red Hat)    if (defined $console) {
21899f7424ccSSteven Rostedt	start_monitor;
21909f7424ccSSteven Rostedt	wait_for_monitor 5;
21919f7424ccSSteven Rostedt	end_monitor;
2192319ab14fSSteven Rostedt (Red Hat)    }
21939f7424ccSSteven Rostedt
2194ddf607e5SSteven Rostedt    get_grub_index;
2195ddf607e5SSteven Rostedt    get_version;
2196ddf607e5SSteven Rostedt    install;
2197ddf607e5SSteven Rostedt
2198319ab14fSSteven Rostedt (Red Hat)    start_monitor if (defined $console);
2199ddf607e5SSteven Rostedt    return monitor;
2200ddf607e5SSteven Rostedt}
2201ddf607e5SSteven Rostedt
22024283b169SSteven Rostedt (Red Hat)my $check_build_re = ".*:.*(warning|error|Error):.*";
22034283b169SSteven Rostedt (Red Hat)my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
22044283b169SSteven Rostedt (Red Hat)
22057328735cSSteven Rostedt (Red Hat)sub process_warning_line {
22067328735cSSteven Rostedt (Red Hat)    my ($line) = @_;
22077328735cSSteven Rostedt (Red Hat)
22087328735cSSteven Rostedt (Red Hat)    chomp $line;
22097328735cSSteven Rostedt (Red Hat)
22107328735cSSteven Rostedt (Red Hat)    # for distcc heterogeneous systems, some compilers
22117328735cSSteven Rostedt (Red Hat)    # do things differently causing warning lines
22127328735cSSteven Rostedt (Red Hat)    # to be slightly different. This makes an attempt
22137328735cSSteven Rostedt (Red Hat)    # to fixe those issues.
22147328735cSSteven Rostedt (Red Hat)
22157328735cSSteven Rostedt (Red Hat)    # chop off the index into the line
22167328735cSSteven Rostedt (Red Hat)    # using distcc, some compilers give different indexes
22177328735cSSteven Rostedt (Red Hat)    # depending on white space
22187328735cSSteven Rostedt (Red Hat)    $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
22197328735cSSteven Rostedt (Red Hat)
22207328735cSSteven Rostedt (Red Hat)    # Some compilers use UTF-8 extended for quotes and some don't.
22217328735cSSteven Rostedt (Red Hat)    $line =~ s/$utf8_quote/'/g;
22227328735cSSteven Rostedt (Red Hat)
22237328735cSSteven Rostedt (Red Hat)    return $line;
22247328735cSSteven Rostedt (Red Hat)}
22257328735cSSteven Rostedt (Red Hat)
22264283b169SSteven Rostedt (Red Hat)# Read buildlog and check against warnings file for any
22274283b169SSteven Rostedt (Red Hat)# new warnings.
22284283b169SSteven Rostedt (Red Hat)#
22294283b169SSteven Rostedt (Red Hat)# Returns 1 if OK
22304283b169SSteven Rostedt (Red Hat)#         0 otherwise
22316c5ee0beSSteven Rostedtsub check_buildlog {
22324283b169SSteven Rostedt (Red Hat)    return 1 if (!defined $warnings_file);
22334283b169SSteven Rostedt (Red Hat)
22344283b169SSteven Rostedt (Red Hat)    my %warnings_list;
22354283b169SSteven Rostedt (Red Hat)
22364283b169SSteven Rostedt (Red Hat)    # Failed builds should not reboot the target
22374283b169SSteven Rostedt (Red Hat)    my $save_no_reboot = $no_reboot;
22384283b169SSteven Rostedt (Red Hat)    $no_reboot = 1;
22394283b169SSteven Rostedt (Red Hat)
22404283b169SSteven Rostedt (Red Hat)    if (-f $warnings_file) {
22414283b169SSteven Rostedt (Red Hat)	open(IN, $warnings_file) or
22424283b169SSteven Rostedt (Red Hat)	    dodie "Error opening $warnings_file";
22434283b169SSteven Rostedt (Red Hat)
22444283b169SSteven Rostedt (Red Hat)	while (<IN>) {
22454283b169SSteven Rostedt (Red Hat)	    if (/$check_build_re/) {
22467328735cSSteven Rostedt (Red Hat)		my $warning = process_warning_line $_;
22477328735cSSteven Rostedt (Red Hat)
22487328735cSSteven Rostedt (Red Hat)		$warnings_list{$warning} = 1;
22494283b169SSteven Rostedt (Red Hat)	    }
22504283b169SSteven Rostedt (Red Hat)	}
22514283b169SSteven Rostedt (Red Hat)	close(IN);
22524283b169SSteven Rostedt (Red Hat)    }
22534283b169SSteven Rostedt (Red Hat)
22544283b169SSteven Rostedt (Red Hat)    # If warnings file didn't exist, and WARNINGS_FILE exist,
22554283b169SSteven Rostedt (Red Hat)    # then we fail on any warning!
22564283b169SSteven Rostedt (Red Hat)
22574283b169SSteven Rostedt (Red Hat)    open(IN, $buildlog) or dodie "Can't open $buildlog";
22584283b169SSteven Rostedt (Red Hat)    while (<IN>) {
22594283b169SSteven Rostedt (Red Hat)	if (/$check_build_re/) {
22607328735cSSteven Rostedt (Red Hat)	    my $warning = process_warning_line $_;
22614283b169SSteven Rostedt (Red Hat)
22627328735cSSteven Rostedt (Red Hat)	    if (!defined $warnings_list{$warning}) {
22634283b169SSteven Rostedt (Red Hat)		fail "New warning found (not in $warnings_file)\n$_\n";
22644283b169SSteven Rostedt (Red Hat)		$no_reboot = $save_no_reboot;
22654283b169SSteven Rostedt (Red Hat)		return 0;
22664283b169SSteven Rostedt (Red Hat)	    }
22674283b169SSteven Rostedt (Red Hat)	}
22684283b169SSteven Rostedt (Red Hat)    }
22694283b169SSteven Rostedt (Red Hat)    $no_reboot = $save_no_reboot;
22704283b169SSteven Rostedt (Red Hat)    close(IN);
22714283b169SSteven Rostedt (Red Hat)}
22724283b169SSteven Rostedt (Red Hat)
22734283b169SSteven Rostedt (Red Hat)sub check_patch_buildlog {
22746c5ee0beSSteven Rostedt    my ($patch) = @_;
22756c5ee0beSSteven Rostedt
22766c5ee0beSSteven Rostedt    my @files = `git show $patch | diffstat -l`;
22776c5ee0beSSteven Rostedt
227835275685SSteven Rostedt (Red Hat)    foreach my $file (@files) {
227935275685SSteven Rostedt (Red Hat)	chomp $file;
228035275685SSteven Rostedt (Red Hat)    }
228135275685SSteven Rostedt (Red Hat)
22826c5ee0beSSteven Rostedt    open(IN, "git show $patch |") or
22836c5ee0beSSteven Rostedt	dodie "failed to show $patch";
22846c5ee0beSSteven Rostedt    while (<IN>) {
22856c5ee0beSSteven Rostedt	if (m,^--- a/(.*),) {
22866c5ee0beSSteven Rostedt	    chomp $1;
22876c5ee0beSSteven Rostedt	    $files[$#files] = $1;
22886c5ee0beSSteven Rostedt	}
22896c5ee0beSSteven Rostedt    }
22906c5ee0beSSteven Rostedt    close(IN);
22916c5ee0beSSteven Rostedt
22926c5ee0beSSteven Rostedt    open(IN, $buildlog) or dodie "Can't open $buildlog";
22936c5ee0beSSteven Rostedt    while (<IN>) {
22946c5ee0beSSteven Rostedt	if (/^\s*(.*?):.*(warning|error)/) {
22956c5ee0beSSteven Rostedt	    my $err = $1;
22966c5ee0beSSteven Rostedt	    foreach my $file (@files) {
2297a75fececSSteven Rostedt		my $fullpath = "$builddir/$file";
22986c5ee0beSSteven Rostedt		if ($file eq $err || $fullpath eq $err) {
22992b7d9b21SSteven Rostedt		    fail "$file built with warnings" and return 0;
23006c5ee0beSSteven Rostedt		}
23016c5ee0beSSteven Rostedt	    }
23026c5ee0beSSteven Rostedt	}
23036c5ee0beSSteven Rostedt    }
23046c5ee0beSSteven Rostedt    close(IN);
23052b7d9b21SSteven Rostedt
23062b7d9b21SSteven Rostedt    return 1;
23076c5ee0beSSteven Rostedt}
23086c5ee0beSSteven Rostedt
2309fcb3f16aSSteven Rostedtsub apply_min_config {
2310fcb3f16aSSteven Rostedt    my $outconfig = "$output_config.new";
2311612b9e9bSSteven Rostedt
2312fcb3f16aSSteven Rostedt    # Read the config file and remove anything that
2313fcb3f16aSSteven Rostedt    # is in the force_config hash (from minconfig and others)
2314fcb3f16aSSteven Rostedt    # then add the force config back.
2315fcb3f16aSSteven Rostedt
2316fcb3f16aSSteven Rostedt    doprint "Applying minimum configurations into $output_config.new\n";
2317fcb3f16aSSteven Rostedt
2318fcb3f16aSSteven Rostedt    open (OUT, ">$outconfig") or
2319fcb3f16aSSteven Rostedt	dodie "Can't create $outconfig";
2320fcb3f16aSSteven Rostedt
2321fcb3f16aSSteven Rostedt    if (-f $output_config) {
2322fcb3f16aSSteven Rostedt	open (IN, $output_config) or
2323fcb3f16aSSteven Rostedt	    dodie "Failed to open $output_config";
2324fcb3f16aSSteven Rostedt	while (<IN>) {
2325fcb3f16aSSteven Rostedt	    if (/^(# )?(CONFIG_[^\s=]*)/) {
2326fcb3f16aSSteven Rostedt		next if (defined($force_config{$2}));
2327fcb3f16aSSteven Rostedt	    }
2328fcb3f16aSSteven Rostedt	    print OUT;
2329fcb3f16aSSteven Rostedt	}
2330fcb3f16aSSteven Rostedt	close IN;
2331fcb3f16aSSteven Rostedt    }
2332fcb3f16aSSteven Rostedt    foreach my $config (keys %force_config) {
2333fcb3f16aSSteven Rostedt	print OUT "$force_config{$config}\n";
2334fcb3f16aSSteven Rostedt    }
2335fcb3f16aSSteven Rostedt    close OUT;
2336fcb3f16aSSteven Rostedt
2337fcb3f16aSSteven Rostedt    run_command "mv $outconfig $output_config";
2338fcb3f16aSSteven Rostedt}
2339fcb3f16aSSteven Rostedt
2340fcb3f16aSSteven Rostedtsub make_oldconfig {
2341fcb3f16aSSteven Rostedt
23424c4ab120SSteven Rostedt    my @force_list = keys %force_config;
23434c4ab120SSteven Rostedt
23444c4ab120SSteven Rostedt    if ($#force_list >= 0) {
2345fcb3f16aSSteven Rostedt	apply_min_config;
23464c4ab120SSteven Rostedt    }
2347fcb3f16aSSteven Rostedt
2348fb16d891SAdam Lee    if (!run_command "$make olddefconfig") {
2349fb16d891SAdam Lee	# Perhaps olddefconfig doesn't exist in this version of the kernel
235018925170SSteven Rostedt	# try oldnoconfig
235118925170SSteven Rostedt	doprint "olddefconfig failed, trying make oldnoconfig\n";
235218925170SSteven Rostedt	if (!run_command "$make oldnoconfig") {
235318925170SSteven Rostedt	    doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2354612b9e9bSSteven Rostedt	    # try a yes '' | oldconfig
2355fcb3f16aSSteven Rostedt	    run_command "yes '' | $make oldconfig" or
2356612b9e9bSSteven Rostedt		dodie "failed make config oldconfig";
2357612b9e9bSSteven Rostedt	}
2358612b9e9bSSteven Rostedt    }
235918925170SSteven Rostedt}
2360612b9e9bSSteven Rostedt
2361fcb3f16aSSteven Rostedt# read a config file and use this to force new configs.
2362fcb3f16aSSteven Rostedtsub load_force_config {
2363fcb3f16aSSteven Rostedt    my ($config) = @_;
2364fcb3f16aSSteven Rostedt
2365cf79fab6SSteven Rostedt    doprint "Loading force configs from $config\n";
2366fcb3f16aSSteven Rostedt    open(IN, $config) or
2367fcb3f16aSSteven Rostedt	dodie "failed to read $config";
2368fcb3f16aSSteven Rostedt    while (<IN>) {
2369fcb3f16aSSteven Rostedt	chomp;
2370fcb3f16aSSteven Rostedt	if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2371fcb3f16aSSteven Rostedt	    $force_config{$1} = $_;
2372fcb3f16aSSteven Rostedt	} elsif (/^# (CONFIG_\S*) is not set/) {
2373fcb3f16aSSteven Rostedt	    $force_config{$1} = $_;
2374fcb3f16aSSteven Rostedt	}
2375fcb3f16aSSteven Rostedt    }
2376fcb3f16aSSteven Rostedt    close IN;
2377fcb3f16aSSteven Rostedt}
2378fcb3f16aSSteven Rostedt
23792545eb61SSteven Rostedtsub build {
23802545eb61SSteven Rostedt    my ($type) = @_;
23812545eb61SSteven Rostedt
23827faafbd6SSteven Rostedt    unlink $buildlog;
23837faafbd6SSteven Rostedt
238438fa3dc1SSteven Rostedt (Red Hat)    my $start_time = time;
238538fa3dc1SSteven Rostedt (Red Hat)
23864ab1cce5SSteven Rostedt    # Failed builds should not reboot the target
23874ab1cce5SSteven Rostedt    my $save_no_reboot = $no_reboot;
23884ab1cce5SSteven Rostedt    $no_reboot = 1;
23894ab1cce5SSteven Rostedt
2390683a3e64SSteven Rostedt    # Calculate a new version from here.
2391683a3e64SSteven Rostedt    $have_version = 0;
2392683a3e64SSteven Rostedt
23930bd6c1a3SSteven Rostedt    if (defined($pre_build)) {
23940bd6c1a3SSteven Rostedt	my $ret = run_command $pre_build;
23950bd6c1a3SSteven Rostedt	if (!$ret && defined($pre_build_die) &&
23960bd6c1a3SSteven Rostedt	    $pre_build_die) {
23970bd6c1a3SSteven Rostedt	    dodie "failed to pre_build\n";
23980bd6c1a3SSteven Rostedt	}
23990bd6c1a3SSteven Rostedt    }
24000bd6c1a3SSteven Rostedt
240175c3fda7SSteven Rostedt    if ($type =~ /^useconfig:(.*)/) {
240251ad1dd1SSteven Rostedt	run_command "cp $1 $output_config" or
240375c3fda7SSteven Rostedt	    dodie "could not copy $1 to .config";
24045f9b6cedSSteven Rostedt
240575c3fda7SSteven Rostedt	$type = "oldconfig";
240675c3fda7SSteven Rostedt    }
240775c3fda7SSteven Rostedt
24085c42fc5bSSteven Rostedt    # old config can ask questions
24095c42fc5bSSteven Rostedt    if ($type eq "oldconfig") {
2410fb16d891SAdam Lee	$type = "olddefconfig";
241175c3fda7SSteven Rostedt
241275c3fda7SSteven Rostedt	# allow for empty configs
241351ad1dd1SSteven Rostedt	run_command "touch $output_config";
241475c3fda7SSteven Rostedt
241513488231SAndrew Jones	if (!$noclean) {
241651ad1dd1SSteven Rostedt	    run_command "mv $output_config $outputdir/config_temp" or
24175c42fc5bSSteven Rostedt		dodie "moving .config";
24185c42fc5bSSteven Rostedt
241913488231SAndrew Jones	    run_command "$make mrproper" or dodie "make mrproper";
24205c42fc5bSSteven Rostedt
242151ad1dd1SSteven Rostedt	    run_command "mv $outputdir/config_temp $output_config" or
24225c42fc5bSSteven Rostedt		dodie "moving config_temp";
242313488231SAndrew Jones	}
24245c42fc5bSSteven Rostedt
24255c42fc5bSSteven Rostedt    } elsif (!$noclean) {
242651ad1dd1SSteven Rostedt	unlink "$output_config";
24275f9b6cedSSteven Rostedt	run_command "$make mrproper" or
24285c42fc5bSSteven Rostedt	    dodie "make mrproper";
24295c42fc5bSSteven Rostedt    }
24302545eb61SSteven Rostedt
24312545eb61SSteven Rostedt    # add something to distinguish this build
2432a75fececSSteven Rostedt    open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2433a75fececSSteven Rostedt    print OUT "$localversion\n";
24342545eb61SSteven Rostedt    close(OUT);
24352545eb61SSteven Rostedt
24365f9b6cedSSteven Rostedt    if (defined($minconfig)) {
2437fcb3f16aSSteven Rostedt	load_force_config($minconfig);
24382545eb61SSteven Rostedt    }
24392545eb61SSteven Rostedt
2440fb16d891SAdam Lee    if ($type ne "olddefconfig") {
2441fcb3f16aSSteven Rostedt	run_command "$make $type" or
24425c42fc5bSSteven Rostedt	    dodie "failed make config";
2443612b9e9bSSteven Rostedt    }
2444fcb3f16aSSteven Rostedt    # Run old config regardless, to enforce min configurations
2445fcb3f16aSSteven Rostedt    make_oldconfig;
24462545eb61SSteven Rostedt
2447f983a2bcSSatoru Takeuchi    my $build_ret = run_command "$make $build_options", $buildlog;
24480bd6c1a3SSteven Rostedt
24490bd6c1a3SSteven Rostedt    if (defined($post_build)) {
2450683a3e64SSteven Rostedt	# Because a post build may change the kernel version
2451683a3e64SSteven Rostedt	# do it now.
2452683a3e64SSteven Rostedt	get_version;
24530bd6c1a3SSteven Rostedt	my $ret = run_command $post_build;
24540bd6c1a3SSteven Rostedt	if (!$ret && defined($post_build_die) &&
24550bd6c1a3SSteven Rostedt	    $post_build_die) {
24560bd6c1a3SSteven Rostedt	    dodie "failed to post_build\n";
24570bd6c1a3SSteven Rostedt	}
24580bd6c1a3SSteven Rostedt    }
24590bd6c1a3SSteven Rostedt
24600bd6c1a3SSteven Rostedt    if (!$build_ret) {
24615f9b6cedSSteven Rostedt	# bisect may need this to pass
24624ab1cce5SSteven Rostedt	if ($in_bisect) {
24634ab1cce5SSteven Rostedt	    $no_reboot = $save_no_reboot;
24644ab1cce5SSteven Rostedt	    return 0;
24654ab1cce5SSteven Rostedt	}
24662b7d9b21SSteven Rostedt	fail "failed build" and return 0;
24672545eb61SSteven Rostedt    }
24685f9b6cedSSteven Rostedt
24694ab1cce5SSteven Rostedt    $no_reboot = $save_no_reboot;
24704ab1cce5SSteven Rostedt
247138fa3dc1SSteven Rostedt (Red Hat)    my $end_time = time;
247238fa3dc1SSteven Rostedt (Red Hat)    $build_time = $end_time - $start_time;
247338fa3dc1SSteven Rostedt (Red Hat)
24742b7d9b21SSteven Rostedt    return 1;
24752545eb61SSteven Rostedt}
24762545eb61SSteven Rostedt
247775c3fda7SSteven Rostedtsub halt {
2478e48c5293SSteven Rostedt    if (!run_ssh "halt" or defined($power_off)) {
2479576f627cSSteven Rostedt	if (defined($poweroff_after_halt)) {
2480576f627cSSteven Rostedt	    sleep $poweroff_after_halt;
2481576f627cSSteven Rostedt	    run_command "$power_off";
2482576f627cSSteven Rostedt	}
2483576f627cSSteven Rostedt    } else {
248475c3fda7SSteven Rostedt	# nope? the zap it!
2485a75fececSSteven Rostedt	run_command "$power_off";
248675c3fda7SSteven Rostedt    }
248775c3fda7SSteven Rostedt}
248875c3fda7SSteven Rostedt
24895f9b6cedSSteven Rostedtsub success {
24905f9b6cedSSteven Rostedt    my ($i) = @_;
24915f9b6cedSSteven Rostedt
2492921ed4c7SSteven Rostedt    if (defined($post_test)) {
2493921ed4c7SSteven Rostedt	run_command $post_test;
2494921ed4c7SSteven Rostedt    }
2495921ed4c7SSteven Rostedt
2496e48c5293SSteven Rostedt    $successes++;
2497e48c5293SSteven Rostedt
24989064af52SSteven Rostedt    my $name = "";
24999064af52SSteven Rostedt
25009064af52SSteven Rostedt    if (defined($test_name)) {
25019064af52SSteven Rostedt	$name = " ($test_name)";
25029064af52SSteven Rostedt    }
25039064af52SSteven Rostedt
25044bf6e1fcSSteven Rostedt (Red Hat)    print_times;
25054bf6e1fcSSteven Rostedt (Red Hat)
25065f9b6cedSSteven Rostedt    doprint "\n\n*******************************************\n";
25075f9b6cedSSteven Rostedt    doprint     "*******************************************\n";
25089064af52SSteven Rostedt    doprint     "KTEST RESULT: TEST $i$name SUCCESS!!!!         **\n";
25095f9b6cedSSteven Rostedt    doprint     "*******************************************\n";
25105f9b6cedSSteven Rostedt    doprint     "*******************************************\n";
25115f9b6cedSSteven Rostedt
2512de5b6e3bSRabin Vincent    if (defined($store_successes)) {
2513de5b6e3bSRabin Vincent        save_logs "success", $store_successes;
2514de5b6e3bSRabin Vincent    }
2515de5b6e3bSRabin Vincent
2516576f627cSSteven Rostedt    if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
2517a75fececSSteven Rostedt	doprint "Reboot and wait $sleep_time seconds\n";
2518bc7c5803SSteven Rostedt	reboot_to_good $sleep_time;
25195f9b6cedSSteven Rostedt    }
25205f9b6cedSSteven Rostedt}
25215f9b6cedSSteven Rostedt
2522c960bb9fSSteven Rostedtsub answer_bisect {
2523c960bb9fSSteven Rostedt    for (;;) {
2524fee9d3e6SChris J Arges	doprint "Pass, fail, or skip? [p/f/s]";
2525c960bb9fSSteven Rostedt	my $ans = <STDIN>;
2526c960bb9fSSteven Rostedt	chomp $ans;
2527c960bb9fSSteven Rostedt	if ($ans eq "p" || $ans eq "P") {
2528c960bb9fSSteven Rostedt	    return 1;
2529c960bb9fSSteven Rostedt	} elsif ($ans eq "f" || $ans eq "F") {
2530c960bb9fSSteven Rostedt	    return 0;
2531fee9d3e6SChris J Arges	} elsif ($ans eq "s" || $ans eq "S") {
2532fee9d3e6SChris J Arges	    return -1;
2533c960bb9fSSteven Rostedt	} else {
2534fee9d3e6SChris J Arges	    print "Please answer 'p', 'f', or 's'\n";
2535c960bb9fSSteven Rostedt	}
2536c960bb9fSSteven Rostedt    }
2537c960bb9fSSteven Rostedt}
2538c960bb9fSSteven Rostedt
25395a391fbfSSteven Rostedtsub child_run_test {
25407faafbd6SSteven Rostedt    my $failed = 0;
25415a391fbfSSteven Rostedt
25427faafbd6SSteven Rostedt    # child should have no power
2543a75fececSSteven Rostedt    $reboot_on_error = 0;
2544a75fececSSteven Rostedt    $poweroff_on_error = 0;
2545a75fececSSteven Rostedt    $die_on_failure = 1;
25467faafbd6SSteven Rostedt
2547f983a2bcSSatoru Takeuchi    run_command $run_test, $testlog or $failed = 1;
2548a9dd5d63SRabin Vincent
25495a391fbfSSteven Rostedt    exit $failed;
25505a391fbfSSteven Rostedt}
25515a391fbfSSteven Rostedt
25525a391fbfSSteven Rostedtmy $child_done;
25535a391fbfSSteven Rostedt
25545a391fbfSSteven Rostedtsub child_finished {
25555a391fbfSSteven Rostedt    $child_done = 1;
25565a391fbfSSteven Rostedt}
25575a391fbfSSteven Rostedt
25585a391fbfSSteven Rostedtsub do_run_test {
25595a391fbfSSteven Rostedt    my $child_pid;
25605a391fbfSSteven Rostedt    my $child_exit;
25615a391fbfSSteven Rostedt    my $line;
25625a391fbfSSteven Rostedt    my $full_line;
25635a391fbfSSteven Rostedt    my $bug = 0;
25649b1d367dSSteven Rostedt    my $bug_ignored = 0;
25655a391fbfSSteven Rostedt
256638fa3dc1SSteven Rostedt (Red Hat)    my $start_time = time;
256738fa3dc1SSteven Rostedt (Red Hat)
25687faafbd6SSteven Rostedt    wait_for_monitor 1;
25695a391fbfSSteven Rostedt
25707faafbd6SSteven Rostedt    doprint "run test $run_test\n";
25715a391fbfSSteven Rostedt
25725a391fbfSSteven Rostedt    $child_done = 0;
25735a391fbfSSteven Rostedt
25745a391fbfSSteven Rostedt    $SIG{CHLD} = qw(child_finished);
25755a391fbfSSteven Rostedt
25765a391fbfSSteven Rostedt    $child_pid = fork;
25775a391fbfSSteven Rostedt
25785a391fbfSSteven Rostedt    child_run_test if (!$child_pid);
25795a391fbfSSteven Rostedt
25805a391fbfSSteven Rostedt    $full_line = "";
25815a391fbfSSteven Rostedt
25825a391fbfSSteven Rostedt    do {
25837faafbd6SSteven Rostedt	$line = wait_for_input($monitor_fp, 1);
25845a391fbfSSteven Rostedt	if (defined($line)) {
25855a391fbfSSteven Rostedt
25865a391fbfSSteven Rostedt	    # we are not guaranteed to get a full line
25875a391fbfSSteven Rostedt	    $full_line .= $line;
25888ea0e063SSteven Rostedt	    doprint $line;
25895a391fbfSSteven Rostedt
25905a391fbfSSteven Rostedt	    if ($full_line =~ /call trace:/i) {
25919b1d367dSSteven Rostedt		if ($ignore_errors) {
25929b1d367dSSteven Rostedt		    $bug_ignored = 1;
25939b1d367dSSteven Rostedt		} else {
25945a391fbfSSteven Rostedt		    $bug = 1;
25955a391fbfSSteven Rostedt		}
25969b1d367dSSteven Rostedt	    }
25975a391fbfSSteven Rostedt
25985a391fbfSSteven Rostedt	    if ($full_line =~ /Kernel panic -/) {
25995a391fbfSSteven Rostedt		$bug = 1;
26005a391fbfSSteven Rostedt	    }
26015a391fbfSSteven Rostedt
26025a391fbfSSteven Rostedt	    if ($line =~ /\n/) {
26035a391fbfSSteven Rostedt		$full_line = "";
26045a391fbfSSteven Rostedt	    }
26055a391fbfSSteven Rostedt	}
26065a391fbfSSteven Rostedt    } while (!$child_done && !$bug);
26075a391fbfSSteven Rostedt
26089b1d367dSSteven Rostedt    if (!$bug && $bug_ignored) {
26099b1d367dSSteven Rostedt	doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
26109b1d367dSSteven Rostedt    }
26119b1d367dSSteven Rostedt
26125a391fbfSSteven Rostedt    if ($bug) {
26138ea0e063SSteven Rostedt	my $failure_start = time;
26148ea0e063SSteven Rostedt	my $now;
26158ea0e063SSteven Rostedt	do {
26168ea0e063SSteven Rostedt	    $line = wait_for_input($monitor_fp, 1);
26178ea0e063SSteven Rostedt	    if (defined($line)) {
26188ea0e063SSteven Rostedt		doprint $line;
26198ea0e063SSteven Rostedt	    }
26208ea0e063SSteven Rostedt	    $now = time;
26218ea0e063SSteven Rostedt	    if ($now - $failure_start >= $stop_after_failure) {
26228ea0e063SSteven Rostedt		last;
26238ea0e063SSteven Rostedt	    }
26248ea0e063SSteven Rostedt	} while (defined($line));
26258ea0e063SSteven Rostedt
26265a391fbfSSteven Rostedt	doprint "Detected kernel crash!\n";
26275a391fbfSSteven Rostedt	# kill the child with extreme prejudice
26285a391fbfSSteven Rostedt	kill 9, $child_pid;
26295a391fbfSSteven Rostedt    }
26305a391fbfSSteven Rostedt
26315a391fbfSSteven Rostedt    waitpid $child_pid, 0;
26325a391fbfSSteven Rostedt    $child_exit = $?;
26335a391fbfSSteven Rostedt
263438fa3dc1SSteven Rostedt (Red Hat)    my $end_time = time;
263538fa3dc1SSteven Rostedt (Red Hat)    $test_time = $end_time - $start_time;
263638fa3dc1SSteven Rostedt (Red Hat)
2637c5dacb88SSteven Rostedt    if (!$bug && $in_bisect) {
2638c5dacb88SSteven Rostedt	if (defined($bisect_ret_good)) {
2639c5dacb88SSteven Rostedt	    if ($child_exit == $bisect_ret_good) {
2640c5dacb88SSteven Rostedt		return 1;
2641c5dacb88SSteven Rostedt	    }
2642c5dacb88SSteven Rostedt	}
2643c5dacb88SSteven Rostedt	if (defined($bisect_ret_skip)) {
2644c5dacb88SSteven Rostedt	    if ($child_exit == $bisect_ret_skip) {
2645c5dacb88SSteven Rostedt		return -1;
2646c5dacb88SSteven Rostedt	    }
2647c5dacb88SSteven Rostedt	}
2648c5dacb88SSteven Rostedt	if (defined($bisect_ret_abort)) {
2649c5dacb88SSteven Rostedt	    if ($child_exit == $bisect_ret_abort) {
2650c5dacb88SSteven Rostedt		fail "test abort" and return -2;
2651c5dacb88SSteven Rostedt	    }
2652c5dacb88SSteven Rostedt	}
2653c5dacb88SSteven Rostedt	if (defined($bisect_ret_bad)) {
2654c5dacb88SSteven Rostedt	    if ($child_exit == $bisect_ret_skip) {
2655c5dacb88SSteven Rostedt		return 0;
2656c5dacb88SSteven Rostedt	    }
2657c5dacb88SSteven Rostedt	}
2658c5dacb88SSteven Rostedt	if (defined($bisect_ret_default)) {
2659c5dacb88SSteven Rostedt	    if ($bisect_ret_default eq "good") {
2660c5dacb88SSteven Rostedt		return 1;
2661c5dacb88SSteven Rostedt	    } elsif ($bisect_ret_default eq "bad") {
2662c5dacb88SSteven Rostedt		return 0;
2663c5dacb88SSteven Rostedt	    } elsif ($bisect_ret_default eq "skip") {
2664c5dacb88SSteven Rostedt		return -1;
2665c5dacb88SSteven Rostedt	    } elsif ($bisect_ret_default eq "abort") {
2666c5dacb88SSteven Rostedt		return -2;
2667c5dacb88SSteven Rostedt	    } else {
2668c5dacb88SSteven Rostedt		fail "unknown default action: $bisect_ret_default"
2669c5dacb88SSteven Rostedt		    and return -2;
2670c5dacb88SSteven Rostedt	    }
2671c5dacb88SSteven Rostedt	}
2672c5dacb88SSteven Rostedt    }
2673c5dacb88SSteven Rostedt
26745a391fbfSSteven Rostedt    if ($bug || $child_exit) {
26752b7d9b21SSteven Rostedt	return 0 if $in_bisect;
26762b7d9b21SSteven Rostedt	fail "test failed" and return 0;
26775a391fbfSSteven Rostedt    }
26782b7d9b21SSteven Rostedt    return 1;
26795a391fbfSSteven Rostedt}
26805a391fbfSSteven Rostedt
2681a75fececSSteven Rostedtsub run_git_bisect {
2682a75fececSSteven Rostedt    my ($command) = @_;
2683a75fececSSteven Rostedt
2684a75fececSSteven Rostedt    doprint "$command ... ";
2685a75fececSSteven Rostedt
2686a75fececSSteven Rostedt    my $output = `$command 2>&1`;
2687a75fececSSteven Rostedt    my $ret = $?;
2688a75fececSSteven Rostedt
2689a75fececSSteven Rostedt    logit $output;
2690a75fececSSteven Rostedt
2691a75fececSSteven Rostedt    if ($ret) {
2692a75fececSSteven Rostedt	doprint "FAILED\n";
2693a75fececSSteven Rostedt	dodie "Failed to git bisect";
2694a75fececSSteven Rostedt    }
2695a75fececSSteven Rostedt
2696a75fececSSteven Rostedt    doprint "SUCCESS\n";
2697a75fececSSteven Rostedt    if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2698a75fececSSteven Rostedt	doprint "$1 [$2]\n";
2699a75fececSSteven Rostedt    } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
2700b5f4aea6SSteven Rostedt	$bisect_bad_commit = $1;
2701a75fececSSteven Rostedt	doprint "Found bad commit... $1\n";
2702a75fececSSteven Rostedt	return 0;
2703a75fececSSteven Rostedt    } else {
2704a75fececSSteven Rostedt	# we already logged it, just print it now.
2705a75fececSSteven Rostedt	print $output;
2706a75fececSSteven Rostedt    }
2707a75fececSSteven Rostedt
2708a75fececSSteven Rostedt    return 1;
2709a75fececSSteven Rostedt}
2710a75fececSSteven Rostedt
2711c23dca7cSSteven Rostedtsub bisect_reboot {
2712c23dca7cSSteven Rostedt    doprint "Reboot and sleep $bisect_sleep_time seconds\n";
2713bc7c5803SSteven Rostedt    reboot_to_good $bisect_sleep_time;
2714c23dca7cSSteven Rostedt}
2715c23dca7cSSteven Rostedt
2716c23dca7cSSteven Rostedt# returns 1 on success, 0 on failure, -1 on skip
27170a05c769SSteven Rostedtsub run_bisect_test {
27180a05c769SSteven Rostedt    my ($type, $buildtype) = @_;
27195f9b6cedSSteven Rostedt
27202b7d9b21SSteven Rostedt    my $failed = 0;
27215f9b6cedSSteven Rostedt    my $result;
27225f9b6cedSSteven Rostedt    my $output;
27235f9b6cedSSteven Rostedt    my $ret;
27245f9b6cedSSteven Rostedt
27250a05c769SSteven Rostedt    $in_bisect = 1;
27260a05c769SSteven Rostedt
27270a05c769SSteven Rostedt    build $buildtype or $failed = 1;
27285f9b6cedSSteven Rostedt
27295f9b6cedSSteven Rostedt    if ($type ne "build") {
2730c23dca7cSSteven Rostedt	if ($failed && $bisect_skip) {
2731c23dca7cSSteven Rostedt	    $in_bisect = 0;
2732c23dca7cSSteven Rostedt	    return -1;
2733c23dca7cSSteven Rostedt	}
27347faafbd6SSteven Rostedt	dodie "Failed on build" if $failed;
27355f9b6cedSSteven Rostedt
27365f9b6cedSSteven Rostedt	# Now boot the box
273764d98283SSteven Rostedt (Red Hat)	start_monitor_and_install or $failed = 1;
27385f9b6cedSSteven Rostedt
27395f9b6cedSSteven Rostedt	if ($type ne "boot") {
2740c23dca7cSSteven Rostedt	    if ($failed && $bisect_skip) {
2741c23dca7cSSteven Rostedt		end_monitor;
2742c23dca7cSSteven Rostedt		bisect_reboot;
2743c23dca7cSSteven Rostedt		$in_bisect = 0;
2744c23dca7cSSteven Rostedt		return -1;
2745c23dca7cSSteven Rostedt	    }
27467faafbd6SSteven Rostedt	    dodie "Failed on boot" if $failed;
27475a391fbfSSteven Rostedt
27482b7d9b21SSteven Rostedt	    do_run_test or $failed = 1;
27495f9b6cedSSteven Rostedt	}
27507faafbd6SSteven Rostedt	end_monitor;
27515f9b6cedSSteven Rostedt    }
27525f9b6cedSSteven Rostedt
27535f9b6cedSSteven Rostedt    if ($failed) {
27540a05c769SSteven Rostedt	$result = 0;
27555f9b6cedSSteven Rostedt    } else {
27560a05c769SSteven Rostedt	$result = 1;
27575f9b6cedSSteven Rostedt    }
27584025bc62SSteven Rostedt
27594025bc62SSteven Rostedt    # reboot the box to a kernel we can ssh to
27604025bc62SSteven Rostedt    if ($type ne "build") {
27614025bc62SSteven Rostedt	bisect_reboot;
27624025bc62SSteven Rostedt    }
27630a05c769SSteven Rostedt    $in_bisect = 0;
27640a05c769SSteven Rostedt
27650a05c769SSteven Rostedt    return $result;
27660a05c769SSteven Rostedt}
27670a05c769SSteven Rostedt
27680a05c769SSteven Rostedtsub run_bisect {
27690a05c769SSteven Rostedt    my ($type) = @_;
27700a05c769SSteven Rostedt    my $buildtype = "oldconfig";
27710a05c769SSteven Rostedt
27720a05c769SSteven Rostedt    # We should have a minconfig to use?
27730a05c769SSteven Rostedt    if (defined($minconfig)) {
27740a05c769SSteven Rostedt	$buildtype = "useconfig:$minconfig";
27750a05c769SSteven Rostedt    }
27760a05c769SSteven Rostedt
2777961d9cacSSteven Rostedt (Red Hat)    # If the user sets bisect_tries to less than 1, then no tries
2778961d9cacSSteven Rostedt (Red Hat)    # is a success.
2779961d9cacSSteven Rostedt (Red Hat)    my $ret = 1;
2780961d9cacSSteven Rostedt (Red Hat)
2781961d9cacSSteven Rostedt (Red Hat)    # Still let the user manually decide that though.
2782961d9cacSSteven Rostedt (Red Hat)    if ($bisect_tries < 1 && $bisect_manual) {
2783961d9cacSSteven Rostedt (Red Hat)	$ret = answer_bisect;
2784961d9cacSSteven Rostedt (Red Hat)    }
2785961d9cacSSteven Rostedt (Red Hat)
2786961d9cacSSteven Rostedt (Red Hat)    for (my $i = 0; $i < $bisect_tries; $i++) {
2787961d9cacSSteven Rostedt (Red Hat)	if ($bisect_tries > 1) {
2788961d9cacSSteven Rostedt (Red Hat)	    my $t = $i + 1;
2789961d9cacSSteven Rostedt (Red Hat)	    doprint("Running bisect trial $t of $bisect_tries:\n");
2790961d9cacSSteven Rostedt (Red Hat)	}
2791961d9cacSSteven Rostedt (Red Hat)	$ret = run_bisect_test $type, $buildtype;
27920a05c769SSteven Rostedt
2793c960bb9fSSteven Rostedt	if ($bisect_manual) {
2794c960bb9fSSteven Rostedt	    $ret = answer_bisect;
2795c960bb9fSSteven Rostedt	}
27965f9b6cedSSteven Rostedt
2797961d9cacSSteven Rostedt (Red Hat)	last if (!$ret);
2798961d9cacSSteven Rostedt (Red Hat)    }
2799961d9cacSSteven Rostedt (Red Hat)
2800d6ce2a0bSSteven Rostedt    # Are we looking for where it worked, not failed?
28015158ba3eSRuss Dill    if ($reverse_bisect && $ret >= 0) {
28020a05c769SSteven Rostedt	$ret = !$ret;
2803d6ce2a0bSSteven Rostedt    }
2804d6ce2a0bSSteven Rostedt
2805c23dca7cSSteven Rostedt    if ($ret > 0) {
28060a05c769SSteven Rostedt	return "good";
2807c23dca7cSSteven Rostedt    } elsif ($ret == 0) {
28080a05c769SSteven Rostedt	return  "bad";
2809c23dca7cSSteven Rostedt    } elsif ($bisect_skip) {
2810c23dca7cSSteven Rostedt	doprint "HIT A BAD COMMIT ... SKIPPING\n";
2811c23dca7cSSteven Rostedt	return "skip";
28120a05c769SSteven Rostedt    }
28135f9b6cedSSteven Rostedt}
28145f9b6cedSSteven Rostedt
2815dad98754SSteven Rostedtsub update_bisect_replay {
2816dad98754SSteven Rostedt    my $tmp_log = "$tmpdir/ktest_bisect_log";
2817dad98754SSteven Rostedt    run_command "git bisect log > $tmp_log" or
2818dad98754SSteven Rostedt	die "can't create bisect log";
2819dad98754SSteven Rostedt    return $tmp_log;
2820dad98754SSteven Rostedt}
2821dad98754SSteven Rostedt
28225f9b6cedSSteven Rostedtsub bisect {
28235f9b6cedSSteven Rostedt    my ($i) = @_;
28245f9b6cedSSteven Rostedt
28255f9b6cedSSteven Rostedt    my $result;
28265f9b6cedSSteven Rostedt
2827b5f4aea6SSteven Rostedt    die "BISECT_GOOD[$i] not defined\n"	if (!defined($bisect_good));
2828b5f4aea6SSteven Rostedt    die "BISECT_BAD[$i] not defined\n"	if (!defined($bisect_bad));
2829b5f4aea6SSteven Rostedt    die "BISECT_TYPE[$i] not defined\n"	if (!defined($bisect_type));
28305f9b6cedSSteven Rostedt
2831b5f4aea6SSteven Rostedt    my $good = $bisect_good;
2832b5f4aea6SSteven Rostedt    my $bad = $bisect_bad;
2833b5f4aea6SSteven Rostedt    my $type = $bisect_type;
2834b5f4aea6SSteven Rostedt    my $start = $bisect_start;
2835b5f4aea6SSteven Rostedt    my $replay = $bisect_replay;
2836b5f4aea6SSteven Rostedt    my $start_files = $bisect_files;
28373410f6fdSSteven Rostedt
28383410f6fdSSteven Rostedt    if (defined($start_files)) {
28393410f6fdSSteven Rostedt	$start_files = " -- " . $start_files;
28403410f6fdSSteven Rostedt    } else {
28413410f6fdSSteven Rostedt	$start_files = "";
28423410f6fdSSteven Rostedt    }
28435f9b6cedSSteven Rostedt
2844a57419b3SSteven Rostedt    # convert to true sha1's
2845a57419b3SSteven Rostedt    $good = get_sha1($good);
2846a57419b3SSteven Rostedt    $bad = get_sha1($bad);
2847a57419b3SSteven Rostedt
2848b5f4aea6SSteven Rostedt    if (defined($bisect_reverse) && $bisect_reverse == 1) {
2849d6ce2a0bSSteven Rostedt	doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2850d6ce2a0bSSteven Rostedt	$reverse_bisect = 1;
2851d6ce2a0bSSteven Rostedt    } else {
2852d6ce2a0bSSteven Rostedt	$reverse_bisect = 0;
2853d6ce2a0bSSteven Rostedt    }
2854d6ce2a0bSSteven Rostedt
28555a391fbfSSteven Rostedt    # Can't have a test without having a test to run
28565a391fbfSSteven Rostedt    if ($type eq "test" && !defined($run_test)) {
28575a391fbfSSteven Rostedt	$type = "boot";
28585a391fbfSSteven Rostedt    }
28595a391fbfSSteven Rostedt
2860dad98754SSteven Rostedt    # Check if a bisect was running
2861dad98754SSteven Rostedt    my $bisect_start_file = "$builddir/.git/BISECT_START";
2862dad98754SSteven Rostedt
2863b5f4aea6SSteven Rostedt    my $check = $bisect_check;
2864dad98754SSteven Rostedt    my $do_check = defined($check) && $check ne "0";
2865dad98754SSteven Rostedt
2866dad98754SSteven Rostedt    if ( -f $bisect_start_file ) {
2867dad98754SSteven Rostedt	print "Bisect in progress found\n";
2868dad98754SSteven Rostedt	if ($do_check) {
2869dad98754SSteven Rostedt	    print " If you say yes, then no checks of good or bad will be done\n";
2870dad98754SSteven Rostedt	}
2871dad98754SSteven Rostedt	if (defined($replay)) {
2872dad98754SSteven Rostedt	    print "** BISECT_REPLAY is defined in config file **";
2873dad98754SSteven Rostedt	    print " Ignore config option and perform new git bisect log?\n";
2874dad98754SSteven Rostedt	    if (read_ync " (yes, no, or cancel) ") {
2875dad98754SSteven Rostedt		$replay = update_bisect_replay;
2876dad98754SSteven Rostedt		$do_check = 0;
2877dad98754SSteven Rostedt	    }
2878dad98754SSteven Rostedt	} elsif (read_yn "read git log and continue?") {
2879dad98754SSteven Rostedt	    $replay = update_bisect_replay;
2880dad98754SSteven Rostedt	    $do_check = 0;
2881dad98754SSteven Rostedt	}
2882dad98754SSteven Rostedt    }
2883dad98754SSteven Rostedt
2884dad98754SSteven Rostedt    if ($do_check) {
2885a75fececSSteven Rostedt
2886a75fececSSteven Rostedt	# get current HEAD
2887a57419b3SSteven Rostedt	my $head = get_sha1("HEAD");
2888a75fececSSteven Rostedt
2889a75fececSSteven Rostedt	if ($check ne "good") {
2890a75fececSSteven Rostedt	    doprint "TESTING BISECT BAD [$bad]\n";
2891a75fececSSteven Rostedt	    run_command "git checkout $bad" or
2892a75fececSSteven Rostedt		die "Failed to checkout $bad";
2893a75fececSSteven Rostedt
2894a75fececSSteven Rostedt	    $result = run_bisect $type;
2895a75fececSSteven Rostedt
2896a75fececSSteven Rostedt	    if ($result ne "bad") {
2897a75fececSSteven Rostedt		fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2898a75fececSSteven Rostedt	    }
2899a75fececSSteven Rostedt	}
2900a75fececSSteven Rostedt
2901a75fececSSteven Rostedt	if ($check ne "bad") {
2902a75fececSSteven Rostedt	    doprint "TESTING BISECT GOOD [$good]\n";
2903a75fececSSteven Rostedt	    run_command "git checkout $good" or
2904a75fececSSteven Rostedt		die "Failed to checkout $good";
2905a75fececSSteven Rostedt
2906a75fececSSteven Rostedt	    $result = run_bisect $type;
2907a75fececSSteven Rostedt
2908a75fececSSteven Rostedt	    if ($result ne "good") {
2909a75fececSSteven Rostedt		fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2910a75fececSSteven Rostedt	    }
2911a75fececSSteven Rostedt	}
2912a75fececSSteven Rostedt
2913a75fececSSteven Rostedt	# checkout where we started
2914a75fececSSteven Rostedt	run_command "git checkout $head" or
2915a75fececSSteven Rostedt	    die "Failed to checkout $head";
2916a75fececSSteven Rostedt    }
2917a75fececSSteven Rostedt
29183410f6fdSSteven Rostedt    run_command "git bisect start$start_files" or
2919a75fececSSteven Rostedt	dodie "could not start bisect";
2920a75fececSSteven Rostedt
2921d832d743SSteven Rostedt (Red Hat)    if (defined($replay)) {
2922d832d743SSteven Rostedt (Red Hat)	run_command "git bisect replay $replay" or
2923d832d743SSteven Rostedt (Red Hat)	    dodie "failed to run replay";
2924d832d743SSteven Rostedt (Red Hat)    } else {
2925d832d743SSteven Rostedt (Red Hat)
2926a75fececSSteven Rostedt	run_command "git bisect good $good" or
2927a75fececSSteven Rostedt	    dodie "could not set bisect good to $good";
2928a75fececSSteven Rostedt
2929a75fececSSteven Rostedt	run_git_bisect "git bisect bad $bad" or
2930a75fececSSteven Rostedt	    dodie "could not set bisect bad to $bad";
2931a75fececSSteven Rostedt
2932a75fececSSteven Rostedt    }
2933a75fececSSteven Rostedt
2934a75fececSSteven Rostedt    if (defined($start)) {
2935a75fececSSteven Rostedt	run_command "git checkout $start" or
2936a75fececSSteven Rostedt	    dodie "failed to checkout $start";
2937a75fececSSteven Rostedt    }
2938a75fececSSteven Rostedt
2939a75fececSSteven Rostedt    my $test;
29405f9b6cedSSteven Rostedt    do {
29415f9b6cedSSteven Rostedt	$result = run_bisect $type;
2942a75fececSSteven Rostedt	$test = run_git_bisect "git bisect $result";
294338fa3dc1SSteven Rostedt (Red Hat)	print_times;
2944a75fececSSteven Rostedt    } while ($test);
29455f9b6cedSSteven Rostedt
29465f9b6cedSSteven Rostedt    run_command "git bisect log" or
29475f9b6cedSSteven Rostedt	dodie "could not capture git bisect log";
29485f9b6cedSSteven Rostedt
29495f9b6cedSSteven Rostedt    run_command "git bisect reset" or
29505f9b6cedSSteven Rostedt	dodie "could not reset git bisect";
29515f9b6cedSSteven Rostedt
2952b5f4aea6SSteven Rostedt    doprint "Bad commit was [$bisect_bad_commit]\n";
29535f9b6cedSSteven Rostedt
29540a05c769SSteven Rostedt    success $i;
29550a05c769SSteven Rostedt}
29560a05c769SSteven Rostedt
2957cf79fab6SSteven Rostedt# config_ignore holds the configs that were set (or unset) for
2958cf79fab6SSteven Rostedt# a good config and we will ignore these configs for the rest
2959cf79fab6SSteven Rostedt# of a config bisect. These configs stay as they were.
29600a05c769SSteven Rostedtmy %config_ignore;
2961cf79fab6SSteven Rostedt
2962cf79fab6SSteven Rostedt# config_set holds what all configs were set as.
29630a05c769SSteven Rostedtmy %config_set;
29640a05c769SSteven Rostedt
2965cf79fab6SSteven Rostedt# config_off holds the set of configs that the bad config had disabled.
2966cf79fab6SSteven Rostedt# We need to record them and set them in the .config when running
2967fb16d891SAdam Lee# olddefconfig, because olddefconfig keeps the defaults.
2968cf79fab6SSteven Rostedtmy %config_off;
2969cf79fab6SSteven Rostedt
2970cf79fab6SSteven Rostedt# config_off_tmp holds a set of configs to turn off for now
2971cf79fab6SSteven Rostedtmy @config_off_tmp;
2972cf79fab6SSteven Rostedt
2973cf79fab6SSteven Rostedt# config_list is the set of configs that are being tested
29740a05c769SSteven Rostedtmy %config_list;
29750a05c769SSteven Rostedtmy %null_config;
29760a05c769SSteven Rostedt
29770a05c769SSteven Rostedtmy %dependency;
29780a05c769SSteven Rostedt
29794c4ab120SSteven Rostedtsub assign_configs {
29804c4ab120SSteven Rostedt    my ($hash, $config) = @_;
29810a05c769SSteven Rostedt
29826071c22eSSteven Rostedt (Red Hat)    doprint "Reading configs from $config\n";
29836071c22eSSteven Rostedt (Red Hat)
29840a05c769SSteven Rostedt    open (IN, $config)
29850a05c769SSteven Rostedt	or dodie "Failed to read $config";
29860a05c769SSteven Rostedt
29870a05c769SSteven Rostedt    while (<IN>) {
29886071c22eSSteven Rostedt (Red Hat)	chomp;
29899bf71749SSteven Rostedt	if (/^((CONFIG\S*)=.*)/) {
29904c4ab120SSteven Rostedt	    ${$hash}{$2} = $1;
29916071c22eSSteven Rostedt (Red Hat)	} elsif (/^(# (CONFIG\S*) is not set)/) {
29926071c22eSSteven Rostedt (Red Hat)	    ${$hash}{$2} = $1;
29930a05c769SSteven Rostedt	}
29940a05c769SSteven Rostedt    }
29950a05c769SSteven Rostedt
29960a05c769SSteven Rostedt    close(IN);
29970a05c769SSteven Rostedt}
29980a05c769SSteven Rostedt
29994c4ab120SSteven Rostedtsub process_config_ignore {
30004c4ab120SSteven Rostedt    my ($config) = @_;
30014c4ab120SSteven Rostedt
30024c4ab120SSteven Rostedt    assign_configs \%config_ignore, $config;
30034c4ab120SSteven Rostedt}
30044c4ab120SSteven Rostedt
30050a05c769SSteven Rostedtsub get_dependencies {
30060a05c769SSteven Rostedt    my ($config) = @_;
30070a05c769SSteven Rostedt
30080a05c769SSteven Rostedt    my $arr = $dependency{$config};
30090a05c769SSteven Rostedt    if (!defined($arr)) {
30100a05c769SSteven Rostedt	return ();
30110a05c769SSteven Rostedt    }
30120a05c769SSteven Rostedt
30130a05c769SSteven Rostedt    my @deps = @{$arr};
30140a05c769SSteven Rostedt
30150a05c769SSteven Rostedt    foreach my $dep (@{$arr}) {
30160a05c769SSteven Rostedt	print "ADD DEP $dep\n";
30170a05c769SSteven Rostedt	@deps = (@deps, get_dependencies $dep);
30180a05c769SSteven Rostedt    }
30190a05c769SSteven Rostedt
30200a05c769SSteven Rostedt    return @deps;
30210a05c769SSteven Rostedt}
30220a05c769SSteven Rostedt
30236071c22eSSteven Rostedt (Red Hat)sub save_config {
30246071c22eSSteven Rostedt (Red Hat)    my ($pc, $file) = @_;
30250a05c769SSteven Rostedt
30266071c22eSSteven Rostedt (Red Hat)    my %configs = %{$pc};
30270a05c769SSteven Rostedt
30286071c22eSSteven Rostedt (Red Hat)    doprint "Saving configs into $file\n";
30290a05c769SSteven Rostedt
30306071c22eSSteven Rostedt (Red Hat)    open(OUT, ">$file") or dodie "Can not write to $file";
3031cf79fab6SSteven Rostedt
30326071c22eSSteven Rostedt (Red Hat)    foreach my $config (keys %configs) {
30336071c22eSSteven Rostedt (Red Hat)	print OUT "$configs{$config}\n";
30340a05c769SSteven Rostedt    }
30350a05c769SSteven Rostedt    close(OUT);
30366071c22eSSteven Rostedt (Red Hat)}
30376071c22eSSteven Rostedt (Red Hat)
30386071c22eSSteven Rostedt (Red Hat)sub create_config {
30396071c22eSSteven Rostedt (Red Hat)    my ($name, $pc) = @_;
30406071c22eSSteven Rostedt (Red Hat)
30416071c22eSSteven Rostedt (Red Hat)    doprint "Creating old config from $name configs\n";
30426071c22eSSteven Rostedt (Red Hat)
30436071c22eSSteven Rostedt (Red Hat)    save_config $pc, $output_config;
30440a05c769SSteven Rostedt
3045fcb3f16aSSteven Rostedt    make_oldconfig;
30460a05c769SSteven Rostedt}
30470a05c769SSteven Rostedt
30486071c22eSSteven Rostedt (Red Hat)# compare two config hashes, and return configs with different vals.
30496071c22eSSteven Rostedt (Red Hat)# It returns B's config values, but you can use A to see what A was.
30506071c22eSSteven Rostedt (Red Hat)sub diff_config_vals {
30516071c22eSSteven Rostedt (Red Hat)    my ($pa, $pb) = @_;
30526071c22eSSteven Rostedt (Red Hat)
30536071c22eSSteven Rostedt (Red Hat)    # crappy Perl way to pass in hashes.
30546071c22eSSteven Rostedt (Red Hat)    my %a = %{$pa};
30556071c22eSSteven Rostedt (Red Hat)    my %b = %{$pb};
30566071c22eSSteven Rostedt (Red Hat)
30576071c22eSSteven Rostedt (Red Hat)    my %ret;
30586071c22eSSteven Rostedt (Red Hat)
30596071c22eSSteven Rostedt (Red Hat)    foreach my $item (keys %a) {
30606071c22eSSteven Rostedt (Red Hat)	if (defined($b{$item}) && $b{$item} ne $a{$item}) {
30616071c22eSSteven Rostedt (Red Hat)	    $ret{$item} = $b{$item};
30626071c22eSSteven Rostedt (Red Hat)	}
30636071c22eSSteven Rostedt (Red Hat)    }
30646071c22eSSteven Rostedt (Red Hat)
30656071c22eSSteven Rostedt (Red Hat)    return %ret;
30666071c22eSSteven Rostedt (Red Hat)}
30676071c22eSSteven Rostedt (Red Hat)
30686071c22eSSteven Rostedt (Red Hat)# compare two config hashes and return the configs in B but not A
30696071c22eSSteven Rostedt (Red Hat)sub diff_configs {
30706071c22eSSteven Rostedt (Red Hat)    my ($pa, $pb) = @_;
30716071c22eSSteven Rostedt (Red Hat)
30726071c22eSSteven Rostedt (Red Hat)    my %ret;
30736071c22eSSteven Rostedt (Red Hat)
30746071c22eSSteven Rostedt (Red Hat)    # crappy Perl way to pass in hashes.
30756071c22eSSteven Rostedt (Red Hat)    my %a = %{$pa};
30766071c22eSSteven Rostedt (Red Hat)    my %b = %{$pb};
30776071c22eSSteven Rostedt (Red Hat)
30786071c22eSSteven Rostedt (Red Hat)    foreach my $item (keys %b) {
30796071c22eSSteven Rostedt (Red Hat)	if (!defined($a{$item})) {
30806071c22eSSteven Rostedt (Red Hat)	    $ret{$item} = $b{$item};
30816071c22eSSteven Rostedt (Red Hat)	}
30826071c22eSSteven Rostedt (Red Hat)    }
30836071c22eSSteven Rostedt (Red Hat)
30846071c22eSSteven Rostedt (Red Hat)    return %ret;
30856071c22eSSteven Rostedt (Red Hat)}
30866071c22eSSteven Rostedt (Red Hat)
30876071c22eSSteven Rostedt (Red Hat)# return if two configs are equal or not
30886071c22eSSteven Rostedt (Red Hat)# 0 is equal +1 b has something a does not
30896071c22eSSteven Rostedt (Red Hat)# +1 if a and b have a different item.
30906071c22eSSteven Rostedt (Red Hat)# -1 if a has something b does not
30910a05c769SSteven Rostedtsub compare_configs {
30926071c22eSSteven Rostedt (Red Hat)    my ($pa, $pb) = @_;
30936071c22eSSteven Rostedt (Red Hat)
30946071c22eSSteven Rostedt (Red Hat)    my %ret;
30956071c22eSSteven Rostedt (Red Hat)
30966071c22eSSteven Rostedt (Red Hat)    # crappy Perl way to pass in hashes.
30976071c22eSSteven Rostedt (Red Hat)    my %a = %{$pa};
30986071c22eSSteven Rostedt (Red Hat)    my %b = %{$pb};
30996071c22eSSteven Rostedt (Red Hat)
31006071c22eSSteven Rostedt (Red Hat)    foreach my $item (keys %b) {
31016071c22eSSteven Rostedt (Red Hat)	if (!defined($a{$item})) {
31026071c22eSSteven Rostedt (Red Hat)	    return 1;
31036071c22eSSteven Rostedt (Red Hat)	}
31046071c22eSSteven Rostedt (Red Hat)	if ($a{$item} ne $b{$item}) {
31056071c22eSSteven Rostedt (Red Hat)	    return 1;
31066071c22eSSteven Rostedt (Red Hat)	}
31076071c22eSSteven Rostedt (Red Hat)    }
31080a05c769SSteven Rostedt
31090a05c769SSteven Rostedt    foreach my $item (keys %a) {
31100a05c769SSteven Rostedt	if (!defined($b{$item})) {
31116071c22eSSteven Rostedt (Red Hat)	    return -1;
31120a05c769SSteven Rostedt	}
31130a05c769SSteven Rostedt    }
31140a05c769SSteven Rostedt
31150a05c769SSteven Rostedt    return 0;
31160a05c769SSteven Rostedt}
31170a05c769SSteven Rostedt
31180a05c769SSteven Rostedtsub run_config_bisect_test {
31190a05c769SSteven Rostedt    my ($type) = @_;
31200a05c769SSteven Rostedt
31214cc559bdSSteven Rostedt (Red Hat)    my $ret = run_bisect_test $type, "oldconfig";
31224cc559bdSSteven Rostedt (Red Hat)
31234cc559bdSSteven Rostedt (Red Hat)    if ($bisect_manual) {
31244cc559bdSSteven Rostedt (Red Hat)	$ret = answer_bisect;
31254cc559bdSSteven Rostedt (Red Hat)    }
31264cc559bdSSteven Rostedt (Red Hat)
31274cc559bdSSteven Rostedt (Red Hat)    return $ret;
31280a05c769SSteven Rostedt}
31290a05c769SSteven Rostedt
31300a05c769SSteven Rostedtsub process_failed {
31310a05c769SSteven Rostedt    my ($config) = @_;
31320a05c769SSteven Rostedt
31330a05c769SSteven Rostedt    doprint "\n\n***************************************\n";
31340a05c769SSteven Rostedt    doprint "Found bad config: $config\n";
31350a05c769SSteven Rostedt    doprint "***************************************\n\n";
31360a05c769SSteven Rostedt}
31370a05c769SSteven Rostedt
31386071c22eSSteven Rostedt (Red Hat)# used for config bisecting
31396071c22eSSteven Rostedt (Red Hat)my $good_config;
31406071c22eSSteven Rostedt (Red Hat)my $bad_config;
31410a05c769SSteven Rostedt
31426071c22eSSteven Rostedt (Red Hat)sub process_new_config {
31436071c22eSSteven Rostedt (Red Hat)    my ($tc, $nc, $gc, $bc) = @_;
31440a05c769SSteven Rostedt
31456071c22eSSteven Rostedt (Red Hat)    my %tmp_config = %{$tc};
31466071c22eSSteven Rostedt (Red Hat)    my %good_configs = %{$gc};
31476071c22eSSteven Rostedt (Red Hat)    my %bad_configs = %{$bc};
31480a05c769SSteven Rostedt
31496071c22eSSteven Rostedt (Red Hat)    my %new_configs;
31506071c22eSSteven Rostedt (Red Hat)
31516071c22eSSteven Rostedt (Red Hat)    my $runtest = 1;
31520a05c769SSteven Rostedt    my $ret;
31530a05c769SSteven Rostedt
31546071c22eSSteven Rostedt (Red Hat)    create_config "tmp_configs", \%tmp_config;
31556071c22eSSteven Rostedt (Red Hat)    assign_configs \%new_configs, $output_config;
31560a05c769SSteven Rostedt
31576071c22eSSteven Rostedt (Red Hat)    $ret = compare_configs \%new_configs, \%bad_configs;
31586071c22eSSteven Rostedt (Red Hat)    if (!$ret) {
31596071c22eSSteven Rostedt (Red Hat)	doprint "New config equals bad config, try next test\n";
31606071c22eSSteven Rostedt (Red Hat)	$runtest = 0;
31616071c22eSSteven Rostedt (Red Hat)    }
31620a05c769SSteven Rostedt
31636071c22eSSteven Rostedt (Red Hat)    if ($runtest) {
31646071c22eSSteven Rostedt (Red Hat)	$ret = compare_configs \%new_configs, \%good_configs;
31656071c22eSSteven Rostedt (Red Hat)	if (!$ret) {
31666071c22eSSteven Rostedt (Red Hat)	    doprint "New config equals good config, try next test\n";
31676071c22eSSteven Rostedt (Red Hat)	    $runtest = 0;
31686071c22eSSteven Rostedt (Red Hat)	}
31696071c22eSSteven Rostedt (Red Hat)    }
31700a05c769SSteven Rostedt
31716071c22eSSteven Rostedt (Red Hat)    %{$nc} = %new_configs;
31726071c22eSSteven Rostedt (Red Hat)
31736071c22eSSteven Rostedt (Red Hat)    return $runtest;
31746071c22eSSteven Rostedt (Red Hat)}
31756071c22eSSteven Rostedt (Red Hat)
31766071c22eSSteven Rostedt (Red Hat)sub run_config_bisect {
31776071c22eSSteven Rostedt (Red Hat)    my ($pgood, $pbad) = @_;
31786071c22eSSteven Rostedt (Red Hat)
31796071c22eSSteven Rostedt (Red Hat)    my $type = $config_bisect_type;
31806071c22eSSteven Rostedt (Red Hat)
31816071c22eSSteven Rostedt (Red Hat)    my %good_configs = %{$pgood};
31826071c22eSSteven Rostedt (Red Hat)    my %bad_configs = %{$pbad};
31836071c22eSSteven Rostedt (Red Hat)
31846071c22eSSteven Rostedt (Red Hat)    my %diff_configs = diff_config_vals \%good_configs, \%bad_configs;
31856071c22eSSteven Rostedt (Red Hat)    my %b_configs = diff_configs \%good_configs, \%bad_configs;
31866071c22eSSteven Rostedt (Red Hat)    my %g_configs = diff_configs \%bad_configs, \%good_configs;
31876071c22eSSteven Rostedt (Red Hat)
31886071c22eSSteven Rostedt (Red Hat)    my @diff_arr = keys %diff_configs;
31896071c22eSSteven Rostedt (Red Hat)    my $len_diff = $#diff_arr + 1;
31906071c22eSSteven Rostedt (Red Hat)
31916071c22eSSteven Rostedt (Red Hat)    my @b_arr = keys %b_configs;
31926071c22eSSteven Rostedt (Red Hat)    my $len_b = $#b_arr + 1;
31936071c22eSSteven Rostedt (Red Hat)
31946071c22eSSteven Rostedt (Red Hat)    my @g_arr = keys %g_configs;
31956071c22eSSteven Rostedt (Red Hat)    my $len_g = $#g_arr + 1;
31966071c22eSSteven Rostedt (Red Hat)
31976071c22eSSteven Rostedt (Red Hat)    my $runtest = 1;
31986071c22eSSteven Rostedt (Red Hat)    my %new_configs;
31996071c22eSSteven Rostedt (Red Hat)    my $ret;
32006071c22eSSteven Rostedt (Red Hat)
32016071c22eSSteven Rostedt (Red Hat)    # First, lets get it down to a single subset.
32026071c22eSSteven Rostedt (Red Hat)    # Is the problem with a difference in values?
32036071c22eSSteven Rostedt (Red Hat)    # Is the problem with a missing config?
32046071c22eSSteven Rostedt (Red Hat)    # Is the problem with a config that breaks things?
32056071c22eSSteven Rostedt (Red Hat)
32066071c22eSSteven Rostedt (Red Hat)    # Enable all of one set and see if we get a new bad
32076071c22eSSteven Rostedt (Red Hat)    # or good config.
32086071c22eSSteven Rostedt (Red Hat)
32096071c22eSSteven Rostedt (Red Hat)    # first set the good config to the bad values.
32106071c22eSSteven Rostedt (Red Hat)
32116071c22eSSteven Rostedt (Red Hat)    doprint "d=$len_diff g=$len_g b=$len_b\n";
32126071c22eSSteven Rostedt (Red Hat)
32136071c22eSSteven Rostedt (Red Hat)    # first lets enable things in bad config that are enabled in good config
32146071c22eSSteven Rostedt (Red Hat)
32156071c22eSSteven Rostedt (Red Hat)    if ($len_diff > 0) {
32166071c22eSSteven Rostedt (Red Hat)	if ($len_b > 0 || $len_g > 0) {
32176071c22eSSteven Rostedt (Red Hat)	    my %tmp_config = %bad_configs;
32186071c22eSSteven Rostedt (Red Hat)
32196071c22eSSteven Rostedt (Red Hat)	    doprint "Set tmp config to be bad config with good config values\n";
32206071c22eSSteven Rostedt (Red Hat)	    foreach my $item (@diff_arr) {
32216071c22eSSteven Rostedt (Red Hat)		$tmp_config{$item} = $good_configs{$item};
32226071c22eSSteven Rostedt (Red Hat)	    }
32236071c22eSSteven Rostedt (Red Hat)
32246071c22eSSteven Rostedt (Red Hat)	    $runtest = process_new_config \%tmp_config, \%new_configs,
32256071c22eSSteven Rostedt (Red Hat)			    \%good_configs, \%bad_configs;
32266071c22eSSteven Rostedt (Red Hat)	}
32276071c22eSSteven Rostedt (Red Hat)    }
32286071c22eSSteven Rostedt (Red Hat)
32296071c22eSSteven Rostedt (Red Hat)    if (!$runtest && $len_diff > 0) {
32306071c22eSSteven Rostedt (Red Hat)
32316071c22eSSteven Rostedt (Red Hat)	if ($len_diff == 1) {
32324186cb45SSteven Rostedt (Red Hat)	    process_failed $diff_arr[0];
32336071c22eSSteven Rostedt (Red Hat)	    return 1;
32346071c22eSSteven Rostedt (Red Hat)	}
32356071c22eSSteven Rostedt (Red Hat)	my %tmp_config = %bad_configs;
32366071c22eSSteven Rostedt (Red Hat)
32376071c22eSSteven Rostedt (Red Hat)	my $half = int($#diff_arr / 2);
32386071c22eSSteven Rostedt (Red Hat)	my @tophalf = @diff_arr[0 .. $half];
32396071c22eSSteven Rostedt (Red Hat)
32406071c22eSSteven Rostedt (Red Hat)	doprint "Settings bisect with top half:\n";
32416071c22eSSteven Rostedt (Red Hat)	doprint "Set tmp config to be bad config with some good config values\n";
32426071c22eSSteven Rostedt (Red Hat)	foreach my $item (@tophalf) {
32436071c22eSSteven Rostedt (Red Hat)	    $tmp_config{$item} = $good_configs{$item};
32446071c22eSSteven Rostedt (Red Hat)	}
32456071c22eSSteven Rostedt (Red Hat)
32466071c22eSSteven Rostedt (Red Hat)	$runtest = process_new_config \%tmp_config, \%new_configs,
32476071c22eSSteven Rostedt (Red Hat)			    \%good_configs, \%bad_configs;
32486071c22eSSteven Rostedt (Red Hat)
32496071c22eSSteven Rostedt (Red Hat)	if (!$runtest) {
32506071c22eSSteven Rostedt (Red Hat)	    my %tmp_config = %bad_configs;
32516071c22eSSteven Rostedt (Red Hat)
32526071c22eSSteven Rostedt (Red Hat)	    doprint "Try bottom half\n";
32536071c22eSSteven Rostedt (Red Hat)
32546071c22eSSteven Rostedt (Red Hat)	    my @bottomhalf = @diff_arr[$half+1 .. $#diff_arr];
32556071c22eSSteven Rostedt (Red Hat)
32566071c22eSSteven Rostedt (Red Hat)	    foreach my $item (@bottomhalf) {
32576071c22eSSteven Rostedt (Red Hat)		$tmp_config{$item} = $good_configs{$item};
32586071c22eSSteven Rostedt (Red Hat)	    }
32596071c22eSSteven Rostedt (Red Hat)
32606071c22eSSteven Rostedt (Red Hat)	    $runtest = process_new_config \%tmp_config, \%new_configs,
32616071c22eSSteven Rostedt (Red Hat)			    \%good_configs, \%bad_configs;
32626071c22eSSteven Rostedt (Red Hat)	}
32636071c22eSSteven Rostedt (Red Hat)    }
32646071c22eSSteven Rostedt (Red Hat)
32656071c22eSSteven Rostedt (Red Hat)    if ($runtest) {
32666071c22eSSteven Rostedt (Red Hat)	$ret = run_config_bisect_test $type;
32676071c22eSSteven Rostedt (Red Hat)	if ($ret) {
32686071c22eSSteven Rostedt (Red Hat)	    doprint "NEW GOOD CONFIG\n";
32696071c22eSSteven Rostedt (Red Hat)	    %good_configs = %new_configs;
32706071c22eSSteven Rostedt (Red Hat)	    run_command "mv $good_config ${good_config}.last";
32716071c22eSSteven Rostedt (Red Hat)	    save_config \%good_configs, $good_config;
32726071c22eSSteven Rostedt (Red Hat)	    %{$pgood} = %good_configs;
3273cf79fab6SSteven Rostedt	} else {
32746071c22eSSteven Rostedt (Red Hat)	    doprint "NEW BAD CONFIG\n";
32756071c22eSSteven Rostedt (Red Hat)	    %bad_configs = %new_configs;
32766071c22eSSteven Rostedt (Red Hat)	    run_command "mv $bad_config ${bad_config}.last";
32776071c22eSSteven Rostedt (Red Hat)	    save_config \%bad_configs, $bad_config;
32786071c22eSSteven Rostedt (Red Hat)	    %{$pbad} = %bad_configs;
32796071c22eSSteven Rostedt (Red Hat)	}
32806071c22eSSteven Rostedt (Red Hat)	return 0;
3281cf79fab6SSteven Rostedt    }
3282cf79fab6SSteven Rostedt
32836071c22eSSteven Rostedt (Red Hat)    fail "Hmm, need to do a mix match?\n";
32840a05c769SSteven Rostedt    return -1;
32850a05c769SSteven Rostedt}
32860a05c769SSteven Rostedt
32870a05c769SSteven Rostedtsub config_bisect {
32880a05c769SSteven Rostedt    my ($i) = @_;
32890a05c769SSteven Rostedt
32906071c22eSSteven Rostedt (Red Hat)    my $type = $config_bisect_type;
3291c4d1d11fSSteven Rostedt (Red Hat)    my $ret;
32920a05c769SSteven Rostedt
32936071c22eSSteven Rostedt (Red Hat)    $bad_config = $config_bisect;
32940a05c769SSteven Rostedt
329530f75da5SSteven Rostedt    if (defined($config_bisect_good)) {
32966071c22eSSteven Rostedt (Red Hat)	$good_config = $config_bisect_good;
32976071c22eSSteven Rostedt (Red Hat)    } elsif (defined($minconfig)) {
32986071c22eSSteven Rostedt (Red Hat)	$good_config = $minconfig;
32990a05c769SSteven Rostedt    } else {
33006071c22eSSteven Rostedt (Red Hat)	doprint "No config specified, checking if defconfig works";
3301c4d1d11fSSteven Rostedt (Red Hat)	$ret = run_bisect_test $type, "defconfig";
33026071c22eSSteven Rostedt (Red Hat)	if (!$ret) {
33036071c22eSSteven Rostedt (Red Hat)	    fail "Have no good config to compare with, please set CONFIG_BISECT_GOOD";
33046071c22eSSteven Rostedt (Red Hat)	    return 1;
33056071c22eSSteven Rostedt (Red Hat)	}
33066071c22eSSteven Rostedt (Red Hat)	$good_config = $output_config;
33070a05c769SSteven Rostedt    }
33080a05c769SSteven Rostedt
33096071c22eSSteven Rostedt (Red Hat)    # we don't want min configs to cause issues here.
33106071c22eSSteven Rostedt (Red Hat)    doprint "Disabling 'MIN_CONFIG' for this test\n";
33116071c22eSSteven Rostedt (Red Hat)    undef $minconfig;
33120a05c769SSteven Rostedt
33136071c22eSSteven Rostedt (Red Hat)    my %good_configs;
33146071c22eSSteven Rostedt (Red Hat)    my %bad_configs;
33156071c22eSSteven Rostedt (Red Hat)    my %tmp_configs;
33160a05c769SSteven Rostedt
33176071c22eSSteven Rostedt (Red Hat)    doprint "Run good configs through make oldconfig\n";
33186071c22eSSteven Rostedt (Red Hat)    assign_configs \%tmp_configs, $good_config;
33196071c22eSSteven Rostedt (Red Hat)    create_config "$good_config", \%tmp_configs;
33206071c22eSSteven Rostedt (Red Hat)    assign_configs \%good_configs, $output_config;
33210a05c769SSteven Rostedt
33226071c22eSSteven Rostedt (Red Hat)    doprint "Run bad configs through make oldconfig\n";
33236071c22eSSteven Rostedt (Red Hat)    assign_configs \%tmp_configs, $bad_config;
33246071c22eSSteven Rostedt (Red Hat)    create_config "$bad_config", \%tmp_configs;
33256071c22eSSteven Rostedt (Red Hat)    assign_configs \%bad_configs, $output_config;
33260a05c769SSteven Rostedt
33276071c22eSSteven Rostedt (Red Hat)    $good_config = "$tmpdir/good_config";
33286071c22eSSteven Rostedt (Red Hat)    $bad_config = "$tmpdir/bad_config";
33290a05c769SSteven Rostedt
33306071c22eSSteven Rostedt (Red Hat)    save_config \%good_configs, $good_config;
33316071c22eSSteven Rostedt (Red Hat)    save_config \%bad_configs, $bad_config;
33320a05c769SSteven Rostedt
3333c4d1d11fSSteven Rostedt (Red Hat)
3334c4d1d11fSSteven Rostedt (Red Hat)    if (defined($config_bisect_check) && $config_bisect_check ne "0") {
3335c4d1d11fSSteven Rostedt (Red Hat)	if ($config_bisect_check ne "good") {
3336c4d1d11fSSteven Rostedt (Red Hat)	    doprint "Testing bad config\n";
3337c4d1d11fSSteven Rostedt (Red Hat)
3338c4d1d11fSSteven Rostedt (Red Hat)	    $ret = run_bisect_test $type, "useconfig:$bad_config";
3339c4d1d11fSSteven Rostedt (Red Hat)	    if ($ret) {
3340c4d1d11fSSteven Rostedt (Red Hat)		fail "Bad config succeeded when expected to fail!";
3341c4d1d11fSSteven Rostedt (Red Hat)		return 0;
3342c4d1d11fSSteven Rostedt (Red Hat)	    }
3343c4d1d11fSSteven Rostedt (Red Hat)	}
3344c4d1d11fSSteven Rostedt (Red Hat)	if ($config_bisect_check ne "bad") {
3345c4d1d11fSSteven Rostedt (Red Hat)	    doprint "Testing good config\n";
3346c4d1d11fSSteven Rostedt (Red Hat)
3347c4d1d11fSSteven Rostedt (Red Hat)	    $ret = run_bisect_test $type, "useconfig:$good_config";
3348c4d1d11fSSteven Rostedt (Red Hat)	    if (!$ret) {
3349c4d1d11fSSteven Rostedt (Red Hat)		fail "Good config failed when expected to succeed!";
3350c4d1d11fSSteven Rostedt (Red Hat)		return 0;
3351c4d1d11fSSteven Rostedt (Red Hat)	    }
3352c4d1d11fSSteven Rostedt (Red Hat)	}
3353c4d1d11fSSteven Rostedt (Red Hat)    }
3354b0918612SSteven Rostedt
33550a05c769SSteven Rostedt    do {
33566071c22eSSteven Rostedt (Red Hat)	$ret = run_config_bisect \%good_configs, \%bad_configs;
335738fa3dc1SSteven Rostedt (Red Hat)	print_times;
33580a05c769SSteven Rostedt    } while (!$ret);
33590a05c769SSteven Rostedt
33600a05c769SSteven Rostedt    return $ret if ($ret < 0);
33615f9b6cedSSteven Rostedt
33625f9b6cedSSteven Rostedt    success $i;
33635f9b6cedSSteven Rostedt}
33645f9b6cedSSteven Rostedt
336527d934b2SSteven Rostedtsub patchcheck_reboot {
336627d934b2SSteven Rostedt    doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
3367bc7c5803SSteven Rostedt    reboot_to_good $patchcheck_sleep_time;
336827d934b2SSteven Rostedt}
336927d934b2SSteven Rostedt
33706c5ee0beSSteven Rostedtsub patchcheck {
33716c5ee0beSSteven Rostedt    my ($i) = @_;
33726c5ee0beSSteven Rostedt
33736c5ee0beSSteven Rostedt    die "PATCHCHECK_START[$i] not defined\n"
3374b5f4aea6SSteven Rostedt	if (!defined($patchcheck_start));
33756c5ee0beSSteven Rostedt    die "PATCHCHECK_TYPE[$i] not defined\n"
3376b5f4aea6SSteven Rostedt	if (!defined($patchcheck_type));
33776c5ee0beSSteven Rostedt
3378b5f4aea6SSteven Rostedt    my $start = $patchcheck_start;
33796c5ee0beSSteven Rostedt
338023a0e161SSteven Rostedt (Red Hat)    my $cherry = $patchcheck_cherry;
338123a0e161SSteven Rostedt (Red Hat)    if (!defined($cherry)) {
338223a0e161SSteven Rostedt (Red Hat)	$cherry = 0;
338323a0e161SSteven Rostedt (Red Hat)    }
338423a0e161SSteven Rostedt (Red Hat)
33856c5ee0beSSteven Rostedt    my $end = "HEAD";
3386b5f4aea6SSteven Rostedt    if (defined($patchcheck_end)) {
3387b5f4aea6SSteven Rostedt	$end = $patchcheck_end;
338823a0e161SSteven Rostedt (Red Hat)    } elsif ($cherry) {
338923a0e161SSteven Rostedt (Red Hat)	die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
33906c5ee0beSSteven Rostedt    }
33916c5ee0beSSteven Rostedt
3392a57419b3SSteven Rostedt    # Get the true sha1's since we can use things like HEAD~3
3393a57419b3SSteven Rostedt    $start = get_sha1($start);
3394a57419b3SSteven Rostedt    $end = get_sha1($end);
3395a57419b3SSteven Rostedt
3396b5f4aea6SSteven Rostedt    my $type = $patchcheck_type;
33976c5ee0beSSteven Rostedt
33986c5ee0beSSteven Rostedt    # Can't have a test without having a test to run
33996c5ee0beSSteven Rostedt    if ($type eq "test" && !defined($run_test)) {
34006c5ee0beSSteven Rostedt	$type = "boot";
34016c5ee0beSSteven Rostedt    }
34026c5ee0beSSteven Rostedt
340323a0e161SSteven Rostedt (Red Hat)    if ($cherry) {
340423a0e161SSteven Rostedt (Red Hat)	open (IN, "git cherry -v $start $end|") or
340523a0e161SSteven Rostedt (Red Hat)	    dodie "could not get git list";
340623a0e161SSteven Rostedt (Red Hat)    } else {
34076c5ee0beSSteven Rostedt	open (IN, "git log --pretty=oneline $end|") or
34086c5ee0beSSteven Rostedt	    dodie "could not get git list";
340923a0e161SSteven Rostedt (Red Hat)    }
34106c5ee0beSSteven Rostedt
34116c5ee0beSSteven Rostedt    my @list;
34126c5ee0beSSteven Rostedt
34136c5ee0beSSteven Rostedt    while (<IN>) {
34146c5ee0beSSteven Rostedt	chomp;
341523a0e161SSteven Rostedt (Red Hat)	# git cherry adds a '+' we want to remove
341623a0e161SSteven Rostedt (Red Hat)	s/^\+ //;
34176c5ee0beSSteven Rostedt	$list[$#list+1] = $_;
34186c5ee0beSSteven Rostedt	last if (/^$start/);
34196c5ee0beSSteven Rostedt    }
34206c5ee0beSSteven Rostedt    close(IN);
34216c5ee0beSSteven Rostedt
342223a0e161SSteven Rostedt (Red Hat)    if (!$cherry) {
34236c5ee0beSSteven Rostedt	if ($list[$#list] !~ /^$start/) {
34242b7d9b21SSteven Rostedt	    fail "SHA1 $start not found";
34256c5ee0beSSteven Rostedt	}
34266c5ee0beSSteven Rostedt
34276c5ee0beSSteven Rostedt	# go backwards in the list
34286c5ee0beSSteven Rostedt	@list = reverse @list;
342923a0e161SSteven Rostedt (Red Hat)    }
343023a0e161SSteven Rostedt (Red Hat)
343123a0e161SSteven Rostedt (Red Hat)    doprint("Going to test the following commits:\n");
343223a0e161SSteven Rostedt (Red Hat)    foreach my $l (@list) {
343323a0e161SSteven Rostedt (Red Hat)	doprint "$l\n";
343423a0e161SSteven Rostedt (Red Hat)    }
34356c5ee0beSSteven Rostedt
34366c5ee0beSSteven Rostedt    my $save_clean = $noclean;
34371990207dSSteven Rostedt    my %ignored_warnings;
34381990207dSSteven Rostedt
34391990207dSSteven Rostedt    if (defined($ignore_warnings)) {
34401990207dSSteven Rostedt	foreach my $sha1 (split /\s+/, $ignore_warnings) {
34411990207dSSteven Rostedt	    $ignored_warnings{$sha1} = 1;
34421990207dSSteven Rostedt	}
34431990207dSSteven Rostedt    }
34446c5ee0beSSteven Rostedt
34456c5ee0beSSteven Rostedt    $in_patchcheck = 1;
34466c5ee0beSSteven Rostedt    foreach my $item (@list) {
34476c5ee0beSSteven Rostedt	my $sha1 = $item;
34486c5ee0beSSteven Rostedt	$sha1 =~ s/^([[:xdigit:]]+).*/$1/;
34496c5ee0beSSteven Rostedt
34506c5ee0beSSteven Rostedt	doprint "\nProcessing commit $item\n\n";
34516c5ee0beSSteven Rostedt
34526c5ee0beSSteven Rostedt	run_command "git checkout $sha1" or
34536c5ee0beSSteven Rostedt	    die "Failed to checkout $sha1";
34546c5ee0beSSteven Rostedt
34556c5ee0beSSteven Rostedt	# only clean on the first and last patch
34566c5ee0beSSteven Rostedt	if ($item eq $list[0] ||
34576c5ee0beSSteven Rostedt	    $item eq $list[$#list]) {
34586c5ee0beSSteven Rostedt	    $noclean = $save_clean;
34596c5ee0beSSteven Rostedt	} else {
34606c5ee0beSSteven Rostedt	    $noclean = 1;
34616c5ee0beSSteven Rostedt	}
34626c5ee0beSSteven Rostedt
34636c5ee0beSSteven Rostedt	if (defined($minconfig)) {
34642b7d9b21SSteven Rostedt	    build "useconfig:$minconfig" or return 0;
34656c5ee0beSSteven Rostedt	} else {
34666c5ee0beSSteven Rostedt	    # ?? no config to use?
34672b7d9b21SSteven Rostedt	    build "oldconfig" or return 0;
34686c5ee0beSSteven Rostedt	}
34696c5ee0beSSteven Rostedt
34704283b169SSteven Rostedt (Red Hat)	# No need to do per patch checking if warnings file exists
34714283b169SSteven Rostedt (Red Hat)	if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
34724283b169SSteven Rostedt (Red Hat)	    check_patch_buildlog $sha1 or return 0;
34731990207dSSteven Rostedt	}
34746c5ee0beSSteven Rostedt
34754283b169SSteven Rostedt (Red Hat)	check_buildlog or return 0;
34764283b169SSteven Rostedt (Red Hat)
34776c5ee0beSSteven Rostedt	next if ($type eq "build");
34786c5ee0beSSteven Rostedt
34797faafbd6SSteven Rostedt	my $failed = 0;
34807faafbd6SSteven Rostedt
348164d98283SSteven Rostedt (Red Hat)	start_monitor_and_install or $failed = 1;
34827faafbd6SSteven Rostedt
34837faafbd6SSteven Rostedt	if (!$failed && $type ne "boot"){
34847faafbd6SSteven Rostedt	    do_run_test or $failed = 1;
34857faafbd6SSteven Rostedt	}
34867faafbd6SSteven Rostedt	end_monitor;
348738fa3dc1SSteven Rostedt (Red Hat)	if ($failed) {
348838fa3dc1SSteven Rostedt (Red Hat)	    print_times;
348938fa3dc1SSteven Rostedt (Red Hat)	    return 0;
349038fa3dc1SSteven Rostedt (Red Hat)	}
349127d934b2SSteven Rostedt	patchcheck_reboot;
349238fa3dc1SSteven Rostedt (Red Hat)	print_times;
34936c5ee0beSSteven Rostedt    }
34946c5ee0beSSteven Rostedt    $in_patchcheck = 0;
34956c5ee0beSSteven Rostedt    success $i;
34962b7d9b21SSteven Rostedt
34972b7d9b21SSteven Rostedt    return 1;
34986c5ee0beSSteven Rostedt}
34996c5ee0beSSteven Rostedt
3500b9066f6cSSteven Rostedtmy %depends;
3501ac6974c7SSteven Rostedtmy %depcount;
3502b9066f6cSSteven Rostedtmy $iflevel = 0;
3503b9066f6cSSteven Rostedtmy @ifdeps;
3504b9066f6cSSteven Rostedt
3505b9066f6cSSteven Rostedt# prevent recursion
3506b9066f6cSSteven Rostedtmy %read_kconfigs;
3507b9066f6cSSteven Rostedt
3508ac6974c7SSteven Rostedtsub add_dep {
3509ac6974c7SSteven Rostedt    # $config depends on $dep
3510ac6974c7SSteven Rostedt    my ($config, $dep) = @_;
3511ac6974c7SSteven Rostedt
3512ac6974c7SSteven Rostedt    if (defined($depends{$config})) {
3513ac6974c7SSteven Rostedt	$depends{$config} .= " " . $dep;
3514ac6974c7SSteven Rostedt    } else {
3515ac6974c7SSteven Rostedt	$depends{$config} = $dep;
3516ac6974c7SSteven Rostedt    }
3517ac6974c7SSteven Rostedt
3518ac6974c7SSteven Rostedt    # record the number of configs depending on $dep
3519ac6974c7SSteven Rostedt    if (defined $depcount{$dep}) {
3520ac6974c7SSteven Rostedt	$depcount{$dep}++;
3521ac6974c7SSteven Rostedt    } else {
3522ac6974c7SSteven Rostedt	$depcount{$dep} = 1;
3523ac6974c7SSteven Rostedt    }
3524ac6974c7SSteven Rostedt}
3525ac6974c7SSteven Rostedt
3526b9066f6cSSteven Rostedt# taken from streamline_config.pl
3527b9066f6cSSteven Rostedtsub read_kconfig {
3528b9066f6cSSteven Rostedt    my ($kconfig) = @_;
3529b9066f6cSSteven Rostedt
3530b9066f6cSSteven Rostedt    my $state = "NONE";
3531b9066f6cSSteven Rostedt    my $config;
3532b9066f6cSSteven Rostedt    my @kconfigs;
3533b9066f6cSSteven Rostedt
3534b9066f6cSSteven Rostedt    my $cont = 0;
3535b9066f6cSSteven Rostedt    my $line;
3536b9066f6cSSteven Rostedt
3537b9066f6cSSteven Rostedt
3538b9066f6cSSteven Rostedt    if (! -f $kconfig) {
3539b9066f6cSSteven Rostedt	doprint "file $kconfig does not exist, skipping\n";
3540b9066f6cSSteven Rostedt	return;
3541b9066f6cSSteven Rostedt    }
3542b9066f6cSSteven Rostedt
3543b9066f6cSSteven Rostedt    open(KIN, "$kconfig")
3544b9066f6cSSteven Rostedt	or die "Can't open $kconfig";
3545b9066f6cSSteven Rostedt    while (<KIN>) {
3546b9066f6cSSteven Rostedt	chomp;
3547b9066f6cSSteven Rostedt
3548b9066f6cSSteven Rostedt	# Make sure that lines ending with \ continue
3549b9066f6cSSteven Rostedt	if ($cont) {
3550b9066f6cSSteven Rostedt	    $_ = $line . " " . $_;
3551b9066f6cSSteven Rostedt	}
3552b9066f6cSSteven Rostedt
3553b9066f6cSSteven Rostedt	if (s/\\$//) {
3554b9066f6cSSteven Rostedt	    $cont = 1;
3555b9066f6cSSteven Rostedt	    $line = $_;
3556b9066f6cSSteven Rostedt	    next;
3557b9066f6cSSteven Rostedt	}
3558b9066f6cSSteven Rostedt
3559b9066f6cSSteven Rostedt	$cont = 0;
3560b9066f6cSSteven Rostedt
3561b9066f6cSSteven Rostedt	# collect any Kconfig sources
3562b9066f6cSSteven Rostedt	if (/^source\s*"(.*)"/) {
3563b9066f6cSSteven Rostedt	    $kconfigs[$#kconfigs+1] = $1;
3564b9066f6cSSteven Rostedt	}
3565b9066f6cSSteven Rostedt
3566b9066f6cSSteven Rostedt	# configs found
3567b9066f6cSSteven Rostedt	if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3568b9066f6cSSteven Rostedt	    $state = "NEW";
3569b9066f6cSSteven Rostedt	    $config = $2;
3570b9066f6cSSteven Rostedt
3571b9066f6cSSteven Rostedt	    for (my $i = 0; $i < $iflevel; $i++) {
3572ac6974c7SSteven Rostedt		add_dep $config, $ifdeps[$i];
3573b9066f6cSSteven Rostedt	    }
3574b9066f6cSSteven Rostedt
3575b9066f6cSSteven Rostedt	# collect the depends for the config
3576b9066f6cSSteven Rostedt	} elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3577b9066f6cSSteven Rostedt
3578ac6974c7SSteven Rostedt	    add_dep $config, $1;
3579b9066f6cSSteven Rostedt
3580b9066f6cSSteven Rostedt	# Get the configs that select this config
3581ac6974c7SSteven Rostedt	} elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3582ac6974c7SSteven Rostedt
3583ac6974c7SSteven Rostedt	    # selected by depends on config
3584ac6974c7SSteven Rostedt	    add_dep $1, $config;
3585b9066f6cSSteven Rostedt
3586b9066f6cSSteven Rostedt	# Check for if statements
3587b9066f6cSSteven Rostedt	} elsif (/^if\s+(.*\S)\s*$/) {
3588b9066f6cSSteven Rostedt	    my $deps = $1;
3589b9066f6cSSteven Rostedt	    # remove beginning and ending non text
3590b9066f6cSSteven Rostedt	    $deps =~ s/^[^a-zA-Z0-9_]*//;
3591b9066f6cSSteven Rostedt	    $deps =~ s/[^a-zA-Z0-9_]*$//;
3592b9066f6cSSteven Rostedt
3593b9066f6cSSteven Rostedt	    my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3594b9066f6cSSteven Rostedt
3595b9066f6cSSteven Rostedt	    $ifdeps[$iflevel++] = join ':', @deps;
3596b9066f6cSSteven Rostedt
3597b9066f6cSSteven Rostedt	} elsif (/^endif/) {
3598b9066f6cSSteven Rostedt
3599b9066f6cSSteven Rostedt	    $iflevel-- if ($iflevel);
3600b9066f6cSSteven Rostedt
3601b9066f6cSSteven Rostedt	# stop on "help"
3602b9066f6cSSteven Rostedt	} elsif (/^\s*help\s*$/) {
3603b9066f6cSSteven Rostedt	    $state = "NONE";
3604b9066f6cSSteven Rostedt	}
3605b9066f6cSSteven Rostedt    }
3606b9066f6cSSteven Rostedt    close(KIN);
3607b9066f6cSSteven Rostedt
3608b9066f6cSSteven Rostedt    # read in any configs that were found.
3609b9066f6cSSteven Rostedt    foreach $kconfig (@kconfigs) {
3610b9066f6cSSteven Rostedt	if (!defined($read_kconfigs{$kconfig})) {
3611b9066f6cSSteven Rostedt	    $read_kconfigs{$kconfig} = 1;
3612b9066f6cSSteven Rostedt	    read_kconfig("$builddir/$kconfig");
3613b9066f6cSSteven Rostedt	}
3614b9066f6cSSteven Rostedt    }
3615b9066f6cSSteven Rostedt}
3616b9066f6cSSteven Rostedt
3617b9066f6cSSteven Rostedtsub read_depends {
3618b9066f6cSSteven Rostedt    # find out which arch this is by the kconfig file
3619b9066f6cSSteven Rostedt    open (IN, $output_config)
3620b9066f6cSSteven Rostedt	or dodie "Failed to read $output_config";
3621b9066f6cSSteven Rostedt    my $arch;
3622b9066f6cSSteven Rostedt    while (<IN>) {
3623b9066f6cSSteven Rostedt	if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3624b9066f6cSSteven Rostedt	    $arch = $1;
3625b9066f6cSSteven Rostedt	    last;
3626b9066f6cSSteven Rostedt	}
3627b9066f6cSSteven Rostedt    }
3628b9066f6cSSteven Rostedt    close IN;
3629b9066f6cSSteven Rostedt
3630b9066f6cSSteven Rostedt    if (!defined($arch)) {
3631b9066f6cSSteven Rostedt	doprint "Could not find arch from config file\n";
3632b9066f6cSSteven Rostedt	doprint "no dependencies used\n";
3633b9066f6cSSteven Rostedt	return;
3634b9066f6cSSteven Rostedt    }
3635b9066f6cSSteven Rostedt
3636b9066f6cSSteven Rostedt    # arch is really the subarch, we need to know
3637b9066f6cSSteven Rostedt    # what directory to look at.
3638b9066f6cSSteven Rostedt    if ($arch eq "i386" || $arch eq "x86_64") {
3639b9066f6cSSteven Rostedt	$arch = "x86";
3640b9066f6cSSteven Rostedt    } elsif ($arch =~ /^tile/) {
3641b9066f6cSSteven Rostedt	$arch = "tile";
3642b9066f6cSSteven Rostedt    }
3643b9066f6cSSteven Rostedt
3644b9066f6cSSteven Rostedt    my $kconfig = "$builddir/arch/$arch/Kconfig";
3645b9066f6cSSteven Rostedt
3646b9066f6cSSteven Rostedt    if (! -f $kconfig && $arch =~ /\d$/) {
3647b9066f6cSSteven Rostedt	my $orig = $arch;
3648b9066f6cSSteven Rostedt 	# some subarchs have numbers, truncate them
3649b9066f6cSSteven Rostedt	$arch =~ s/\d*$//;
3650b9066f6cSSteven Rostedt	$kconfig = "$builddir/arch/$arch/Kconfig";
3651b9066f6cSSteven Rostedt	if (! -f $kconfig) {
3652b9066f6cSSteven Rostedt	    doprint "No idea what arch dir $orig is for\n";
3653b9066f6cSSteven Rostedt	    doprint "no dependencies used\n";
3654b9066f6cSSteven Rostedt	    return;
3655b9066f6cSSteven Rostedt	}
3656b9066f6cSSteven Rostedt    }
3657b9066f6cSSteven Rostedt
3658b9066f6cSSteven Rostedt    read_kconfig($kconfig);
3659b9066f6cSSteven Rostedt}
3660b9066f6cSSteven Rostedt
36614c4ab120SSteven Rostedtsub make_new_config {
36624c4ab120SSteven Rostedt    my @configs = @_;
36634c4ab120SSteven Rostedt
36644c4ab120SSteven Rostedt    open (OUT, ">$output_config")
36654c4ab120SSteven Rostedt	or dodie "Failed to write $output_config";
36664c4ab120SSteven Rostedt
36674c4ab120SSteven Rostedt    foreach my $config (@configs) {
36684c4ab120SSteven Rostedt	print OUT "$config\n";
36694c4ab120SSteven Rostedt    }
36704c4ab120SSteven Rostedt    close OUT;
36714c4ab120SSteven Rostedt}
36724c4ab120SSteven Rostedt
3673ac6974c7SSteven Rostedtsub chomp_config {
3674ac6974c7SSteven Rostedt    my ($config) = @_;
3675ac6974c7SSteven Rostedt
3676ac6974c7SSteven Rostedt    $config =~ s/CONFIG_//;
3677ac6974c7SSteven Rostedt
3678ac6974c7SSteven Rostedt    return $config;
3679ac6974c7SSteven Rostedt}
3680ac6974c7SSteven Rostedt
3681b9066f6cSSteven Rostedtsub get_depends {
3682b9066f6cSSteven Rostedt    my ($dep) = @_;
3683b9066f6cSSteven Rostedt
3684ac6974c7SSteven Rostedt    my $kconfig = chomp_config $dep;
3685b9066f6cSSteven Rostedt
3686b9066f6cSSteven Rostedt    $dep = $depends{"$kconfig"};
3687b9066f6cSSteven Rostedt
3688b9066f6cSSteven Rostedt    # the dep string we have saves the dependencies as they
3689b9066f6cSSteven Rostedt    # were found, including expressions like ! && ||. We
3690b9066f6cSSteven Rostedt    # want to split this out into just an array of configs.
3691b9066f6cSSteven Rostedt
3692b9066f6cSSteven Rostedt    my $valid = "A-Za-z_0-9";
3693b9066f6cSSteven Rostedt
3694b9066f6cSSteven Rostedt    my @configs;
3695b9066f6cSSteven Rostedt
3696b9066f6cSSteven Rostedt    while ($dep =~ /[$valid]/) {
3697b9066f6cSSteven Rostedt
3698b9066f6cSSteven Rostedt	if ($dep =~ /^[^$valid]*([$valid]+)/) {
3699b9066f6cSSteven Rostedt	    my $conf = "CONFIG_" . $1;
3700b9066f6cSSteven Rostedt
3701b9066f6cSSteven Rostedt	    $configs[$#configs + 1] = $conf;
3702b9066f6cSSteven Rostedt
3703b9066f6cSSteven Rostedt	    $dep =~ s/^[^$valid]*[$valid]+//;
3704b9066f6cSSteven Rostedt	} else {
3705b9066f6cSSteven Rostedt	    die "this should never happen";
3706b9066f6cSSteven Rostedt	}
3707b9066f6cSSteven Rostedt    }
3708b9066f6cSSteven Rostedt
3709b9066f6cSSteven Rostedt    return @configs;
3710b9066f6cSSteven Rostedt}
3711b9066f6cSSteven Rostedt
3712b9066f6cSSteven Rostedtmy %min_configs;
3713b9066f6cSSteven Rostedtmy %keep_configs;
371443d1b651SSteven Rostedtmy %save_configs;
3715b9066f6cSSteven Rostedtmy %processed_configs;
3716b9066f6cSSteven Rostedtmy %nochange_config;
3717b9066f6cSSteven Rostedt
3718b9066f6cSSteven Rostedtsub test_this_config {
3719b9066f6cSSteven Rostedt    my ($config) = @_;
3720b9066f6cSSteven Rostedt
3721b9066f6cSSteven Rostedt    my $found;
3722b9066f6cSSteven Rostedt
3723b9066f6cSSteven Rostedt    # if we already processed this config, skip it
3724b9066f6cSSteven Rostedt    if (defined($processed_configs{$config})) {
3725b9066f6cSSteven Rostedt	return undef;
3726b9066f6cSSteven Rostedt    }
3727b9066f6cSSteven Rostedt    $processed_configs{$config} = 1;
3728b9066f6cSSteven Rostedt
3729b9066f6cSSteven Rostedt    # if this config failed during this round, skip it
3730b9066f6cSSteven Rostedt    if (defined($nochange_config{$config})) {
3731b9066f6cSSteven Rostedt	return undef;
3732b9066f6cSSteven Rostedt    }
3733b9066f6cSSteven Rostedt
3734ac6974c7SSteven Rostedt    my $kconfig = chomp_config $config;
3735b9066f6cSSteven Rostedt
3736b9066f6cSSteven Rostedt    # Test dependencies first
3737b9066f6cSSteven Rostedt    if (defined($depends{"$kconfig"})) {
3738b9066f6cSSteven Rostedt	my @parents = get_depends $config;
3739b9066f6cSSteven Rostedt	foreach my $parent (@parents) {
3740b9066f6cSSteven Rostedt	    # if the parent is in the min config, check it first
3741b9066f6cSSteven Rostedt	    next if (!defined($min_configs{$parent}));
3742b9066f6cSSteven Rostedt	    $found = test_this_config($parent);
3743b9066f6cSSteven Rostedt	    if (defined($found)) {
3744b9066f6cSSteven Rostedt		return $found;
3745b9066f6cSSteven Rostedt	    }
3746b9066f6cSSteven Rostedt	}
3747b9066f6cSSteven Rostedt    }
3748b9066f6cSSteven Rostedt
3749b9066f6cSSteven Rostedt    # Remove this config from the list of configs
3750fb16d891SAdam Lee    # do a make olddefconfig and then read the resulting
3751b9066f6cSSteven Rostedt    # .config to make sure it is missing the config that
3752b9066f6cSSteven Rostedt    # we had before
3753b9066f6cSSteven Rostedt    my %configs = %min_configs;
3754b9066f6cSSteven Rostedt    delete $configs{$config};
3755b9066f6cSSteven Rostedt    make_new_config ((values %configs), (values %keep_configs));
3756b9066f6cSSteven Rostedt    make_oldconfig;
3757b9066f6cSSteven Rostedt    undef %configs;
3758b9066f6cSSteven Rostedt    assign_configs \%configs, $output_config;
3759b9066f6cSSteven Rostedt
37609972fc0bSSteven Rostedt (Red Hat)    if (!defined($configs{$config}) || $configs{$config} =~ /^#/) {
37619972fc0bSSteven Rostedt (Red Hat)	return $config;
37629972fc0bSSteven Rostedt (Red Hat)    }
3763b9066f6cSSteven Rostedt
3764b9066f6cSSteven Rostedt    doprint "disabling config $config did not change .config\n";
3765b9066f6cSSteven Rostedt
3766b9066f6cSSteven Rostedt    $nochange_config{$config} = 1;
3767b9066f6cSSteven Rostedt
3768b9066f6cSSteven Rostedt    return undef;
3769b9066f6cSSteven Rostedt}
3770b9066f6cSSteven Rostedt
37714c4ab120SSteven Rostedtsub make_min_config {
37724c4ab120SSteven Rostedt    my ($i) = @_;
37734c4ab120SSteven Rostedt
3774ccc513b6SSteven Rostedt    my $type = $minconfig_type;
3775ccc513b6SSteven Rostedt    if ($type ne "boot" && $type ne "test") {
3776ccc513b6SSteven Rostedt	fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3777ccc513b6SSteven Rostedt	    " make_min_config works only with 'boot' and 'test'\n" and return;
3778ccc513b6SSteven Rostedt    }
3779ccc513b6SSteven Rostedt
37804c4ab120SSteven Rostedt    if (!defined($output_minconfig)) {
37814c4ab120SSteven Rostedt	fail "OUTPUT_MIN_CONFIG not defined" and return;
37824c4ab120SSteven Rostedt    }
378335ce5952SSteven Rostedt
378435ce5952SSteven Rostedt    # If output_minconfig exists, and the start_minconfig
378535ce5952SSteven Rostedt    # came from min_config, than ask if we should use
378635ce5952SSteven Rostedt    # that instead.
378735ce5952SSteven Rostedt    if (-f $output_minconfig && !$start_minconfig_defined) {
378835ce5952SSteven Rostedt	print "$output_minconfig exists\n";
378943de3316SSteven Rostedt	if (!defined($use_output_minconfig)) {
379035ce5952SSteven Rostedt	    if (read_yn " Use it as minconfig?") {
379135ce5952SSteven Rostedt		$start_minconfig = $output_minconfig;
379235ce5952SSteven Rostedt	    }
379343de3316SSteven Rostedt	} elsif ($use_output_minconfig > 0) {
379443de3316SSteven Rostedt	    doprint "Using $output_minconfig as MIN_CONFIG\n";
379543de3316SSteven Rostedt	    $start_minconfig = $output_minconfig;
379643de3316SSteven Rostedt	} else {
379743de3316SSteven Rostedt	    doprint "Set to still use MIN_CONFIG as starting point\n";
379843de3316SSteven Rostedt	}
379935ce5952SSteven Rostedt    }
380035ce5952SSteven Rostedt
38014c4ab120SSteven Rostedt    if (!defined($start_minconfig)) {
38024c4ab120SSteven Rostedt	fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
38034c4ab120SSteven Rostedt    }
38044c4ab120SSteven Rostedt
380535ce5952SSteven Rostedt    my $temp_config = "$tmpdir/temp_config";
380635ce5952SSteven Rostedt
38074c4ab120SSteven Rostedt    # First things first. We build an allnoconfig to find
38084c4ab120SSteven Rostedt    # out what the defaults are that we can't touch.
38094c4ab120SSteven Rostedt    # Some are selections, but we really can't handle selections.
38104c4ab120SSteven Rostedt
38114c4ab120SSteven Rostedt    my $save_minconfig = $minconfig;
38124c4ab120SSteven Rostedt    undef $minconfig;
38134c4ab120SSteven Rostedt
38144c4ab120SSteven Rostedt    run_command "$make allnoconfig" or return 0;
38154c4ab120SSteven Rostedt
3816b9066f6cSSteven Rostedt    read_depends;
3817b9066f6cSSteven Rostedt
38184c4ab120SSteven Rostedt    process_config_ignore $output_config;
3819b9066f6cSSteven Rostedt
382043d1b651SSteven Rostedt    undef %save_configs;
3821b9066f6cSSteven Rostedt    undef %min_configs;
38224c4ab120SSteven Rostedt
38234c4ab120SSteven Rostedt    if (defined($ignore_config)) {
38244c4ab120SSteven Rostedt	# make sure the file exists
38254c4ab120SSteven Rostedt	`touch $ignore_config`;
382643d1b651SSteven Rostedt	assign_configs \%save_configs, $ignore_config;
38274c4ab120SSteven Rostedt    }
38284c4ab120SSteven Rostedt
382943d1b651SSteven Rostedt    %keep_configs = %save_configs;
383043d1b651SSteven Rostedt
38314c4ab120SSteven Rostedt    doprint "Load initial configs from $start_minconfig\n";
38324c4ab120SSteven Rostedt
38334c4ab120SSteven Rostedt    # Look at the current min configs, and save off all the
38344c4ab120SSteven Rostedt    # ones that were set via the allnoconfig
38354c4ab120SSteven Rostedt    assign_configs \%min_configs, $start_minconfig;
38364c4ab120SSteven Rostedt
38374c4ab120SSteven Rostedt    my @config_keys = keys %min_configs;
38384c4ab120SSteven Rostedt
3839ac6974c7SSteven Rostedt    # All configs need a depcount
3840ac6974c7SSteven Rostedt    foreach my $config (@config_keys) {
3841ac6974c7SSteven Rostedt	my $kconfig = chomp_config $config;
3842ac6974c7SSteven Rostedt	if (!defined $depcount{$kconfig}) {
3843ac6974c7SSteven Rostedt		$depcount{$kconfig} = 0;
3844ac6974c7SSteven Rostedt	}
3845ac6974c7SSteven Rostedt    }
3846ac6974c7SSteven Rostedt
38474c4ab120SSteven Rostedt    # Remove anything that was set by the make allnoconfig
38484c4ab120SSteven Rostedt    # we shouldn't need them as they get set for us anyway.
38494c4ab120SSteven Rostedt    foreach my $config (@config_keys) {
38504c4ab120SSteven Rostedt	# Remove anything in the ignore_config
38514c4ab120SSteven Rostedt	if (defined($keep_configs{$config})) {
38524c4ab120SSteven Rostedt	    my $file = $ignore_config;
38534c4ab120SSteven Rostedt	    $file =~ s,.*/(.*?)$,$1,;
38544c4ab120SSteven Rostedt	    doprint "$config set by $file ... ignored\n";
38554c4ab120SSteven Rostedt	    delete $min_configs{$config};
38564c4ab120SSteven Rostedt	    next;
38574c4ab120SSteven Rostedt	}
38584c4ab120SSteven Rostedt	# But make sure the settings are the same. If a min config
38594c4ab120SSteven Rostedt	# sets a selection, we do not want to get rid of it if
38604c4ab120SSteven Rostedt	# it is not the same as what we have. Just move it into
38614c4ab120SSteven Rostedt	# the keep configs.
38624c4ab120SSteven Rostedt	if (defined($config_ignore{$config})) {
38634c4ab120SSteven Rostedt	    if ($config_ignore{$config} ne $min_configs{$config}) {
38644c4ab120SSteven Rostedt		doprint "$config is in allnoconfig as '$config_ignore{$config}'";
38654c4ab120SSteven Rostedt		doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
38664c4ab120SSteven Rostedt		$keep_configs{$config} = $min_configs{$config};
38674c4ab120SSteven Rostedt	    } else {
38684c4ab120SSteven Rostedt		doprint "$config set by allnoconfig ... ignored\n";
38694c4ab120SSteven Rostedt	    }
38704c4ab120SSteven Rostedt	    delete $min_configs{$config};
38714c4ab120SSteven Rostedt	}
38724c4ab120SSteven Rostedt    }
38734c4ab120SSteven Rostedt
38744c4ab120SSteven Rostedt    my $done = 0;
3875b9066f6cSSteven Rostedt    my $take_two = 0;
38764c4ab120SSteven Rostedt
38774c4ab120SSteven Rostedt    while (!$done) {
38784c4ab120SSteven Rostedt
38794c4ab120SSteven Rostedt	my $config;
38804c4ab120SSteven Rostedt	my $found;
38814c4ab120SSteven Rostedt
38824c4ab120SSteven Rostedt	# Now disable each config one by one and do a make oldconfig
38834c4ab120SSteven Rostedt	# till we find a config that changes our list.
38844c4ab120SSteven Rostedt
38854c4ab120SSteven Rostedt	my @test_configs = keys %min_configs;
3886ac6974c7SSteven Rostedt
3887ac6974c7SSteven Rostedt	# Sort keys by who is most dependent on
3888ac6974c7SSteven Rostedt	@test_configs = sort  { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3889ac6974c7SSteven Rostedt			  @test_configs ;
3890ac6974c7SSteven Rostedt
3891ac6974c7SSteven Rostedt	# Put configs that did not modify the config at the end.
38924c4ab120SSteven Rostedt	my $reset = 1;
38934c4ab120SSteven Rostedt	for (my $i = 0; $i < $#test_configs; $i++) {
38944c4ab120SSteven Rostedt	    if (!defined($nochange_config{$test_configs[0]})) {
38954c4ab120SSteven Rostedt		$reset = 0;
38964c4ab120SSteven Rostedt		last;
38974c4ab120SSteven Rostedt	    }
38984c4ab120SSteven Rostedt	    # This config didn't change the .config last time.
38994c4ab120SSteven Rostedt	    # Place it at the end
39004c4ab120SSteven Rostedt	    my $config = shift @test_configs;
39014c4ab120SSteven Rostedt	    push @test_configs, $config;
39024c4ab120SSteven Rostedt	}
39034c4ab120SSteven Rostedt
39044c4ab120SSteven Rostedt	# if every test config has failed to modify the .config file
39054c4ab120SSteven Rostedt	# in the past, then reset and start over.
39064c4ab120SSteven Rostedt	if ($reset) {
39074c4ab120SSteven Rostedt	    undef %nochange_config;
39084c4ab120SSteven Rostedt	}
39094c4ab120SSteven Rostedt
3910b9066f6cSSteven Rostedt	undef %processed_configs;
3911b9066f6cSSteven Rostedt
39124c4ab120SSteven Rostedt	foreach my $config (@test_configs) {
39134c4ab120SSteven Rostedt
3914b9066f6cSSteven Rostedt	    $found = test_this_config $config;
39154c4ab120SSteven Rostedt
3916b9066f6cSSteven Rostedt	    last if (defined($found));
39174c4ab120SSteven Rostedt
39184c4ab120SSteven Rostedt	    # oh well, try another config
39194c4ab120SSteven Rostedt	}
39204c4ab120SSteven Rostedt
39214c4ab120SSteven Rostedt	if (!defined($found)) {
3922b9066f6cSSteven Rostedt	    # we could have failed due to the nochange_config hash
3923b9066f6cSSteven Rostedt	    # reset and try again
3924b9066f6cSSteven Rostedt	    if (!$take_two) {
3925b9066f6cSSteven Rostedt		undef %nochange_config;
3926b9066f6cSSteven Rostedt		$take_two = 1;
3927b9066f6cSSteven Rostedt		next;
3928b9066f6cSSteven Rostedt	    }
39294c4ab120SSteven Rostedt	    doprint "No more configs found that we can disable\n";
39304c4ab120SSteven Rostedt	    $done = 1;
39314c4ab120SSteven Rostedt	    last;
39324c4ab120SSteven Rostedt	}
3933b9066f6cSSteven Rostedt	$take_two = 0;
39344c4ab120SSteven Rostedt
39354c4ab120SSteven Rostedt	$config = $found;
39364c4ab120SSteven Rostedt
39374c4ab120SSteven Rostedt	doprint "Test with $config disabled\n";
39384c4ab120SSteven Rostedt
39394c4ab120SSteven Rostedt	# set in_bisect to keep build and monitor from dieing
39404c4ab120SSteven Rostedt	$in_bisect = 1;
39414c4ab120SSteven Rostedt
39424c4ab120SSteven Rostedt	my $failed = 0;
3943bf1c95abSSteven Rostedt	build "oldconfig" or $failed = 1;
3944bf1c95abSSteven Rostedt	if (!$failed) {
394564d98283SSteven Rostedt (Red Hat)		start_monitor_and_install or $failed = 1;
3946ccc513b6SSteven Rostedt
3947ccc513b6SSteven Rostedt		if ($type eq "test" && !$failed) {
3948ccc513b6SSteven Rostedt		    do_run_test or $failed = 1;
3949ccc513b6SSteven Rostedt		}
3950ccc513b6SSteven Rostedt
39514c4ab120SSteven Rostedt		end_monitor;
3952bf1c95abSSteven Rostedt	}
39534c4ab120SSteven Rostedt
39544c4ab120SSteven Rostedt	$in_bisect = 0;
39554c4ab120SSteven Rostedt
39564c4ab120SSteven Rostedt	if ($failed) {
3957b9066f6cSSteven Rostedt	    doprint "$min_configs{$config} is needed to boot the box... keeping\n";
39584c4ab120SSteven Rostedt	    # this config is needed, add it to the ignore list.
39594c4ab120SSteven Rostedt	    $keep_configs{$config} = $min_configs{$config};
396043d1b651SSteven Rostedt	    $save_configs{$config} = $min_configs{$config};
39614c4ab120SSteven Rostedt	    delete $min_configs{$config};
396235ce5952SSteven Rostedt
396335ce5952SSteven Rostedt	    # update new ignore configs
396435ce5952SSteven Rostedt	    if (defined($ignore_config)) {
396535ce5952SSteven Rostedt		open (OUT, ">$temp_config")
396635ce5952SSteven Rostedt		    or die "Can't write to $temp_config";
396743d1b651SSteven Rostedt		foreach my $config (keys %save_configs) {
396843d1b651SSteven Rostedt		    print OUT "$save_configs{$config}\n";
396935ce5952SSteven Rostedt		}
397035ce5952SSteven Rostedt		close OUT;
397135ce5952SSteven Rostedt		run_command "mv $temp_config $ignore_config" or
397235ce5952SSteven Rostedt		    dodie "failed to copy update to $ignore_config";
397335ce5952SSteven Rostedt	    }
397435ce5952SSteven Rostedt
39754c4ab120SSteven Rostedt	} else {
39764c4ab120SSteven Rostedt	    # We booted without this config, remove it from the minconfigs.
39774c4ab120SSteven Rostedt	    doprint "$config is not needed, disabling\n";
39784c4ab120SSteven Rostedt
39794c4ab120SSteven Rostedt	    delete $min_configs{$config};
39804c4ab120SSteven Rostedt
39814c4ab120SSteven Rostedt	    # Also disable anything that is not enabled in this config
39824c4ab120SSteven Rostedt	    my %configs;
39834c4ab120SSteven Rostedt	    assign_configs \%configs, $output_config;
39844c4ab120SSteven Rostedt	    my @config_keys = keys %min_configs;
39854c4ab120SSteven Rostedt	    foreach my $config (@config_keys) {
39864c4ab120SSteven Rostedt		if (!defined($configs{$config})) {
39874c4ab120SSteven Rostedt		    doprint "$config is not set, disabling\n";
39884c4ab120SSteven Rostedt		    delete $min_configs{$config};
39894c4ab120SSteven Rostedt		}
39904c4ab120SSteven Rostedt	    }
39914c4ab120SSteven Rostedt
39924c4ab120SSteven Rostedt	    # Save off all the current mandidory configs
399335ce5952SSteven Rostedt	    open (OUT, ">$temp_config")
399435ce5952SSteven Rostedt		or die "Can't write to $temp_config";
39954c4ab120SSteven Rostedt	    foreach my $config (keys %keep_configs) {
39964c4ab120SSteven Rostedt		print OUT "$keep_configs{$config}\n";
39974c4ab120SSteven Rostedt	    }
39984c4ab120SSteven Rostedt	    foreach my $config (keys %min_configs) {
39994c4ab120SSteven Rostedt		print OUT "$min_configs{$config}\n";
40004c4ab120SSteven Rostedt	    }
40014c4ab120SSteven Rostedt	    close OUT;
400235ce5952SSteven Rostedt
400335ce5952SSteven Rostedt	    run_command "mv $temp_config $output_minconfig" or
400435ce5952SSteven Rostedt		dodie "failed to copy update to $output_minconfig";
40054c4ab120SSteven Rostedt	}
40064c4ab120SSteven Rostedt
40074c4ab120SSteven Rostedt	doprint "Reboot and wait $sleep_time seconds\n";
4008bc7c5803SSteven Rostedt	reboot_to_good $sleep_time;
40094c4ab120SSteven Rostedt    }
40104c4ab120SSteven Rostedt
40114c4ab120SSteven Rostedt    success $i;
40124c4ab120SSteven Rostedt    return 1;
40134c4ab120SSteven Rostedt}
40144c4ab120SSteven Rostedt
40154283b169SSteven Rostedt (Red Hat)sub make_warnings_file {
40164283b169SSteven Rostedt (Red Hat)    my ($i) = @_;
40174283b169SSteven Rostedt (Red Hat)
40184283b169SSteven Rostedt (Red Hat)    if (!defined($warnings_file)) {
40194283b169SSteven Rostedt (Red Hat)	dodie "Must define WARNINGS_FILE for make_warnings_file test";
40204283b169SSteven Rostedt (Red Hat)    }
40214283b169SSteven Rostedt (Red Hat)
40224283b169SSteven Rostedt (Red Hat)    if ($build_type eq "nobuild") {
40234283b169SSteven Rostedt (Red Hat)	dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
40244283b169SSteven Rostedt (Red Hat)    }
40254283b169SSteven Rostedt (Red Hat)
40264283b169SSteven Rostedt (Red Hat)    build $build_type or dodie "Failed to build";
40274283b169SSteven Rostedt (Red Hat)
40284283b169SSteven Rostedt (Red Hat)    open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
40294283b169SSteven Rostedt (Red Hat)
40304283b169SSteven Rostedt (Red Hat)    open(IN, $buildlog) or dodie "Can't open $buildlog";
40314283b169SSteven Rostedt (Red Hat)    while (<IN>) {
40324283b169SSteven Rostedt (Red Hat)
40334283b169SSteven Rostedt (Red Hat)	# Some compilers use UTF-8 extended for quotes
40344283b169SSteven Rostedt (Red Hat)	# for distcc heterogeneous systems, this causes issues
40354283b169SSteven Rostedt (Red Hat)	s/$utf8_quote/'/g;
40364283b169SSteven Rostedt (Red Hat)
40374283b169SSteven Rostedt (Red Hat)	if (/$check_build_re/) {
40384283b169SSteven Rostedt (Red Hat)	    print OUT;
40394283b169SSteven Rostedt (Red Hat)	}
40404283b169SSteven Rostedt (Red Hat)    }
40414283b169SSteven Rostedt (Red Hat)    close(IN);
40424283b169SSteven Rostedt (Red Hat)
40434283b169SSteven Rostedt (Red Hat)    close(OUT);
40444283b169SSteven Rostedt (Red Hat)
40454283b169SSteven Rostedt (Red Hat)    success $i;
40464283b169SSteven Rostedt (Red Hat)}
40474283b169SSteven Rostedt (Red Hat)
40485269faadSSatoru Takeuchi$#ARGV < 1 or die "ktest.pl version: $VERSION\n   usage: ktest.pl [config-file]\n";
40492545eb61SSteven Rostedt
40508d1491baSSteven Rostedtif ($#ARGV == 0) {
40518d1491baSSteven Rostedt    $ktest_config = $ARGV[0];
40528d1491baSSteven Rostedt    if (! -f $ktest_config) {
40538d1491baSSteven Rostedt	print "$ktest_config does not exist.\n";
405435ce5952SSteven Rostedt	if (!read_yn "Create it?") {
40558d1491baSSteven Rostedt	    exit 0;
40568d1491baSSteven Rostedt	}
40578d1491baSSteven Rostedt    }
40588d1491baSSteven Rostedt}
40598d1491baSSteven Rostedt
40608d1491baSSteven Rostedtif (! -f $ktest_config) {
4061dbd3783bSSteven Rostedt    $newconfig = 1;
4062c4261d0fSSteven Rostedt    get_test_case;
40638d1491baSSteven Rostedt    open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
40648d1491baSSteven Rostedt    print OUT << "EOF"
40658d1491baSSteven Rostedt# Generated by ktest.pl
40668d1491baSSteven Rostedt#
40670e7a22deSSteven Rostedt
40680e7a22deSSteven Rostedt# PWD is a ktest.pl variable that will result in the process working
40690e7a22deSSteven Rostedt# directory that ktest.pl is executed in.
40700e7a22deSSteven Rostedt
40710e7a22deSSteven Rostedt# THIS_DIR is automatically assigned the PWD of the path that generated
40720e7a22deSSteven Rostedt# the config file. It is best to use this variable when assigning other
40730e7a22deSSteven Rostedt# directory paths within this directory. This allows you to easily
40740e7a22deSSteven Rostedt# move the test cases to other locations or to other machines.
40750e7a22deSSteven Rostedt#
40760e7a22deSSteven RostedtTHIS_DIR := $variable{"PWD"}
40770e7a22deSSteven Rostedt
40788d1491baSSteven Rostedt# Define each test with TEST_START
40798d1491baSSteven Rostedt# The config options below it will override the defaults
40808d1491baSSteven RostedtTEST_START
4081c4261d0fSSteven RostedtTEST_TYPE = $default{"TEST_TYPE"}
40828d1491baSSteven Rostedt
40838d1491baSSteven RostedtDEFAULTS
40848d1491baSSteven RostedtEOF
40858d1491baSSteven Rostedt;
40868d1491baSSteven Rostedt    close(OUT);
40878d1491baSSteven Rostedt}
40888d1491baSSteven Rostedtread_config $ktest_config;
40898d1491baSSteven Rostedt
409023715c3cSSteven Rostedtif (defined($opt{"LOG_FILE"})) {
409104262be3SSteven Rostedt (Red Hat)    $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
409223715c3cSSteven Rostedt}
409323715c3cSSteven Rostedt
40948d1491baSSteven Rostedt# Append any configs entered in manually to the config file.
40958d1491baSSteven Rostedtmy @new_configs = keys %entered_configs;
40968d1491baSSteven Rostedtif ($#new_configs >= 0) {
40978d1491baSSteven Rostedt    print "\nAppending entered in configs to $ktest_config\n";
40988d1491baSSteven Rostedt    open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
40998d1491baSSteven Rostedt    foreach my $config (@new_configs) {
41008d1491baSSteven Rostedt	print OUT "$config = $entered_configs{$config}\n";
41010e7a22deSSteven Rostedt	$opt{$config} = process_variables($entered_configs{$config});
41028d1491baSSteven Rostedt    }
41038d1491baSSteven Rostedt}
41042545eb61SSteven Rostedt
41052b7d9b21SSteven Rostedtif ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
41062b7d9b21SSteven Rostedt    unlink $opt{"LOG_FILE"};
41072b7d9b21SSteven Rostedt}
41082545eb61SSteven Rostedt
41092b7d9b21SSteven Rostedtdoprint "\n\nSTARTING AUTOMATED TESTS\n\n";
41102b7d9b21SSteven Rostedt
4111a57419b3SSteven Rostedtfor (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
4112a57419b3SSteven Rostedt
4113a57419b3SSteven Rostedt    if (!$i) {
4114a57419b3SSteven Rostedt	doprint "DEFAULT OPTIONS:\n";
4115a57419b3SSteven Rostedt    } else {
4116a57419b3SSteven Rostedt	doprint "\nTEST $i OPTIONS";
4117a57419b3SSteven Rostedt	if (defined($repeat_tests{$i})) {
4118a57419b3SSteven Rostedt	    $repeat = $repeat_tests{$i};
4119a57419b3SSteven Rostedt	    doprint " ITERATE $repeat";
4120a57419b3SSteven Rostedt	}
4121a57419b3SSteven Rostedt	doprint "\n";
4122a57419b3SSteven Rostedt    }
4123a57419b3SSteven Rostedt
41242b7d9b21SSteven Rostedt    foreach my $option (sort keys %opt) {
4125a57419b3SSteven Rostedt
4126a57419b3SSteven Rostedt	if ($option =~ /\[(\d+)\]$/) {
4127a57419b3SSteven Rostedt	    next if ($i != $1);
4128a57419b3SSteven Rostedt	} else {
4129a57419b3SSteven Rostedt	    next if ($i);
4130a57419b3SSteven Rostedt	}
4131a57419b3SSteven Rostedt
41322b7d9b21SSteven Rostedt	doprint "$option = $opt{$option}\n";
41332b7d9b21SSteven Rostedt    }
4134a57419b3SSteven Rostedt}
41352545eb61SSteven Rostedt
413622c37a9aSSteven Rostedt (Red Hat)sub option_defined {
413722c37a9aSSteven Rostedt (Red Hat)    my ($option) = @_;
413822c37a9aSSteven Rostedt (Red Hat)
413922c37a9aSSteven Rostedt (Red Hat)    if (defined($opt{$option}) && $opt{$option} !~ /^\s*$/) {
414022c37a9aSSteven Rostedt (Red Hat)	return 1;
414122c37a9aSSteven Rostedt (Red Hat)    }
414222c37a9aSSteven Rostedt (Red Hat)
414322c37a9aSSteven Rostedt (Red Hat)    return 0;
414422c37a9aSSteven Rostedt (Red Hat)}
414522c37a9aSSteven Rostedt (Red Hat)
41462a62512bSSteven Rostedtsub __set_test_option {
41475a391fbfSSteven Rostedt    my ($name, $i) = @_;
41485a391fbfSSteven Rostedt
41495a391fbfSSteven Rostedt    my $option = "$name\[$i\]";
41505a391fbfSSteven Rostedt
415122c37a9aSSteven Rostedt (Red Hat)    if (option_defined($option)) {
41525a391fbfSSteven Rostedt	return $opt{$option};
41535a391fbfSSteven Rostedt    }
41545a391fbfSSteven Rostedt
4155a57419b3SSteven Rostedt    foreach my $test (keys %repeat_tests) {
4156a57419b3SSteven Rostedt	if ($i >= $test &&
4157a57419b3SSteven Rostedt	    $i < $test + $repeat_tests{$test}) {
4158a57419b3SSteven Rostedt	    $option = "$name\[$test\]";
415922c37a9aSSteven Rostedt (Red Hat)	    if (option_defined($option)) {
4160a57419b3SSteven Rostedt		return $opt{$option};
4161a57419b3SSteven Rostedt	    }
4162a57419b3SSteven Rostedt	}
4163a57419b3SSteven Rostedt    }
4164a57419b3SSteven Rostedt
416522c37a9aSSteven Rostedt (Red Hat)    if (option_defined($name)) {
41665a391fbfSSteven Rostedt	return $opt{$name};
41675a391fbfSSteven Rostedt    }
41685a391fbfSSteven Rostedt
41695a391fbfSSteven Rostedt    return undef;
41705a391fbfSSteven Rostedt}
41715a391fbfSSteven Rostedt
41722a62512bSSteven Rostedtsub set_test_option {
41732a62512bSSteven Rostedt    my ($name, $i) = @_;
41742a62512bSSteven Rostedt
41752a62512bSSteven Rostedt    my $option = __set_test_option($name, $i);
41762a62512bSSteven Rostedt    return $option if (!defined($option));
41772a62512bSSteven Rostedt
417804262be3SSteven Rostedt (Red Hat)    return eval_option($name, $option, $i);
41792a62512bSSteven Rostedt}
41802a62512bSSteven Rostedt
41812545eb61SSteven Rostedt# First we need to do is the builds
4182a75fececSSteven Rostedtfor (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
41832545eb61SSteven Rostedt
41844ab1cce5SSteven Rostedt    # Do not reboot on failing test options
41854ab1cce5SSteven Rostedt    $no_reboot = 1;
4186759a3cc6SSteven Rostedt    $reboot_success = 0;
41874ab1cce5SSteven Rostedt
4188683a3e64SSteven Rostedt    $have_version = 0;
4189683a3e64SSteven Rostedt
4190576f627cSSteven Rostedt    $iteration = $i;
4191576f627cSSteven Rostedt
419238fa3dc1SSteven Rostedt (Red Hat)    $build_time = 0;
419338fa3dc1SSteven Rostedt (Red Hat)    $install_time = 0;
419438fa3dc1SSteven Rostedt (Red Hat)    $reboot_time = 0;
419538fa3dc1SSteven Rostedt (Red Hat)    $test_time = 0;
419638fa3dc1SSteven Rostedt (Red Hat)
4197c1434dccSSteven Rostedt    undef %force_config;
4198c1434dccSSteven Rostedt
4199a75fececSSteven Rostedt    my $makecmd = set_test_option("MAKE_CMD", $i);
4200a75fececSSteven Rostedt
42018e80bf05SSteven Rostedt (Red Hat)    $outputdir = set_test_option("OUTPUT_DIR", $i);
42028e80bf05SSteven Rostedt (Red Hat)    $builddir = set_test_option("BUILD_DIR", $i);
42038e80bf05SSteven Rostedt (Red Hat)
42048e80bf05SSteven Rostedt (Red Hat)    chdir $builddir || die "can't change directory to $builddir";
42058e80bf05SSteven Rostedt (Red Hat)
42068e80bf05SSteven Rostedt (Red Hat)    if (!-d $outputdir) {
42078e80bf05SSteven Rostedt (Red Hat)	mkpath($outputdir) or
42088e80bf05SSteven Rostedt (Red Hat)	    die "can't create $outputdir";
42098e80bf05SSteven Rostedt (Red Hat)    }
42108e80bf05SSteven Rostedt (Red Hat)
42118e80bf05SSteven Rostedt (Red Hat)    $make = "$makecmd O=$outputdir";
42128e80bf05SSteven Rostedt (Red Hat)
42139cc9e091SSteven Rostedt    # Load all the options into their mapped variable names
42149cc9e091SSteven Rostedt    foreach my $opt (keys %option_map) {
42159cc9e091SSteven Rostedt	${$option_map{$opt}} = set_test_option($opt, $i);
42169cc9e091SSteven Rostedt    }
4217b5f4aea6SSteven Rostedt
421835ce5952SSteven Rostedt    $start_minconfig_defined = 1;
421935ce5952SSteven Rostedt
4220921ed4c7SSteven Rostedt    # The first test may override the PRE_KTEST option
4221921ed4c7SSteven Rostedt    if (defined($pre_ktest) && $i == 1) {
4222921ed4c7SSteven Rostedt	doprint "\n";
4223921ed4c7SSteven Rostedt	run_command $pre_ktest;
4224921ed4c7SSteven Rostedt    }
4225921ed4c7SSteven Rostedt
4226921ed4c7SSteven Rostedt    # Any test can override the POST_KTEST option
4227921ed4c7SSteven Rostedt    # The last test takes precedence.
4228921ed4c7SSteven Rostedt    if (defined($post_ktest)) {
4229921ed4c7SSteven Rostedt	$final_post_ktest = $post_ktest;
4230921ed4c7SSteven Rostedt    }
4231921ed4c7SSteven Rostedt
42324c4ab120SSteven Rostedt    if (!defined($start_minconfig)) {
423335ce5952SSteven Rostedt	$start_minconfig_defined = 0;
42344c4ab120SSteven Rostedt	$start_minconfig = $minconfig;
42354c4ab120SSteven Rostedt    }
42364c4ab120SSteven Rostedt
42378e80bf05SSteven Rostedt (Red Hat)    if (!-d $tmpdir) {
42388e80bf05SSteven Rostedt (Red Hat)	mkpath($tmpdir) or
42398e80bf05SSteven Rostedt (Red Hat)	    die "can't create $tmpdir";
4240a75fececSSteven Rostedt    }
4241a75fececSSteven Rostedt
4242e48c5293SSteven Rostedt    $ENV{"SSH_USER"} = $ssh_user;
4243e48c5293SSteven Rostedt    $ENV{"MACHINE"} = $machine;
4244e48c5293SSteven Rostedt
4245a75fececSSteven Rostedt    $buildlog = "$tmpdir/buildlog-$machine";
4246a9dd5d63SRabin Vincent    $testlog = "$tmpdir/testlog-$machine";
4247a75fececSSteven Rostedt    $dmesg = "$tmpdir/dmesg-$machine";
424851ad1dd1SSteven Rostedt    $output_config = "$outputdir/.config";
4249a75fececSSteven Rostedt
4250bb8474b1SSteven Rostedt    if (!$buildonly) {
4251bb8474b1SSteven Rostedt	$target = "$ssh_user\@$machine";
4252a75fececSSteven Rostedt	if ($reboot_type eq "grub") {
4253576f627cSSteven Rostedt	    dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4254a15ba913SSteven Rostedt	} elsif ($reboot_type eq "grub2") {
4255a15ba913SSteven Rostedt	    dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4256a15ba913SSteven Rostedt	    dodie "GRUB_FILE not defined" if (!defined($grub_file));
42577786954cSSteven Rostedt	} elsif ($reboot_type eq "syslinux") {
42587786954cSSteven Rostedt	    dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
4259a75fececSSteven Rostedt	}
4260bb8474b1SSteven Rostedt    }
4261a75fececSSteven Rostedt
4262a75fececSSteven Rostedt    my $run_type = $build_type;
4263a75fececSSteven Rostedt    if ($test_type eq "patchcheck") {
4264b5f4aea6SSteven Rostedt	$run_type = $patchcheck_type;
4265a75fececSSteven Rostedt    } elsif ($test_type eq "bisect") {
4266b5f4aea6SSteven Rostedt	$run_type = $bisect_type;
42670a05c769SSteven Rostedt    } elsif ($test_type eq "config_bisect") {
4268b5f4aea6SSteven Rostedt	$run_type = $config_bisect_type;
42694283b169SSteven Rostedt (Red Hat)    } elsif ($test_type eq "make_min_config") {
42704283b169SSteven Rostedt (Red Hat)	$run_type = "";
42714283b169SSteven Rostedt (Red Hat)    } elsif ($test_type eq "make_warnings_file") {
42724c4ab120SSteven Rostedt	$run_type = "";
42734c4ab120SSteven Rostedt    }
42744c4ab120SSteven Rostedt
4275a75fececSSteven Rostedt    # mistake in config file?
4276a75fececSSteven Rostedt    if (!defined($run_type)) {
4277a75fececSSteven Rostedt	$run_type = "ERROR";
4278a75fececSSteven Rostedt    }
42792545eb61SSteven Rostedt
4280e0a8742eSSteven Rostedt    my $installme = "";
4281e0a8742eSSteven Rostedt    $installme = " no_install" if ($no_install);
4282e0a8742eSSteven Rostedt
428318656c70SSteven Rostedt (Red Hat)    my $name = "";
428418656c70SSteven Rostedt (Red Hat)
428518656c70SSteven Rostedt (Red Hat)    if (defined($test_name)) {
428618656c70SSteven Rostedt (Red Hat)	$name = " ($test_name)";
428718656c70SSteven Rostedt (Red Hat)    }
428818656c70SSteven Rostedt (Red Hat)
42892545eb61SSteven Rostedt    doprint "\n\n";
429018656c70SSteven Rostedt (Red Hat)    doprint "RUNNING TEST $i of $opt{NUM_TESTS}$name with option $test_type $run_type$installme\n\n";
42917faafbd6SSteven Rostedt
4292921ed4c7SSteven Rostedt    if (defined($pre_test)) {
4293921ed4c7SSteven Rostedt	run_command $pre_test;
4294921ed4c7SSteven Rostedt    }
4295921ed4c7SSteven Rostedt
42967faafbd6SSteven Rostedt    unlink $dmesg;
42977faafbd6SSteven Rostedt    unlink $buildlog;
4298a9dd5d63SRabin Vincent    unlink $testlog;
42992545eb61SSteven Rostedt
4300250bae8bSSteven Rostedt    if (defined($addconfig)) {
4301250bae8bSSteven Rostedt	my $min = $minconfig;
43022b7d9b21SSteven Rostedt	if (!defined($minconfig)) {
4303250bae8bSSteven Rostedt	    $min = "";
4304250bae8bSSteven Rostedt	}
4305250bae8bSSteven Rostedt	run_command "cat $addconfig $min > $tmpdir/add_config" or
43062b7d9b21SSteven Rostedt	    dodie "Failed to create temp config";
43079be2e6b5SSteven Rostedt	$minconfig = "$tmpdir/add_config";
43082b7d9b21SSteven Rostedt    }
43092b7d9b21SSteven Rostedt
43106c5ee0beSSteven Rostedt    if (defined($checkout)) {
43116c5ee0beSSteven Rostedt	run_command "git checkout $checkout" or
43126c5ee0beSSteven Rostedt	    die "failed to checkout $checkout";
43136c5ee0beSSteven Rostedt    }
43146c5ee0beSSteven Rostedt
4315759a3cc6SSteven Rostedt    $no_reboot = 0;
4316759a3cc6SSteven Rostedt
4317648a182cSSteven Rostedt    # A test may opt to not reboot the box
4318648a182cSSteven Rostedt    if ($reboot_on_success) {
4319759a3cc6SSteven Rostedt	$reboot_success = 1;
4320648a182cSSteven Rostedt    }
43214ab1cce5SSteven Rostedt
4322a75fececSSteven Rostedt    if ($test_type eq "bisect") {
43235f9b6cedSSteven Rostedt	bisect $i;
43245f9b6cedSSteven Rostedt	next;
43250a05c769SSteven Rostedt    } elsif ($test_type eq "config_bisect") {
43260a05c769SSteven Rostedt	config_bisect $i;
43270a05c769SSteven Rostedt	next;
4328a75fececSSteven Rostedt    } elsif ($test_type eq "patchcheck") {
43296c5ee0beSSteven Rostedt	patchcheck $i;
43306c5ee0beSSteven Rostedt	next;
43314c4ab120SSteven Rostedt    } elsif ($test_type eq "make_min_config") {
43324c4ab120SSteven Rostedt	make_min_config $i;
43334c4ab120SSteven Rostedt	next;
43344283b169SSteven Rostedt (Red Hat)    } elsif ($test_type eq "make_warnings_file") {
43354283b169SSteven Rostedt (Red Hat)	$no_reboot = 1;
43364283b169SSteven Rostedt (Red Hat)	make_warnings_file $i;
43374283b169SSteven Rostedt (Red Hat)	next;
43385f9b6cedSSteven Rostedt    }
43395f9b6cedSSteven Rostedt
43407faafbd6SSteven Rostedt    if ($build_type ne "nobuild") {
43417faafbd6SSteven Rostedt	build $build_type or next;
43424283b169SSteven Rostedt (Red Hat)	check_buildlog or next;
43432545eb61SSteven Rostedt    }
43442545eb61SSteven Rostedt
4345cd8e368fSSteven Rostedt    if ($test_type eq "install") {
4346cd8e368fSSteven Rostedt	get_version;
4347cd8e368fSSteven Rostedt	install;
4348cd8e368fSSteven Rostedt	success $i;
4349cd8e368fSSteven Rostedt	next;
4350cd8e368fSSteven Rostedt    }
4351cd8e368fSSteven Rostedt
4352a75fececSSteven Rostedt    if ($test_type ne "build") {
43537faafbd6SSteven Rostedt	my $failed = 0;
435464d98283SSteven Rostedt (Red Hat)	start_monitor_and_install or $failed = 1;
4355a75fececSSteven Rostedt
4356a75fececSSteven Rostedt	if (!$failed && $test_type ne "boot" && defined($run_test)) {
43577faafbd6SSteven Rostedt	    do_run_test or $failed = 1;
43585a391fbfSSteven Rostedt	}
43597faafbd6SSteven Rostedt	end_monitor;
436038fa3dc1SSteven Rostedt (Red Hat)	if ($failed) {
436138fa3dc1SSteven Rostedt (Red Hat)	    print_times;
436238fa3dc1SSteven Rostedt (Red Hat)	    next;
4363a75fececSSteven Rostedt	}
436438fa3dc1SSteven Rostedt (Red Hat)    }
436538fa3dc1SSteven Rostedt (Red Hat)
436638fa3dc1SSteven Rostedt (Red Hat)    print_times;
43675a391fbfSSteven Rostedt
43685f9b6cedSSteven Rostedt    success $i;
436975c3fda7SSteven Rostedt}
43702545eb61SSteven Rostedt
4371921ed4c7SSteven Rostedtif (defined($final_post_ktest)) {
4372921ed4c7SSteven Rostedt    run_command $final_post_ktest;
4373921ed4c7SSteven Rostedt}
4374921ed4c7SSteven Rostedt
43755c42fc5bSSteven Rostedtif ($opt{"POWEROFF_ON_SUCCESS"}) {
437675c3fda7SSteven Rostedt    halt;
4377759a3cc6SSteven Rostedt} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
4378bc7c5803SSteven Rostedt    reboot_to_good;
4379648a182cSSteven Rostedt} elsif (defined($switch_to_good)) {
4380648a182cSSteven Rostedt    # still need to get to the good kernel
4381648a182cSSteven Rostedt    run_command $switch_to_good;
43825c42fc5bSSteven Rostedt}
438375c3fda7SSteven Rostedt
4384648a182cSSteven Rostedt
4385e48c5293SSteven Rostedtdoprint "\n    $successes of $opt{NUM_TESTS} tests were successful\n\n";
4386e48c5293SSteven Rostedt
43872545eb61SSteven Rostedtexit 0;
4388