xref: /openbmc/linux/tools/testing/ktest/ktest.pl (revision 2ceb2d85b6697e2a3485047d1c908a4908069411)
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;
1340667fb5SSteven Rostedt (VMware)use FindBin;
142545eb61SSteven Rostedt
15e48c5293SSteven Rostedtmy $VERSION = "0.2";
16e48c5293SSteven Rostedt
172545eb61SSteven Rostedt$| = 1;
182545eb61SSteven Rostedt
192545eb61SSteven Rostedtmy %opt;
20a57419b3SSteven Rostedtmy %repeat_tests;
21a57419b3SSteven Rostedtmy %repeats;
22c75d22d9SSteven Rostedt (Red Hat)my %evals;
232545eb61SSteven Rostedt
242545eb61SSteven Rostedt#default opts
254f43e0dcSSteven Rostedtmy %default = (
26*2ceb2d85STim Tianyang Chen    "MAILER"				=> "sendmail",  # default mailer
27*2ceb2d85STim Tianyang Chen    "EMAIL_ON_ERROR"		=> 1,
28*2ceb2d85STim Tianyang Chen    "EMAIL_WHEN_FINISHED"	=> 1,
29*2ceb2d85STim Tianyang Chen    "EMAIL_WHEN_CANCELED"	=> 0,
30*2ceb2d85STim Tianyang Chen    "EMAIL_WHEN_STARTED"	=> 0,
314f43e0dcSSteven Rostedt    "NUM_TESTS"			=> 1,
324f43e0dcSSteven Rostedt    "TEST_TYPE"			=> "build",
334f43e0dcSSteven Rostedt    "BUILD_TYPE"		=> "randconfig",
344f43e0dcSSteven Rostedt    "MAKE_CMD"			=> "make",
355a5d8e48SSatoru Takeuchi    "CLOSE_CONSOLE_SIGNAL"	=> "INT",
364f43e0dcSSteven Rostedt    "TIMEOUT"			=> 120,
374f43e0dcSSteven Rostedt    "TMP_DIR"			=> "/tmp/ktest/\${MACHINE}",
384f43e0dcSSteven Rostedt    "SLEEP_TIME"		=> 60,	# sleep time between tests
394f43e0dcSSteven Rostedt    "BUILD_NOCLEAN"		=> 0,
404f43e0dcSSteven Rostedt    "REBOOT_ON_ERROR"		=> 0,
414f43e0dcSSteven Rostedt    "POWEROFF_ON_ERROR"		=> 0,
424f43e0dcSSteven Rostedt    "REBOOT_ON_SUCCESS"		=> 1,
434f43e0dcSSteven Rostedt    "POWEROFF_ON_SUCCESS"	=> 0,
444f43e0dcSSteven Rostedt    "BUILD_OPTIONS"		=> "",
454f43e0dcSSteven Rostedt    "BISECT_SLEEP_TIME"		=> 60,   # sleep time between bisects
464f43e0dcSSteven Rostedt    "PATCHCHECK_SLEEP_TIME"	=> 60, # sleep time between patch checks
474f43e0dcSSteven Rostedt    "CLEAR_LOG"			=> 0,
484f43e0dcSSteven Rostedt    "BISECT_MANUAL"		=> 0,
494f43e0dcSSteven Rostedt    "BISECT_SKIP"		=> 1,
50961d9cacSSteven Rostedt (Red Hat)    "BISECT_TRIES"		=> 1,
51ccc513b6SSteven Rostedt    "MIN_CONFIG_TYPE"		=> "boot",
524f43e0dcSSteven Rostedt    "SUCCESS_LINE"		=> "login:",
534f43e0dcSSteven Rostedt    "DETECT_TRIPLE_FAULT"	=> 1,
544f43e0dcSSteven Rostedt    "NO_INSTALL"		=> 0,
554f43e0dcSSteven Rostedt    "BOOTED_TIMEOUT"		=> 1,
564f43e0dcSSteven Rostedt    "DIE_ON_FAILURE"		=> 1,
574f43e0dcSSteven Rostedt    "SSH_EXEC"			=> "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
584f43e0dcSSteven Rostedt    "SCP_TO_TARGET"		=> "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
5902ad2617SSteven Rostedt    "SCP_TO_TARGET_INSTALL"	=> "\${SCP_TO_TARGET}",
604f43e0dcSSteven Rostedt    "REBOOT"			=> "ssh \$SSH_USER\@\$MACHINE reboot",
614f43e0dcSSteven Rostedt    "STOP_AFTER_SUCCESS"	=> 10,
624f43e0dcSSteven Rostedt    "STOP_AFTER_FAILURE"	=> 60,
634f43e0dcSSteven Rostedt    "STOP_TEST_AFTER"		=> 600,
64407b95b7SSteven Rostedt    "MAX_MONITOR_WAIT"		=> 1800,
65a15ba913SSteven Rostedt    "GRUB_REBOOT"		=> "grub2-reboot",
667786954cSSteven Rostedt    "SYSLINUX"			=> "extlinux",
677786954cSSteven Rostedt    "SYSLINUX_PATH"		=> "/boot/extlinux",
683e1d3678SSteven Rostedt (VMware)    "CONNECT_TIMEOUT"		=> 25,
69600bbf0aSSteven Rostedt
70600bbf0aSSteven Rostedt# required, and we will ask users if they don't have them but we keep the default
71600bbf0aSSteven Rostedt# value something that is common.
724f43e0dcSSteven Rostedt    "REBOOT_TYPE"		=> "grub",
734f43e0dcSSteven Rostedt    "LOCALVERSION"		=> "-test",
744f43e0dcSSteven Rostedt    "SSH_USER"			=> "root",
754f43e0dcSSteven Rostedt    "BUILD_TARGET"	 	=> "arch/x86/boot/bzImage",
764f43e0dcSSteven Rostedt    "TARGET_IMAGE"		=> "/boot/vmlinuz-test",
779cc9e091SSteven Rostedt
789cc9e091SSteven Rostedt    "LOG_FILE"			=> undef,
799cc9e091SSteven Rostedt    "IGNORE_UNUSED"		=> 0,
804f43e0dcSSteven Rostedt);
812545eb61SSteven Rostedt
825269faadSSatoru Takeuchimy $ktest_config = "ktest.conf";
832545eb61SSteven Rostedtmy $version;
84683a3e64SSteven Rostedtmy $have_version = 0;
85a75fececSSteven Rostedtmy $machine;
86df5f7c66SSteven Rostedt (Red Hat)my $last_machine;
87e48c5293SSteven Rostedtmy $ssh_user;
88a75fececSSteven Rostedtmy $tmpdir;
89a75fececSSteven Rostedtmy $builddir;
90a75fececSSteven Rostedtmy $outputdir;
9151ad1dd1SSteven Rostedtmy $output_config;
92a75fececSSteven Rostedtmy $test_type;
937faafbd6SSteven Rostedtmy $build_type;
94a75fececSSteven Rostedtmy $build_options;
95921ed4c7SSteven Rostedtmy $final_post_ktest;
96921ed4c7SSteven Rostedtmy $pre_ktest;
97921ed4c7SSteven Rostedtmy $post_ktest;
98921ed4c7SSteven Rostedtmy $pre_test;
99921ed4c7SSteven Rostedtmy $post_test;
1000bd6c1a3SSteven Rostedtmy $pre_build;
1010bd6c1a3SSteven Rostedtmy $post_build;
1020bd6c1a3SSteven Rostedtmy $pre_build_die;
1030bd6c1a3SSteven Rostedtmy $post_build_die;
104a75fececSSteven Rostedtmy $reboot_type;
105a75fececSSteven Rostedtmy $reboot_script;
106a75fececSSteven Rostedtmy $power_cycle;
107e48c5293SSteven Rostedtmy $reboot;
108a75fececSSteven Rostedtmy $reboot_on_error;
109bc7c5803SSteven Rostedtmy $switch_to_good;
110bc7c5803SSteven Rostedtmy $switch_to_test;
111a75fececSSteven Rostedtmy $poweroff_on_error;
112648a182cSSteven Rostedtmy $reboot_on_success;
113a75fececSSteven Rostedtmy $die_on_failure;
114576f627cSSteven Rostedtmy $powercycle_after_reboot;
115576f627cSSteven Rostedtmy $poweroff_after_halt;
116407b95b7SSteven Rostedtmy $max_monitor_wait;
117e48c5293SSteven Rostedtmy $ssh_exec;
118e48c5293SSteven Rostedtmy $scp_to_target;
11902ad2617SSteven Rostedtmy $scp_to_target_install;
120a75fececSSteven Rostedtmy $power_off;
121a75fececSSteven Rostedtmy $grub_menu;
122752d9665SSteven Rostedt (Red Hat)my $last_grub_menu;
123a15ba913SSteven Rostedtmy $grub_file;
1242545eb61SSteven Rostedtmy $grub_number;
125a15ba913SSteven Rostedtmy $grub_reboot;
1267786954cSSteven Rostedtmy $syslinux;
1277786954cSSteven Rostedtmy $syslinux_path;
1287786954cSSteven Rostedtmy $syslinux_label;
1292545eb61SSteven Rostedtmy $target;
1302545eb61SSteven Rostedtmy $make;
131e5c2ec11SSteven Rostedtmy $pre_install;
1328b37ca8cSSteven Rostedtmy $post_install;
133e0a8742eSSteven Rostedtmy $no_install;
1345c42fc5bSSteven Rostedtmy $noclean;
1355f9b6cedSSteven Rostedtmy $minconfig;
1364c4ab120SSteven Rostedtmy $start_minconfig;
13735ce5952SSteven Rostedtmy $start_minconfig_defined;
1384c4ab120SSteven Rostedtmy $output_minconfig;
139ccc513b6SSteven Rostedtmy $minconfig_type;
14043de3316SSteven Rostedtmy $use_output_minconfig;
1414283b169SSteven Rostedt (Red Hat)my $warnings_file;
1424c4ab120SSteven Rostedtmy $ignore_config;
143be405f95SSteven Rostedtmy $ignore_errors;
1442b7d9b21SSteven Rostedtmy $addconfig;
1455f9b6cedSSteven Rostedtmy $in_bisect = 0;
146b5f4aea6SSteven Rostedtmy $bisect_bad_commit = "";
147d6ce2a0bSSteven Rostedtmy $reverse_bisect;
148c960bb9fSSteven Rostedtmy $bisect_manual;
149c23dca7cSSteven Rostedtmy $bisect_skip;
150961d9cacSSteven Rostedt (Red Hat)my $bisect_tries;
15130f75da5SSteven Rostedtmy $config_bisect_good;
152c5dacb88SSteven Rostedtmy $bisect_ret_good;
153c5dacb88SSteven Rostedtmy $bisect_ret_bad;
154c5dacb88SSteven Rostedtmy $bisect_ret_skip;
155c5dacb88SSteven Rostedtmy $bisect_ret_abort;
156c5dacb88SSteven Rostedtmy $bisect_ret_default;
1576c5ee0beSSteven Rostedtmy $in_patchcheck = 0;
1585a391fbfSSteven Rostedtmy $run_test;
1597faafbd6SSteven Rostedtmy $buildlog;
160a9dd5d63SRabin Vincentmy $testlog;
1617faafbd6SSteven Rostedtmy $dmesg;
1627faafbd6SSteven Rostedtmy $monitor_fp;
1637faafbd6SSteven Rostedtmy $monitor_pid;
1647faafbd6SSteven Rostedtmy $monitor_cnt = 0;
165a75fececSSteven Rostedtmy $sleep_time;
166a75fececSSteven Rostedtmy $bisect_sleep_time;
16727d934b2SSteven Rostedtmy $patchcheck_sleep_time;
1681990207dSSteven Rostedtmy $ignore_warnings;
169a75fececSSteven Rostedtmy $store_failures;
170de5b6e3bSRabin Vincentmy $store_successes;
1719064af52SSteven Rostedtmy $test_name;
172a75fececSSteven Rostedtmy $timeout;
1733e1d3678SSteven Rostedt (VMware)my $connect_timeout;
17440667fb5SSteven Rostedt (VMware)my $config_bisect_exec;
175a75fececSSteven Rostedtmy $booted_timeout;
176f1a5b962SSteven Rostedtmy $detect_triplefault;
177a75fececSSteven Rostedtmy $console;
1785a5d8e48SSatoru Takeuchimy $close_console_signal;
1792b803365SSteven Rostedtmy $reboot_success_line;
180a75fececSSteven Rostedtmy $success_line;
1811c8a617aSSteven Rostedtmy $stop_after_success;
1821c8a617aSSteven Rostedtmy $stop_after_failure;
1832d01b26aSSteven Rostedtmy $stop_test_after;
184a75fececSSteven Rostedtmy $build_target;
185a75fececSSteven Rostedtmy $target_image;
186b5f4aea6SSteven Rostedtmy $checkout;
187a75fececSSteven Rostedtmy $localversion;
188576f627cSSteven Rostedtmy $iteration = 0;
189e48c5293SSteven Rostedtmy $successes = 0;
1909d2f7f05SJosh Poimboeufmy $stty_orig;
1915739438bSSteven Rostedt (VMware)my $run_command_status = 0;
1922545eb61SSteven Rostedt
193b5f4aea6SSteven Rostedtmy $bisect_good;
194b5f4aea6SSteven Rostedtmy $bisect_bad;
195b5f4aea6SSteven Rostedtmy $bisect_type;
196b5f4aea6SSteven Rostedtmy $bisect_start;
197b5f4aea6SSteven Rostedtmy $bisect_replay;
198b5f4aea6SSteven Rostedtmy $bisect_files;
199b5f4aea6SSteven Rostedtmy $bisect_reverse;
200b5f4aea6SSteven Rostedtmy $bisect_check;
201b5f4aea6SSteven Rostedt
202b5f4aea6SSteven Rostedtmy $config_bisect;
203b5f4aea6SSteven Rostedtmy $config_bisect_type;
204b0918612SSteven Rostedtmy $config_bisect_check;
205b5f4aea6SSteven Rostedt
206b5f4aea6SSteven Rostedtmy $patchcheck_type;
207b5f4aea6SSteven Rostedtmy $patchcheck_start;
20823a0e161SSteven Rostedt (Red Hat)my $patchcheck_cherry;
209b5f4aea6SSteven Rostedtmy $patchcheck_end;
210b5f4aea6SSteven Rostedt
21138fa3dc1SSteven Rostedt (Red Hat)my $build_time;
21238fa3dc1SSteven Rostedt (Red Hat)my $install_time;
21338fa3dc1SSteven Rostedt (Red Hat)my $reboot_time;
21438fa3dc1SSteven Rostedt (Red Hat)my $test_time;
21538fa3dc1SSteven Rostedt (Red Hat)
21640667fb5SSteven Rostedt (VMware)my $pwd;
21740667fb5SSteven Rostedt (VMware)my $dirname = $FindBin::Bin;
21840667fb5SSteven Rostedt (VMware)
219*2ceb2d85STim Tianyang Chenmy $mailto;
220*2ceb2d85STim Tianyang Chenmy $mailer;
221*2ceb2d85STim Tianyang Chenmy $email_on_error;
222*2ceb2d85STim Tianyang Chenmy $email_when_finished;
223*2ceb2d85STim Tianyang Chenmy $email_when_started;
224*2ceb2d85STim Tianyang Chenmy $email_when_canceled;
225*2ceb2d85STim Tianyang Chen
226*2ceb2d85STim Tianyang Chenmy $script_start_time = localtime();
227*2ceb2d85STim Tianyang Chen
228165708b2SSteven Rostedt# set when a test is something other that just building or install
229bb8474b1SSteven Rostedt# which would require more options.
230bb8474b1SSteven Rostedtmy $buildonly = 1;
231bb8474b1SSteven Rostedt
2324283b169SSteven Rostedt (Red Hat)# tell build not to worry about warnings, even when WARNINGS_FILE is set
2334283b169SSteven Rostedt (Red Hat)my $warnings_ok = 0;
2344283b169SSteven Rostedt (Red Hat)
235dbd3783bSSteven Rostedt# set when creating a new config
236dbd3783bSSteven Rostedtmy $newconfig = 0;
237dbd3783bSSteven Rostedt
2388d1491baSSteven Rostedtmy %entered_configs;
2398d1491baSSteven Rostedtmy %config_help;
24077d942ceSSteven Rostedtmy %variable;
241cf79fab6SSteven Rostedt
242cf79fab6SSteven Rostedt# force_config is the list of configs that we force enabled (or disabled)
243cf79fab6SSteven Rostedt# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
244fcb3f16aSSteven Rostedtmy %force_config;
2458d1491baSSteven Rostedt
2464ab1cce5SSteven Rostedt# do not force reboots on config problems
2474ab1cce5SSteven Rostedtmy $no_reboot = 1;
2484ab1cce5SSteven Rostedt
249759a3cc6SSteven Rostedt# reboot on success
250759a3cc6SSteven Rostedtmy $reboot_success = 0;
251759a3cc6SSteven Rostedt
2529cc9e091SSteven Rostedtmy %option_map = (
253*2ceb2d85STim Tianyang Chen    "MAILTO"				=> \$mailto,
254*2ceb2d85STim Tianyang Chen    "MAILER"				=> \$mailer,
255*2ceb2d85STim Tianyang Chen    "EMAIL_ON_ERROR"		=> \$email_on_error,
256*2ceb2d85STim Tianyang Chen    "EMAIL_WHEN_FINISHED"	=> \$email_when_finished,
257*2ceb2d85STim Tianyang Chen    "EMAIL_WHEN_STARTED"	=> \$email_when_started,
258*2ceb2d85STim Tianyang Chen    "EMAIL_WHEN_CANCELED"	=> \$email_when_canceled,
2599cc9e091SSteven Rostedt    "MACHINE"			=> \$machine,
2609cc9e091SSteven Rostedt    "SSH_USER"			=> \$ssh_user,
2619cc9e091SSteven Rostedt    "TMP_DIR"			=> \$tmpdir,
2629cc9e091SSteven Rostedt    "OUTPUT_DIR"		=> \$outputdir,
2639cc9e091SSteven Rostedt    "BUILD_DIR"			=> \$builddir,
2649cc9e091SSteven Rostedt    "TEST_TYPE"			=> \$test_type,
265921ed4c7SSteven Rostedt    "PRE_KTEST"			=> \$pre_ktest,
266921ed4c7SSteven Rostedt    "POST_KTEST"		=> \$post_ktest,
267921ed4c7SSteven Rostedt    "PRE_TEST"			=> \$pre_test,
268921ed4c7SSteven Rostedt    "POST_TEST"			=> \$post_test,
2699cc9e091SSteven Rostedt    "BUILD_TYPE"		=> \$build_type,
2709cc9e091SSteven Rostedt    "BUILD_OPTIONS"		=> \$build_options,
2719cc9e091SSteven Rostedt    "PRE_BUILD"			=> \$pre_build,
2729cc9e091SSteven Rostedt    "POST_BUILD"		=> \$post_build,
2739cc9e091SSteven Rostedt    "PRE_BUILD_DIE"		=> \$pre_build_die,
2749cc9e091SSteven Rostedt    "POST_BUILD_DIE"		=> \$post_build_die,
2759cc9e091SSteven Rostedt    "POWER_CYCLE"		=> \$power_cycle,
2769cc9e091SSteven Rostedt    "REBOOT"			=> \$reboot,
2779cc9e091SSteven Rostedt    "BUILD_NOCLEAN"		=> \$noclean,
2789cc9e091SSteven Rostedt    "MIN_CONFIG"		=> \$minconfig,
2799cc9e091SSteven Rostedt    "OUTPUT_MIN_CONFIG"		=> \$output_minconfig,
2809cc9e091SSteven Rostedt    "START_MIN_CONFIG"		=> \$start_minconfig,
281ccc513b6SSteven Rostedt    "MIN_CONFIG_TYPE"		=> \$minconfig_type,
28243de3316SSteven Rostedt    "USE_OUTPUT_MIN_CONFIG"	=> \$use_output_minconfig,
2834283b169SSteven Rostedt (Red Hat)    "WARNINGS_FILE"		=> \$warnings_file,
2849cc9e091SSteven Rostedt    "IGNORE_CONFIG"		=> \$ignore_config,
2859cc9e091SSteven Rostedt    "TEST"			=> \$run_test,
2869cc9e091SSteven Rostedt    "ADD_CONFIG"		=> \$addconfig,
2879cc9e091SSteven Rostedt    "REBOOT_TYPE"		=> \$reboot_type,
2889cc9e091SSteven Rostedt    "GRUB_MENU"			=> \$grub_menu,
289a15ba913SSteven Rostedt    "GRUB_FILE"			=> \$grub_file,
290a15ba913SSteven Rostedt    "GRUB_REBOOT"		=> \$grub_reboot,
2917786954cSSteven Rostedt    "SYSLINUX"			=> \$syslinux,
2927786954cSSteven Rostedt    "SYSLINUX_PATH"		=> \$syslinux_path,
2937786954cSSteven Rostedt    "SYSLINUX_LABEL"		=> \$syslinux_label,
294e5c2ec11SSteven Rostedt    "PRE_INSTALL"		=> \$pre_install,
2959cc9e091SSteven Rostedt    "POST_INSTALL"		=> \$post_install,
2969cc9e091SSteven Rostedt    "NO_INSTALL"		=> \$no_install,
2979cc9e091SSteven Rostedt    "REBOOT_SCRIPT"		=> \$reboot_script,
2989cc9e091SSteven Rostedt    "REBOOT_ON_ERROR"		=> \$reboot_on_error,
2999cc9e091SSteven Rostedt    "SWITCH_TO_GOOD"		=> \$switch_to_good,
3009cc9e091SSteven Rostedt    "SWITCH_TO_TEST"		=> \$switch_to_test,
3019cc9e091SSteven Rostedt    "POWEROFF_ON_ERROR"		=> \$poweroff_on_error,
302648a182cSSteven Rostedt    "REBOOT_ON_SUCCESS"		=> \$reboot_on_success,
3039cc9e091SSteven Rostedt    "DIE_ON_FAILURE"		=> \$die_on_failure,
3049cc9e091SSteven Rostedt    "POWER_OFF"			=> \$power_off,
3059cc9e091SSteven Rostedt    "POWERCYCLE_AFTER_REBOOT"	=> \$powercycle_after_reboot,
3069cc9e091SSteven Rostedt    "POWEROFF_AFTER_HALT"	=> \$poweroff_after_halt,
307407b95b7SSteven Rostedt    "MAX_MONITOR_WAIT"		=> \$max_monitor_wait,
3089cc9e091SSteven Rostedt    "SLEEP_TIME"		=> \$sleep_time,
3099cc9e091SSteven Rostedt    "BISECT_SLEEP_TIME"		=> \$bisect_sleep_time,
3109cc9e091SSteven Rostedt    "PATCHCHECK_SLEEP_TIME"	=> \$patchcheck_sleep_time,
3119cc9e091SSteven Rostedt    "IGNORE_WARNINGS"		=> \$ignore_warnings,
312be405f95SSteven Rostedt    "IGNORE_ERRORS"		=> \$ignore_errors,
3139cc9e091SSteven Rostedt    "BISECT_MANUAL"		=> \$bisect_manual,
3149cc9e091SSteven Rostedt    "BISECT_SKIP"		=> \$bisect_skip,
315961d9cacSSteven Rostedt (Red Hat)    "BISECT_TRIES"		=> \$bisect_tries,
3169cc9e091SSteven Rostedt    "CONFIG_BISECT_GOOD"	=> \$config_bisect_good,
3179cc9e091SSteven Rostedt    "BISECT_RET_GOOD"		=> \$bisect_ret_good,
3189cc9e091SSteven Rostedt    "BISECT_RET_BAD"		=> \$bisect_ret_bad,
3199cc9e091SSteven Rostedt    "BISECT_RET_SKIP"		=> \$bisect_ret_skip,
3209cc9e091SSteven Rostedt    "BISECT_RET_ABORT"		=> \$bisect_ret_abort,
3219cc9e091SSteven Rostedt    "BISECT_RET_DEFAULT"	=> \$bisect_ret_default,
3229cc9e091SSteven Rostedt    "STORE_FAILURES"		=> \$store_failures,
3239cc9e091SSteven Rostedt    "STORE_SUCCESSES"		=> \$store_successes,
3249cc9e091SSteven Rostedt    "TEST_NAME"			=> \$test_name,
3259cc9e091SSteven Rostedt    "TIMEOUT"			=> \$timeout,
3263e1d3678SSteven Rostedt (VMware)    "CONNECT_TIMEOUT"		=> \$connect_timeout,
32740667fb5SSteven Rostedt (VMware)    "CONFIG_BISECT_EXEC"	=> \$config_bisect_exec,
3289cc9e091SSteven Rostedt    "BOOTED_TIMEOUT"		=> \$booted_timeout,
3299cc9e091SSteven Rostedt    "CONSOLE"			=> \$console,
3305a5d8e48SSatoru Takeuchi    "CLOSE_CONSOLE_SIGNAL"	=> \$close_console_signal,
3319cc9e091SSteven Rostedt    "DETECT_TRIPLE_FAULT"	=> \$detect_triplefault,
3329cc9e091SSteven Rostedt    "SUCCESS_LINE"		=> \$success_line,
3339cc9e091SSteven Rostedt    "REBOOT_SUCCESS_LINE"	=> \$reboot_success_line,
3349cc9e091SSteven Rostedt    "STOP_AFTER_SUCCESS"	=> \$stop_after_success,
3359cc9e091SSteven Rostedt    "STOP_AFTER_FAILURE"	=> \$stop_after_failure,
3369cc9e091SSteven Rostedt    "STOP_TEST_AFTER"		=> \$stop_test_after,
3379cc9e091SSteven Rostedt    "BUILD_TARGET"		=> \$build_target,
3389cc9e091SSteven Rostedt    "SSH_EXEC"			=> \$ssh_exec,
3399cc9e091SSteven Rostedt    "SCP_TO_TARGET"		=> \$scp_to_target,
34002ad2617SSteven Rostedt    "SCP_TO_TARGET_INSTALL"	=> \$scp_to_target_install,
3419cc9e091SSteven Rostedt    "CHECKOUT"			=> \$checkout,
3429cc9e091SSteven Rostedt    "TARGET_IMAGE"		=> \$target_image,
3439cc9e091SSteven Rostedt    "LOCALVERSION"		=> \$localversion,
3449cc9e091SSteven Rostedt
3459cc9e091SSteven Rostedt    "BISECT_GOOD"		=> \$bisect_good,
3469cc9e091SSteven Rostedt    "BISECT_BAD"		=> \$bisect_bad,
3479cc9e091SSteven Rostedt    "BISECT_TYPE"		=> \$bisect_type,
3489cc9e091SSteven Rostedt    "BISECT_START"		=> \$bisect_start,
3499cc9e091SSteven Rostedt    "BISECT_REPLAY"		=> \$bisect_replay,
3509cc9e091SSteven Rostedt    "BISECT_FILES"		=> \$bisect_files,
3519cc9e091SSteven Rostedt    "BISECT_REVERSE"		=> \$bisect_reverse,
3529cc9e091SSteven Rostedt    "BISECT_CHECK"		=> \$bisect_check,
3539cc9e091SSteven Rostedt
3549cc9e091SSteven Rostedt    "CONFIG_BISECT"		=> \$config_bisect,
3559cc9e091SSteven Rostedt    "CONFIG_BISECT_TYPE"	=> \$config_bisect_type,
356b0918612SSteven Rostedt    "CONFIG_BISECT_CHECK"	=> \$config_bisect_check,
3579cc9e091SSteven Rostedt
3589cc9e091SSteven Rostedt    "PATCHCHECK_TYPE"		=> \$patchcheck_type,
3599cc9e091SSteven Rostedt    "PATCHCHECK_START"		=> \$patchcheck_start,
36023a0e161SSteven Rostedt (Red Hat)    "PATCHCHECK_CHERRY"		=> \$patchcheck_cherry,
3619cc9e091SSteven Rostedt    "PATCHCHECK_END"		=> \$patchcheck_end,
3629cc9e091SSteven Rostedt);
3639cc9e091SSteven Rostedt
3649cc9e091SSteven Rostedt# Options may be used by other options, record them.
3659cc9e091SSteven Rostedtmy %used_options;
3669cc9e091SSteven Rostedt
3677bf51073SSteven Rostedt# default variables that can be used
3687bf51073SSteven Rostedtchomp ($variable{"PWD"} = `pwd`);
36940667fb5SSteven Rostedt (VMware)$pwd = $variable{"PWD"};
3707bf51073SSteven Rostedt
3718d1491baSSteven Rostedt$config_help{"MACHINE"} = << "EOF"
3728d1491baSSteven Rostedt The machine hostname that you will test.
373bb8474b1SSteven Rostedt For build only tests, it is still needed to differentiate log files.
3748d1491baSSteven RostedtEOF
3758d1491baSSteven Rostedt    ;
3768d1491baSSteven Rostedt$config_help{"SSH_USER"} = << "EOF"
3778d1491baSSteven Rostedt The box is expected to have ssh on normal bootup, provide the user
3788d1491baSSteven Rostedt  (most likely root, since you need privileged operations)
3798d1491baSSteven RostedtEOF
3808d1491baSSteven Rostedt    ;
3818d1491baSSteven Rostedt$config_help{"BUILD_DIR"} = << "EOF"
3828d1491baSSteven Rostedt The directory that contains the Linux source code (full path).
3830e7a22deSSteven Rostedt You can use \${PWD} that will be the path where ktest.pl is run, or use
3840e7a22deSSteven Rostedt \${THIS_DIR} which is assigned \${PWD} but may be changed later.
3858d1491baSSteven RostedtEOF
3868d1491baSSteven Rostedt    ;
3878d1491baSSteven Rostedt$config_help{"OUTPUT_DIR"} = << "EOF"
3888d1491baSSteven Rostedt The directory that the objects will be built (full path).
3898d1491baSSteven Rostedt (can not be same as BUILD_DIR)
3900e7a22deSSteven Rostedt You can use \${PWD} that will be the path where ktest.pl is run, or use
3910e7a22deSSteven Rostedt \${THIS_DIR} which is assigned \${PWD} but may be changed later.
3928d1491baSSteven RostedtEOF
3938d1491baSSteven Rostedt    ;
3948d1491baSSteven Rostedt$config_help{"BUILD_TARGET"} = << "EOF"
3958d1491baSSteven Rostedt The location of the compiled file to copy to the target.
3968d1491baSSteven Rostedt (relative to OUTPUT_DIR)
3978d1491baSSteven RostedtEOF
3988d1491baSSteven Rostedt    ;
399dbd3783bSSteven Rostedt$config_help{"BUILD_OPTIONS"} = << "EOF"
400dbd3783bSSteven Rostedt Options to add to \"make\" when building.
401dbd3783bSSteven Rostedt i.e.  -j20
402dbd3783bSSteven RostedtEOF
403dbd3783bSSteven Rostedt    ;
4048d1491baSSteven Rostedt$config_help{"TARGET_IMAGE"} = << "EOF"
4058d1491baSSteven Rostedt The place to put your image on the test machine.
4068d1491baSSteven RostedtEOF
4078d1491baSSteven Rostedt    ;
4088d1491baSSteven Rostedt$config_help{"POWER_CYCLE"} = << "EOF"
4098d1491baSSteven Rostedt A script or command to reboot the box.
4108d1491baSSteven Rostedt
4118d1491baSSteven Rostedt Here is a digital loggers power switch example
4128d1491baSSteven Rostedt POWER_CYCLE = wget --no-proxy -O /dev/null -q  --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
4138d1491baSSteven Rostedt
4148d1491baSSteven Rostedt Here is an example to reboot a virtual box on the current host
4158d1491baSSteven Rostedt with the name "Guest".
4168d1491baSSteven Rostedt POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
4178d1491baSSteven RostedtEOF
4188d1491baSSteven Rostedt    ;
4198d1491baSSteven Rostedt$config_help{"CONSOLE"} = << "EOF"
4208d1491baSSteven Rostedt The script or command that reads the console
4218d1491baSSteven Rostedt
4228d1491baSSteven Rostedt  If you use ttywatch server, something like the following would work.
4238d1491baSSteven RostedtCONSOLE = nc -d localhost 3001
4248d1491baSSteven Rostedt
4258d1491baSSteven Rostedt For a virtual machine with guest name "Guest".
4268d1491baSSteven RostedtCONSOLE =  virsh console Guest
4278d1491baSSteven RostedtEOF
4288d1491baSSteven Rostedt    ;
4298d1491baSSteven Rostedt$config_help{"LOCALVERSION"} = << "EOF"
4308d1491baSSteven Rostedt Required version ending to differentiate the test
4318d1491baSSteven Rostedt from other linux builds on the system.
4328d1491baSSteven RostedtEOF
4338d1491baSSteven Rostedt    ;
4348d1491baSSteven Rostedt$config_help{"REBOOT_TYPE"} = << "EOF"
4358d1491baSSteven Rostedt Way to reboot the box to the test kernel.
4367786954cSSteven Rostedt Only valid options so far are "grub", "grub2", "syslinux", and "script".
4378d1491baSSteven Rostedt
4388d1491baSSteven Rostedt If you specify grub, it will assume grub version 1
4398d1491baSSteven Rostedt and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
4408d1491baSSteven Rostedt and select that target to reboot to the kernel. If this is not
4418d1491baSSteven Rostedt your setup, then specify "script" and have a command or script
4428d1491baSSteven Rostedt specified in REBOOT_SCRIPT to boot to the target.
4438d1491baSSteven Rostedt
4448d1491baSSteven Rostedt The entry in /boot/grub/menu.lst must be entered in manually.
4458d1491baSSteven Rostedt The test will not modify that file.
446a15ba913SSteven Rostedt
447a15ba913SSteven Rostedt If you specify grub2, then you also need to specify both \$GRUB_MENU
448a15ba913SSteven Rostedt and \$GRUB_FILE.
4497786954cSSteven Rostedt
4507786954cSSteven Rostedt If you specify syslinux, then you may use SYSLINUX to define the syslinux
4517786954cSSteven Rostedt command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
4527786954cSSteven Rostedt the syslinux install (defaults to /boot/extlinux). But you have to specify
4537786954cSSteven Rostedt SYSLINUX_LABEL to define the label to boot to for the test kernel.
4548d1491baSSteven RostedtEOF
4558d1491baSSteven Rostedt    ;
4568d1491baSSteven Rostedt$config_help{"GRUB_MENU"} = << "EOF"
4578d1491baSSteven Rostedt The grub title name for the test kernel to boot
458a15ba913SSteven Rostedt (Only mandatory if REBOOT_TYPE = grub or grub2)
4598d1491baSSteven Rostedt
4608d1491baSSteven Rostedt Note, ktest.pl will not update the grub menu.lst, you need to
4618d1491baSSteven Rostedt manually add an option for the test. ktest.pl will search
4628d1491baSSteven Rostedt the grub menu.lst for this option to find what kernel to
4638d1491baSSteven Rostedt reboot into.
4648d1491baSSteven Rostedt
4658d1491baSSteven Rostedt For example, if in the /boot/grub/menu.lst the test kernel title has:
4668d1491baSSteven Rostedt title Test Kernel
4678d1491baSSteven Rostedt kernel vmlinuz-test
4688d1491baSSteven Rostedt GRUB_MENU = Test Kernel
469a15ba913SSteven Rostedt
470a15ba913SSteven Rostedt For grub2, a search of \$GRUB_FILE is performed for the lines
471a15ba913SSteven Rostedt that begin with "menuentry". It will not detect submenus. The
472a15ba913SSteven Rostedt menu must be a non-nested menu. Add the quotes used in the menu
473a15ba913SSteven Rostedt to guarantee your selection, as the first menuentry with the content
474a15ba913SSteven Rostedt of \$GRUB_MENU that is found will be used.
475a15ba913SSteven RostedtEOF
476a15ba913SSteven Rostedt    ;
477a15ba913SSteven Rostedt$config_help{"GRUB_FILE"} = << "EOF"
478a15ba913SSteven Rostedt If grub2 is used, the full path for the grub.cfg file is placed
479a15ba913SSteven Rostedt here. Use something like /boot/grub2/grub.cfg to search.
4808d1491baSSteven RostedtEOF
4818d1491baSSteven Rostedt    ;
4827786954cSSteven Rostedt$config_help{"SYSLINUX_LABEL"} = << "EOF"
4837786954cSSteven Rostedt If syslinux is used, the label that boots the target kernel must
4847786954cSSteven Rostedt be specified with SYSLINUX_LABEL.
4857786954cSSteven RostedtEOF
4867786954cSSteven Rostedt    ;
4878d1491baSSteven Rostedt$config_help{"REBOOT_SCRIPT"} = << "EOF"
4888d1491baSSteven Rostedt A script to reboot the target into the test kernel
4898d1491baSSteven Rostedt (Only mandatory if REBOOT_TYPE = script)
4908d1491baSSteven RostedtEOF
4918d1491baSSteven Rostedt    ;
4928d1491baSSteven Rostedt
493c75d22d9SSteven Rostedt (Red Hat)sub _logit {
494c75d22d9SSteven Rostedt (Red Hat)    if (defined($opt{"LOG_FILE"})) {
495c75d22d9SSteven Rostedt (Red Hat)	open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
496c75d22d9SSteven Rostedt (Red Hat)	print OUT @_;
497c75d22d9SSteven Rostedt (Red Hat)	close(OUT);
498c75d22d9SSteven Rostedt (Red Hat)    }
499c75d22d9SSteven Rostedt (Red Hat)}
500c75d22d9SSteven Rostedt (Red Hat)
501c75d22d9SSteven Rostedt (Red Hat)sub logit {
502c75d22d9SSteven Rostedt (Red Hat)    if (defined($opt{"LOG_FILE"})) {
503c75d22d9SSteven Rostedt (Red Hat)	_logit @_;
504c75d22d9SSteven Rostedt (Red Hat)    } else {
505c75d22d9SSteven Rostedt (Red Hat)	print @_;
506c75d22d9SSteven Rostedt (Red Hat)    }
507c75d22d9SSteven Rostedt (Red Hat)}
508c75d22d9SSteven Rostedt (Red Hat)
509c75d22d9SSteven Rostedt (Red Hat)sub doprint {
510c75d22d9SSteven Rostedt (Red Hat)    print @_;
511c75d22d9SSteven Rostedt (Red Hat)    _logit @_;
512c75d22d9SSteven Rostedt (Red Hat)}
513c75d22d9SSteven Rostedt (Red Hat)
514dad98754SSteven Rostedtsub read_prompt {
515dad98754SSteven Rostedt    my ($cancel, $prompt) = @_;
51635ce5952SSteven Rostedt
51735ce5952SSteven Rostedt    my $ans;
51835ce5952SSteven Rostedt
51935ce5952SSteven Rostedt    for (;;) {
520dad98754SSteven Rostedt	if ($cancel) {
521dad98754SSteven Rostedt	    print "$prompt [y/n/C] ";
522dad98754SSteven Rostedt	} else {
52335ce5952SSteven Rostedt	    print "$prompt [Y/n] ";
524dad98754SSteven Rostedt	}
52535ce5952SSteven Rostedt	$ans = <STDIN>;
52635ce5952SSteven Rostedt	chomp $ans;
52735ce5952SSteven Rostedt	if ($ans =~ /^\s*$/) {
528dad98754SSteven Rostedt	    if ($cancel) {
529dad98754SSteven Rostedt		$ans = "c";
530dad98754SSteven Rostedt	    } else {
53135ce5952SSteven Rostedt		$ans = "y";
53235ce5952SSteven Rostedt	    }
533dad98754SSteven Rostedt	}
53435ce5952SSteven Rostedt	last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
535dad98754SSteven Rostedt	if ($cancel) {
536dad98754SSteven Rostedt	    last if ($ans =~ /^c$/i);
537dad98754SSteven Rostedt	    print "Please answer either 'y', 'n' or 'c'.\n";
538dad98754SSteven Rostedt	} else {
53935ce5952SSteven Rostedt	    print "Please answer either 'y' or 'n'.\n";
54035ce5952SSteven Rostedt	}
541dad98754SSteven Rostedt    }
542dad98754SSteven Rostedt    if ($ans =~ /^c/i) {
543dad98754SSteven Rostedt	exit;
544dad98754SSteven Rostedt    }
54535ce5952SSteven Rostedt    if ($ans !~ /^y$/i) {
54635ce5952SSteven Rostedt	return 0;
54735ce5952SSteven Rostedt    }
54835ce5952SSteven Rostedt    return 1;
54935ce5952SSteven Rostedt}
5508d1491baSSteven Rostedt
551dad98754SSteven Rostedtsub read_yn {
552dad98754SSteven Rostedt    my ($prompt) = @_;
553dad98754SSteven Rostedt
554dad98754SSteven Rostedt    return read_prompt 0, $prompt;
555dad98754SSteven Rostedt}
556dad98754SSteven Rostedt
557dad98754SSteven Rostedtsub read_ync {
558dad98754SSteven Rostedt    my ($prompt) = @_;
559dad98754SSteven Rostedt
560dad98754SSteven Rostedt    return read_prompt 1, $prompt;
561dad98754SSteven Rostedt}
562dad98754SSteven Rostedt
5635269faadSSatoru Takeuchisub get_mandatory_config {
5648d1491baSSteven Rostedt    my ($config) = @_;
565815e2bd7SSteven Rostedt    my $ans;
5668d1491baSSteven Rostedt
5678d1491baSSteven Rostedt    return if (defined($opt{$config}));
5688d1491baSSteven Rostedt
5698d1491baSSteven Rostedt    if (defined($config_help{$config})) {
5708d1491baSSteven Rostedt	print "\n";
5718d1491baSSteven Rostedt	print $config_help{$config};
5728d1491baSSteven Rostedt    }
5738d1491baSSteven Rostedt
5748d1491baSSteven Rostedt    for (;;) {
5758d1491baSSteven Rostedt	print "$config = ";
576dbd3783bSSteven Rostedt	if (defined($default{$config}) && length($default{$config})) {
5778d1491baSSteven Rostedt	    print "\[$default{$config}\] ";
5788d1491baSSteven Rostedt	}
579815e2bd7SSteven Rostedt	$ans = <STDIN>;
580815e2bd7SSteven Rostedt	$ans =~ s/^\s*(.*\S)\s*$/$1/;
581815e2bd7SSteven Rostedt	if ($ans =~ /^\s*$/) {
5828d1491baSSteven Rostedt	    if ($default{$config}) {
583815e2bd7SSteven Rostedt		$ans = $default{$config};
5848d1491baSSteven Rostedt	    } else {
5858d1491baSSteven Rostedt		print "Your answer can not be blank\n";
5868d1491baSSteven Rostedt		next;
5878d1491baSSteven Rostedt	    }
5888d1491baSSteven Rostedt	}
5890e7a22deSSteven Rostedt	$entered_configs{$config} = ${ans};
5908d1491baSSteven Rostedt	last;
5918d1491baSSteven Rostedt    }
5928d1491baSSteven Rostedt}
5938d1491baSSteven Rostedt
59438fa3dc1SSteven Rostedt (Red Hat)sub show_time {
59538fa3dc1SSteven Rostedt (Red Hat)    my ($time) = @_;
59638fa3dc1SSteven Rostedt (Red Hat)
59738fa3dc1SSteven Rostedt (Red Hat)    my $hours = 0;
59838fa3dc1SSteven Rostedt (Red Hat)    my $minutes = 0;
59938fa3dc1SSteven Rostedt (Red Hat)
60038fa3dc1SSteven Rostedt (Red Hat)    if ($time > 3600) {
60138fa3dc1SSteven Rostedt (Red Hat)	$hours = int($time / 3600);
60238fa3dc1SSteven Rostedt (Red Hat)	$time -= $hours * 3600;
60338fa3dc1SSteven Rostedt (Red Hat)    }
60438fa3dc1SSteven Rostedt (Red Hat)    if ($time > 60) {
60538fa3dc1SSteven Rostedt (Red Hat)	$minutes = int($time / 60);
60638fa3dc1SSteven Rostedt (Red Hat)	$time -= $minutes * 60;
60738fa3dc1SSteven Rostedt (Red Hat)    }
60838fa3dc1SSteven Rostedt (Red Hat)
60938fa3dc1SSteven Rostedt (Red Hat)    if ($hours > 0) {
61038fa3dc1SSteven Rostedt (Red Hat)	doprint "$hours hour";
61138fa3dc1SSteven Rostedt (Red Hat)	doprint "s" if ($hours > 1);
61238fa3dc1SSteven Rostedt (Red Hat)	doprint " ";
61338fa3dc1SSteven Rostedt (Red Hat)    }
61438fa3dc1SSteven Rostedt (Red Hat)
61538fa3dc1SSteven Rostedt (Red Hat)    if ($minutes > 0) {
61638fa3dc1SSteven Rostedt (Red Hat)	doprint "$minutes minute";
61738fa3dc1SSteven Rostedt (Red Hat)	doprint "s" if ($minutes > 1);
61838fa3dc1SSteven Rostedt (Red Hat)	doprint " ";
61938fa3dc1SSteven Rostedt (Red Hat)    }
62038fa3dc1SSteven Rostedt (Red Hat)
62138fa3dc1SSteven Rostedt (Red Hat)    doprint "$time second";
62238fa3dc1SSteven Rostedt (Red Hat)    doprint "s" if ($time != 1);
62338fa3dc1SSteven Rostedt (Red Hat)}
62438fa3dc1SSteven Rostedt (Red Hat)
62538fa3dc1SSteven Rostedt (Red Hat)sub print_times {
62638fa3dc1SSteven Rostedt (Red Hat)    doprint "\n";
62738fa3dc1SSteven Rostedt (Red Hat)    if ($build_time) {
62838fa3dc1SSteven Rostedt (Red Hat)	doprint "Build time:   ";
62938fa3dc1SSteven Rostedt (Red Hat)	show_time($build_time);
63038fa3dc1SSteven Rostedt (Red Hat)	doprint "\n";
63138fa3dc1SSteven Rostedt (Red Hat)    }
63238fa3dc1SSteven Rostedt (Red Hat)    if ($install_time) {
63338fa3dc1SSteven Rostedt (Red Hat)	doprint "Install time: ";
63438fa3dc1SSteven Rostedt (Red Hat)	show_time($install_time);
63538fa3dc1SSteven Rostedt (Red Hat)	doprint "\n";
63638fa3dc1SSteven Rostedt (Red Hat)    }
63738fa3dc1SSteven Rostedt (Red Hat)    if ($reboot_time) {
63838fa3dc1SSteven Rostedt (Red Hat)	doprint "Reboot time:  ";
63938fa3dc1SSteven Rostedt (Red Hat)	show_time($reboot_time);
64038fa3dc1SSteven Rostedt (Red Hat)	doprint "\n";
64138fa3dc1SSteven Rostedt (Red Hat)    }
64238fa3dc1SSteven Rostedt (Red Hat)    if ($test_time) {
64338fa3dc1SSteven Rostedt (Red Hat)	doprint "Test time:    ";
64438fa3dc1SSteven Rostedt (Red Hat)	show_time($test_time);
64538fa3dc1SSteven Rostedt (Red Hat)	doprint "\n";
64638fa3dc1SSteven Rostedt (Red Hat)    }
64738fa3dc1SSteven Rostedt (Red Hat)    # reset for iterations like bisect
64838fa3dc1SSteven Rostedt (Red Hat)    $build_time = 0;
64938fa3dc1SSteven Rostedt (Red Hat)    $install_time = 0;
65038fa3dc1SSteven Rostedt (Red Hat)    $reboot_time = 0;
65138fa3dc1SSteven Rostedt (Red Hat)    $test_time = 0;
65238fa3dc1SSteven Rostedt (Red Hat)}
65338fa3dc1SSteven Rostedt (Red Hat)
6545269faadSSatoru Takeuchisub get_mandatory_configs {
6555269faadSSatoru Takeuchi    get_mandatory_config("MACHINE");
6565269faadSSatoru Takeuchi    get_mandatory_config("BUILD_DIR");
6575269faadSSatoru Takeuchi    get_mandatory_config("OUTPUT_DIR");
658bb8474b1SSteven Rostedt
659dbd3783bSSteven Rostedt    if ($newconfig) {
6605269faadSSatoru Takeuchi	get_mandatory_config("BUILD_OPTIONS");
661dbd3783bSSteven Rostedt    }
662dbd3783bSSteven Rostedt
663bb8474b1SSteven Rostedt    # options required for other than just building a kernel
664bb8474b1SSteven Rostedt    if (!$buildonly) {
6655269faadSSatoru Takeuchi	get_mandatory_config("POWER_CYCLE");
6665269faadSSatoru Takeuchi	get_mandatory_config("CONSOLE");
667165708b2SSteven Rostedt    }
668165708b2SSteven Rostedt
669165708b2SSteven Rostedt    # options required for install and more
670165708b2SSteven Rostedt    if ($buildonly != 1) {
6715269faadSSatoru Takeuchi	get_mandatory_config("SSH_USER");
6725269faadSSatoru Takeuchi	get_mandatory_config("BUILD_TARGET");
6735269faadSSatoru Takeuchi	get_mandatory_config("TARGET_IMAGE");
674bb8474b1SSteven Rostedt    }
675bb8474b1SSteven Rostedt
6765269faadSSatoru Takeuchi    get_mandatory_config("LOCALVERSION");
6778d1491baSSteven Rostedt
678bb8474b1SSteven Rostedt    return if ($buildonly);
679bb8474b1SSteven Rostedt
6808d1491baSSteven Rostedt    my $rtype = $opt{"REBOOT_TYPE"};
6818d1491baSSteven Rostedt
6828d1491baSSteven Rostedt    if (!defined($rtype)) {
6838d1491baSSteven Rostedt	if (!defined($opt{"GRUB_MENU"})) {
6845269faadSSatoru Takeuchi	    get_mandatory_config("REBOOT_TYPE");
6858d1491baSSteven Rostedt	    $rtype = $entered_configs{"REBOOT_TYPE"};
6868d1491baSSteven Rostedt	} else {
6878d1491baSSteven Rostedt	    $rtype = "grub";
6888d1491baSSteven Rostedt	}
6898d1491baSSteven Rostedt    }
6908d1491baSSteven Rostedt
6918d1491baSSteven Rostedt    if ($rtype eq "grub") {
6925269faadSSatoru Takeuchi	get_mandatory_config("GRUB_MENU");
6938d1491baSSteven Rostedt    }
694a15ba913SSteven Rostedt
695a15ba913SSteven Rostedt    if ($rtype eq "grub2") {
6965269faadSSatoru Takeuchi	get_mandatory_config("GRUB_MENU");
6975269faadSSatoru Takeuchi	get_mandatory_config("GRUB_FILE");
698a15ba913SSteven Rostedt    }
6997786954cSSteven Rostedt
7007786954cSSteven Rostedt    if ($rtype eq "syslinux") {
7015269faadSSatoru Takeuchi	get_mandatory_config("SYSLINUX_LABEL");
7027786954cSSteven Rostedt    }
7038d1491baSSteven Rostedt}
7048d1491baSSteven Rostedt
70577d942ceSSteven Rostedtsub process_variables {
7068d735212SSteven Rostedt    my ($value, $remove_undef) = @_;
70777d942ceSSteven Rostedt    my $retval = "";
70877d942ceSSteven Rostedt
70977d942ceSSteven Rostedt    # We want to check for '\', and it is just easier
71077d942ceSSteven Rostedt    # to check the previous characet of '$' and not need
71177d942ceSSteven Rostedt    # to worry if '$' is the first character. By adding
71277d942ceSSteven Rostedt    # a space to $value, we can just check [^\\]\$ and
71377d942ceSSteven Rostedt    # it will still work.
71477d942ceSSteven Rostedt    $value = " $value";
71577d942ceSSteven Rostedt
71677d942ceSSteven Rostedt    while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
71777d942ceSSteven Rostedt	my $begin = $1;
71877d942ceSSteven Rostedt	my $var = $2;
71977d942ceSSteven Rostedt	my $end = $3;
72077d942ceSSteven Rostedt	# append beginning of value to retval
72177d942ceSSteven Rostedt	$retval = "$retval$begin";
72277d942ceSSteven Rostedt	if (defined($variable{$var})) {
72377d942ceSSteven Rostedt	    $retval = "$retval$variable{$var}";
7248d735212SSteven Rostedt	} elsif (defined($remove_undef) && $remove_undef) {
7258d735212SSteven Rostedt	    # for if statements, any variable that is not defined,
7268d735212SSteven Rostedt	    # we simple convert to 0
7278d735212SSteven Rostedt	    $retval = "${retval}0";
72877d942ceSSteven Rostedt	} else {
72977d942ceSSteven Rostedt	    # put back the origin piece.
73077d942ceSSteven Rostedt	    $retval = "$retval\$\{$var\}";
7319cc9e091SSteven Rostedt	    # This could be an option that is used later, save
7329cc9e091SSteven Rostedt	    # it so we don't warn if this option is not one of
7339cc9e091SSteven Rostedt	    # ktests options.
7349cc9e091SSteven Rostedt	    $used_options{$var} = 1;
73577d942ceSSteven Rostedt	}
73677d942ceSSteven Rostedt	$value = $end;
73777d942ceSSteven Rostedt    }
73877d942ceSSteven Rostedt    $retval = "$retval$value";
73977d942ceSSteven Rostedt
74077d942ceSSteven Rostedt    # remove the space added in the beginning
74177d942ceSSteven Rostedt    $retval =~ s/ //;
74277d942ceSSteven Rostedt
74377d942ceSSteven Rostedt    return "$retval"
74477d942ceSSteven Rostedt}
74577d942ceSSteven Rostedt
746a57419b3SSteven Rostedtsub set_value {
7473d1cc414SSteven Rostedt    my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
7482545eb61SSteven Rostedt
749cad96669SSteven Rostedt    my $prvalue = process_variables($rvalue);
750cad96669SSteven Rostedt
75125bc70faSScott Wood    if ($lvalue =~ /^(TEST|BISECT|CONFIG_BISECT)_TYPE(\[.*\])?$/ &&
75225bc70faSScott Wood	$prvalue !~ /^(config_|)bisect$/ &&
75325bc70faSScott Wood	$prvalue !~ /^build$/ &&
75425bc70faSScott Wood	$buildonly) {
75525bc70faSScott Wood
756bb8474b1SSteven Rostedt	# Note if a test is something other than build, then we
75722722799SPavel Machek	# will need other mandatory options.
758cad96669SSteven Rostedt	if ($prvalue ne "install") {
759bb8474b1SSteven Rostedt	    $buildonly = 0;
760165708b2SSteven Rostedt	} else {
76122722799SPavel Machek	    # install still limits some mandatory options.
762165708b2SSteven Rostedt	    $buildonly = 2;
763165708b2SSteven Rostedt	}
764bb8474b1SSteven Rostedt    }
765bb8474b1SSteven Rostedt
766a75fececSSteven Rostedt    if (defined($opt{$lvalue})) {
7673d1cc414SSteven Rostedt	if (!$override || defined(${$overrides}{$lvalue})) {
7683d1cc414SSteven Rostedt	    my $extra = "";
7693d1cc414SSteven Rostedt	    if ($override) {
7703d1cc414SSteven Rostedt		$extra = "In the same override section!\n";
7713d1cc414SSteven Rostedt	    }
7723d1cc414SSteven Rostedt	    die "$name: $.: Option $lvalue defined more than once!\n$extra";
7733d1cc414SSteven Rostedt	}
774cad96669SSteven Rostedt	${$overrides}{$lvalue} = $prvalue;
775a75fececSSteven Rostedt    }
77622c37a9aSSteven Rostedt (Red Hat)
777cad96669SSteven Rostedt    $opt{$lvalue} = $prvalue;
77821a9679fSSteven Rostedt}
779a57419b3SSteven Rostedt
780c75d22d9SSteven Rostedt (Red Hat)sub set_eval {
781c75d22d9SSteven Rostedt (Red Hat)    my ($lvalue, $rvalue, $name) = @_;
782c75d22d9SSteven Rostedt (Red Hat)
783c75d22d9SSteven Rostedt (Red Hat)    my $prvalue = process_variables($rvalue);
784c75d22d9SSteven Rostedt (Red Hat)    my $arr;
785c75d22d9SSteven Rostedt (Red Hat)
786c75d22d9SSteven Rostedt (Red Hat)    if (defined($evals{$lvalue})) {
787c75d22d9SSteven Rostedt (Red Hat)	$arr = $evals{$lvalue};
788c75d22d9SSteven Rostedt (Red Hat)    } else {
789c75d22d9SSteven Rostedt (Red Hat)	$arr = [];
790c75d22d9SSteven Rostedt (Red Hat)	$evals{$lvalue} = $arr;
791c75d22d9SSteven Rostedt (Red Hat)    }
792c75d22d9SSteven Rostedt (Red Hat)
793c75d22d9SSteven Rostedt (Red Hat)    push @{$arr}, $rvalue;
794c75d22d9SSteven Rostedt (Red Hat)}
795c75d22d9SSteven Rostedt (Red Hat)
79677d942ceSSteven Rostedtsub set_variable {
79777d942ceSSteven Rostedt    my ($lvalue, $rvalue) = @_;
79877d942ceSSteven Rostedt
79977d942ceSSteven Rostedt    if ($rvalue =~ /^\s*$/) {
80077d942ceSSteven Rostedt	delete $variable{$lvalue};
80177d942ceSSteven Rostedt    } else {
80277d942ceSSteven Rostedt	$rvalue = process_variables($rvalue);
80377d942ceSSteven Rostedt	$variable{$lvalue} = $rvalue;
80477d942ceSSteven Rostedt    }
80577d942ceSSteven Rostedt}
80677d942ceSSteven Rostedt
807ab7a3f52SSteven Rostedtsub process_compare {
808ab7a3f52SSteven Rostedt    my ($lval, $cmp, $rval) = @_;
809ab7a3f52SSteven Rostedt
810ab7a3f52SSteven Rostedt    # remove whitespace
811ab7a3f52SSteven Rostedt
812ab7a3f52SSteven Rostedt    $lval =~ s/^\s*//;
813ab7a3f52SSteven Rostedt    $lval =~ s/\s*$//;
814ab7a3f52SSteven Rostedt
815ab7a3f52SSteven Rostedt    $rval =~ s/^\s*//;
816ab7a3f52SSteven Rostedt    $rval =~ s/\s*$//;
817ab7a3f52SSteven Rostedt
818ab7a3f52SSteven Rostedt    if ($cmp eq "==") {
819ab7a3f52SSteven Rostedt	return $lval eq $rval;
820ab7a3f52SSteven Rostedt    } elsif ($cmp eq "!=") {
821ab7a3f52SSteven Rostedt	return $lval ne $rval;
8228fddbe9bSSteven Rostedt    } elsif ($cmp eq "=~") {
8238fddbe9bSSteven Rostedt	return $lval =~ m/$rval/;
8248fddbe9bSSteven Rostedt    } elsif ($cmp eq "!~") {
8258fddbe9bSSteven Rostedt	return $lval !~ m/$rval/;
826ab7a3f52SSteven Rostedt    }
827ab7a3f52SSteven Rostedt
828ab7a3f52SSteven Rostedt    my $statement = "$lval $cmp $rval";
829ab7a3f52SSteven Rostedt    my $ret = eval $statement;
830ab7a3f52SSteven Rostedt
831ab7a3f52SSteven Rostedt    # $@ stores error of eval
832ab7a3f52SSteven Rostedt    if ($@) {
833ab7a3f52SSteven Rostedt	return -1;
834ab7a3f52SSteven Rostedt    }
835ab7a3f52SSteven Rostedt
836ab7a3f52SSteven Rostedt    return $ret;
837ab7a3f52SSteven Rostedt}
838ab7a3f52SSteven Rostedt
8399900b5dcSSteven Rostedtsub value_defined {
8409900b5dcSSteven Rostedt    my ($val) = @_;
8419900b5dcSSteven Rostedt
8429900b5dcSSteven Rostedt    return defined($variable{$2}) ||
8439900b5dcSSteven Rostedt	defined($opt{$2});
8449900b5dcSSteven Rostedt}
8459900b5dcSSteven Rostedt
8468d735212SSteven Rostedtmy $d = 0;
8478d735212SSteven Rostedtsub process_expression {
8488d735212SSteven Rostedt    my ($name, $val) = @_;
84945d73a5dSSteven Rostedt
8508d735212SSteven Rostedt    my $c = $d++;
8518d735212SSteven Rostedt
8528d735212SSteven Rostedt    while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
8538d735212SSteven Rostedt	my $express = $1;
8548d735212SSteven Rostedt
8558d735212SSteven Rostedt	if (process_expression($name, $express)) {
8568d735212SSteven Rostedt	    $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
8578d735212SSteven Rostedt	} else {
8588d735212SSteven Rostedt	    $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
8598d735212SSteven Rostedt	}
8608d735212SSteven Rostedt    }
8618d735212SSteven Rostedt
8628d735212SSteven Rostedt    $d--;
8638d735212SSteven Rostedt    my $OR = "\\|\\|";
8648d735212SSteven Rostedt    my $AND = "\\&\\&";
8658d735212SSteven Rostedt
8668d735212SSteven Rostedt    while ($val =~ s/^(.*?)($OR|$AND)//) {
8678d735212SSteven Rostedt	my $express = $1;
8688d735212SSteven Rostedt	my $op = $2;
8698d735212SSteven Rostedt
8708d735212SSteven Rostedt	if (process_expression($name, $express)) {
8718d735212SSteven Rostedt	    if ($op eq "||") {
8728d735212SSteven Rostedt		return 1;
8738d735212SSteven Rostedt	    }
8748d735212SSteven Rostedt	} else {
8758d735212SSteven Rostedt	    if ($op eq "&&") {
8768d735212SSteven Rostedt		return 0;
8778d735212SSteven Rostedt	    }
8788d735212SSteven Rostedt	}
8798d735212SSteven Rostedt    }
88045d73a5dSSteven Rostedt
8818fddbe9bSSteven Rostedt    if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
882ab7a3f52SSteven Rostedt	my $ret = process_compare($1, $2, $3);
883ab7a3f52SSteven Rostedt	if ($ret < 0) {
884ab7a3f52SSteven Rostedt	    die "$name: $.: Unable to process comparison\n";
885ab7a3f52SSteven Rostedt	}
886ab7a3f52SSteven Rostedt	return $ret;
887ab7a3f52SSteven Rostedt    }
888ab7a3f52SSteven Rostedt
8899900b5dcSSteven Rostedt    if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
8909900b5dcSSteven Rostedt	if (defined $1) {
8919900b5dcSSteven Rostedt	    return !value_defined($2);
8929900b5dcSSteven Rostedt	} else {
8939900b5dcSSteven Rostedt	    return value_defined($2);
8949900b5dcSSteven Rostedt	}
8959900b5dcSSteven Rostedt    }
8969900b5dcSSteven Rostedt
89745d73a5dSSteven Rostedt    if ($val =~ /^\s*0\s*$/) {
89845d73a5dSSteven Rostedt	return 0;
89945d73a5dSSteven Rostedt    } elsif ($val =~ /^\s*\d+\s*$/) {
90045d73a5dSSteven Rostedt	return 1;
90145d73a5dSSteven Rostedt    }
90245d73a5dSSteven Rostedt
9039900b5dcSSteven Rostedt    die ("$name: $.: Undefined content $val in if statement\n");
9048d735212SSteven Rostedt}
9058d735212SSteven Rostedt
9068d735212SSteven Rostedtsub process_if {
9078d735212SSteven Rostedt    my ($name, $value) = @_;
9088d735212SSteven Rostedt
9098d735212SSteven Rostedt    # Convert variables and replace undefined ones with 0
9108d735212SSteven Rostedt    my $val = process_variables($value, 1);
9118d735212SSteven Rostedt    my $ret = process_expression $name, $val;
9128d735212SSteven Rostedt
9138d735212SSteven Rostedt    return $ret;
91445d73a5dSSteven Rostedt}
91545d73a5dSSteven Rostedt
9162ed3b161SSteven Rostedtsub __read_config {
9172ed3b161SSteven Rostedt    my ($config, $current_test_num) = @_;
918a57419b3SSteven Rostedt
9192ed3b161SSteven Rostedt    my $in;
9202ed3b161SSteven Rostedt    open($in, $config) || die "can't read file $config";
921a57419b3SSteven Rostedt
922a57419b3SSteven Rostedt    my $name = $config;
923a57419b3SSteven Rostedt    $name =~ s,.*/(.*),$1,;
924a57419b3SSteven Rostedt
9252ed3b161SSteven Rostedt    my $test_num = $$current_test_num;
926a57419b3SSteven Rostedt    my $default = 1;
927a57419b3SSteven Rostedt    my $repeat = 1;
928a57419b3SSteven Rostedt    my $num_tests_set = 0;
929a57419b3SSteven Rostedt    my $skip = 0;
930a57419b3SSteven Rostedt    my $rest;
931a9f84424SSteven Rostedt    my $line;
9320df213caSSteven Rostedt    my $test_case = 0;
93345d73a5dSSteven Rostedt    my $if = 0;
93445d73a5dSSteven Rostedt    my $if_set = 0;
9353d1cc414SSteven Rostedt    my $override = 0;
9363d1cc414SSteven Rostedt
9373d1cc414SSteven Rostedt    my %overrides;
938a57419b3SSteven Rostedt
9392ed3b161SSteven Rostedt    while (<$in>) {
940a57419b3SSteven Rostedt
941a57419b3SSteven Rostedt	# ignore blank lines and comments
942a57419b3SSteven Rostedt	next if (/^\s*$/ || /\s*\#/);
943a57419b3SSteven Rostedt
9440050b6bbSSteven Rostedt	if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
945a57419b3SSteven Rostedt
9460050b6bbSSteven Rostedt	    my $type = $1;
9470050b6bbSSteven Rostedt	    $rest = $2;
948a9f84424SSteven Rostedt	    $line = $2;
9490050b6bbSSteven Rostedt
9500050b6bbSSteven Rostedt	    my $old_test_num;
9510050b6bbSSteven Rostedt	    my $old_repeat;
9523d1cc414SSteven Rostedt	    $override = 0;
9530050b6bbSSteven Rostedt
9540050b6bbSSteven Rostedt	    if ($type eq "TEST_START") {
955a57419b3SSteven Rostedt
956a57419b3SSteven Rostedt		if ($num_tests_set) {
957a57419b3SSteven Rostedt		    die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
958a57419b3SSteven Rostedt		}
959a57419b3SSteven Rostedt
9600050b6bbSSteven Rostedt		$old_test_num = $test_num;
9610050b6bbSSteven Rostedt		$old_repeat = $repeat;
962a57419b3SSteven Rostedt
963a57419b3SSteven Rostedt		$test_num += $repeat;
964a57419b3SSteven Rostedt		$default = 0;
965a57419b3SSteven Rostedt		$repeat = 1;
9660050b6bbSSteven Rostedt	    } else {
9670050b6bbSSteven Rostedt		$default = 1;
9680050b6bbSSteven Rostedt	    }
969a57419b3SSteven Rostedt
970a9f84424SSteven Rostedt	    # If SKIP is anywhere in the line, the command will be skipped
971a9f84424SSteven Rostedt	    if ($rest =~ s/\s+SKIP\b//) {
972a57419b3SSteven Rostedt		$skip = 1;
973a57419b3SSteven Rostedt	    } else {
9740df213caSSteven Rostedt		$test_case = 1;
975a57419b3SSteven Rostedt		$skip = 0;
976a57419b3SSteven Rostedt	    }
977a57419b3SSteven Rostedt
978a9f84424SSteven Rostedt	    if ($rest =~ s/\sELSE\b//) {
979a9f84424SSteven Rostedt		if (!$if) {
980a9f84424SSteven Rostedt		    die "$name: $.: ELSE found with out matching IF section\n$_";
981a57419b3SSteven Rostedt		}
982a9f84424SSteven Rostedt		$if = 0;
983a9f84424SSteven Rostedt
984a9f84424SSteven Rostedt		if ($if_set) {
985a9f84424SSteven Rostedt		    $skip = 1;
986a9f84424SSteven Rostedt		} else {
987a9f84424SSteven Rostedt		    $skip = 0;
9883d1cc414SSteven Rostedt		}
9893d1cc414SSteven Rostedt	    }
990a57419b3SSteven Rostedt
991a9f84424SSteven Rostedt	    if ($rest =~ s/\sIF\s+(.*)//) {
99245d73a5dSSteven Rostedt		if (process_if($name, $1)) {
99345d73a5dSSteven Rostedt		    $if_set = 1;
99445d73a5dSSteven Rostedt		} else {
995a57419b3SSteven Rostedt		    $skip = 1;
996a57419b3SSteven Rostedt		}
99745d73a5dSSteven Rostedt		$if = 1;
99845d73a5dSSteven Rostedt	    } else {
99945d73a5dSSteven Rostedt		$if = 0;
1000a9f84424SSteven Rostedt		$if_set = 0;
100145d73a5dSSteven Rostedt	    }
1002a57419b3SSteven Rostedt
1003a9f84424SSteven Rostedt	    if (!$skip) {
1004a9f84424SSteven Rostedt		if ($type eq "TEST_START") {
1005a9f84424SSteven Rostedt		    if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
1006a9f84424SSteven Rostedt			$repeat = $1;
1007a9f84424SSteven Rostedt			$repeat_tests{"$test_num"} = $repeat;
1008a9f84424SSteven Rostedt		    }
1009a9f84424SSteven Rostedt		} elsif ($rest =~ s/\sOVERRIDE\b//) {
1010a9f84424SSteven Rostedt		    # DEFAULT only
1011a9f84424SSteven Rostedt		    $override = 1;
1012a9f84424SSteven Rostedt		    # Clear previous overrides
1013a9f84424SSteven Rostedt		    %overrides = ();
1014a9f84424SSteven Rostedt		}
1015a9f84424SSteven Rostedt	    }
1016a9f84424SSteven Rostedt
1017a9f84424SSteven Rostedt	    if (!$skip && $rest !~ /^\s*$/) {
10180050b6bbSSteven Rostedt		die "$name: $.: Gargbage found after $type\n$_";
1019a57419b3SSteven Rostedt	    }
1020a57419b3SSteven Rostedt
10210050b6bbSSteven Rostedt	    if ($skip && $type eq "TEST_START") {
1022a57419b3SSteven Rostedt		$test_num = $old_test_num;
1023e48c5293SSteven Rostedt		$repeat = $old_repeat;
1024a57419b3SSteven Rostedt	    }
1025a57419b3SSteven Rostedt
1026ab7a3f52SSteven Rostedt	} elsif (/^\s*ELSE\b(.*)$/) {
102745d73a5dSSteven Rostedt	    if (!$if) {
102845d73a5dSSteven Rostedt		die "$name: $.: ELSE found with out matching IF section\n$_";
102945d73a5dSSteven Rostedt	    }
103045d73a5dSSteven Rostedt	    $rest = $1;
103145d73a5dSSteven Rostedt	    if ($if_set) {
103245d73a5dSSteven Rostedt		$skip = 1;
1033ab7a3f52SSteven Rostedt		$rest = "";
103445d73a5dSSteven Rostedt	    } else {
103545d73a5dSSteven Rostedt		$skip = 0;
103645d73a5dSSteven Rostedt
1037ab7a3f52SSteven Rostedt		if ($rest =~ /\sIF\s+(.*)/) {
103845d73a5dSSteven Rostedt		    # May be a ELSE IF section.
103995f57838SSteven Rostedt		    if (process_if($name, $1)) {
104095f57838SSteven Rostedt			$if_set = 1;
104195f57838SSteven Rostedt		    } else {
104245d73a5dSSteven Rostedt			$skip = 1;
104345d73a5dSSteven Rostedt		    }
1044ab7a3f52SSteven Rostedt		    $rest = "";
104545d73a5dSSteven Rostedt		} else {
104645d73a5dSSteven Rostedt		    $if = 0;
104745d73a5dSSteven Rostedt		}
104845d73a5dSSteven Rostedt	    }
104945d73a5dSSteven Rostedt
1050ab7a3f52SSteven Rostedt	    if ($rest !~ /^\s*$/) {
1051ab7a3f52SSteven Rostedt		die "$name: $.: Gargbage found after DEFAULTS\n$_";
1052ab7a3f52SSteven Rostedt	    }
1053ab7a3f52SSteven Rostedt
10542ed3b161SSteven Rostedt	} elsif (/^\s*INCLUDE\s+(\S+)/) {
10552ed3b161SSteven Rostedt
10562ed3b161SSteven Rostedt	    next if ($skip);
10572ed3b161SSteven Rostedt
10582ed3b161SSteven Rostedt	    if (!$default) {
10592ed3b161SSteven Rostedt		die "$name: $.: INCLUDE can only be done in default sections\n$_";
10602ed3b161SSteven Rostedt	    }
10612ed3b161SSteven Rostedt
10622ed3b161SSteven Rostedt	    my $file = process_variables($1);
10632ed3b161SSteven Rostedt
10642ed3b161SSteven Rostedt	    if ($file !~ m,^/,) {
10652ed3b161SSteven Rostedt		# check the path of the config file first
10662ed3b161SSteven Rostedt		if ($config =~ m,(.*)/,) {
10672ed3b161SSteven Rostedt		    if (-f "$1/$file") {
10682ed3b161SSteven Rostedt			$file = "$1/$file";
10692ed3b161SSteven Rostedt		    }
10702ed3b161SSteven Rostedt		}
10712ed3b161SSteven Rostedt	    }
10722ed3b161SSteven Rostedt
10732ed3b161SSteven Rostedt	    if ( ! -r $file ) {
10742ed3b161SSteven Rostedt		die "$name: $.: Can't read file $file\n$_";
10752ed3b161SSteven Rostedt	    }
10762ed3b161SSteven Rostedt
10772ed3b161SSteven Rostedt	    if (__read_config($file, \$test_num)) {
10782ed3b161SSteven Rostedt		$test_case = 1;
10792ed3b161SSteven Rostedt	    }
10802ed3b161SSteven Rostedt
1081c75d22d9SSteven Rostedt (Red Hat)	} elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
1082c75d22d9SSteven Rostedt (Red Hat)
1083c75d22d9SSteven Rostedt (Red Hat)	    next if ($skip);
1084c75d22d9SSteven Rostedt (Red Hat)
1085c75d22d9SSteven Rostedt (Red Hat)	    my $lvalue = $1;
1086c75d22d9SSteven Rostedt (Red Hat)	    my $rvalue = $2;
1087c75d22d9SSteven Rostedt (Red Hat)
1088c75d22d9SSteven Rostedt (Red Hat)	    if ($default || $lvalue =~ /\[\d+\]$/) {
1089c75d22d9SSteven Rostedt (Red Hat)		set_eval($lvalue, $rvalue, $name);
1090c75d22d9SSteven Rostedt (Red Hat)	    } else {
1091c75d22d9SSteven Rostedt (Red Hat)		my $val = "$lvalue\[$test_num\]";
1092c75d22d9SSteven Rostedt (Red Hat)		set_eval($val, $rvalue, $name);
1093c75d22d9SSteven Rostedt (Red Hat)	    }
1094c75d22d9SSteven Rostedt (Red Hat)
1095a57419b3SSteven Rostedt	} elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1096a57419b3SSteven Rostedt
1097a57419b3SSteven Rostedt	    next if ($skip);
1098a57419b3SSteven Rostedt
1099a57419b3SSteven Rostedt	    my $lvalue = $1;
1100a57419b3SSteven Rostedt	    my $rvalue = $2;
1101a57419b3SSteven Rostedt
1102a57419b3SSteven Rostedt	    if (!$default &&
1103a57419b3SSteven Rostedt		($lvalue eq "NUM_TESTS" ||
1104a57419b3SSteven Rostedt		 $lvalue eq "LOG_FILE" ||
1105a57419b3SSteven Rostedt		 $lvalue eq "CLEAR_LOG")) {
1106a57419b3SSteven Rostedt		die "$name: $.: $lvalue must be set in DEFAULTS section\n";
1107a57419b3SSteven Rostedt	    }
1108a57419b3SSteven Rostedt
1109a57419b3SSteven Rostedt	    if ($lvalue eq "NUM_TESTS") {
1110a57419b3SSteven Rostedt		if ($test_num) {
1111a57419b3SSteven Rostedt		    die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
1112a57419b3SSteven Rostedt		}
1113a57419b3SSteven Rostedt		if (!$default) {
1114a57419b3SSteven Rostedt		    die "$name: $.: NUM_TESTS must be set in default section\n";
1115a57419b3SSteven Rostedt		}
1116a57419b3SSteven Rostedt		$num_tests_set = 1;
1117a57419b3SSteven Rostedt	    }
1118a57419b3SSteven Rostedt
1119a57419b3SSteven Rostedt	    if ($default || $lvalue =~ /\[\d+\]$/) {
11203d1cc414SSteven Rostedt		set_value($lvalue, $rvalue, $override, \%overrides, $name);
1121a57419b3SSteven Rostedt	    } else {
1122a57419b3SSteven Rostedt		my $val = "$lvalue\[$test_num\]";
11233d1cc414SSteven Rostedt		set_value($val, $rvalue, $override, \%overrides, $name);
1124a57419b3SSteven Rostedt
1125a57419b3SSteven Rostedt		if ($repeat > 1) {
1126a57419b3SSteven Rostedt		    $repeats{$val} = $repeat;
1127a57419b3SSteven Rostedt		}
1128a57419b3SSteven Rostedt	    }
112977d942ceSSteven Rostedt	} elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
113077d942ceSSteven Rostedt	    next if ($skip);
113177d942ceSSteven Rostedt
113277d942ceSSteven Rostedt	    my $lvalue = $1;
113377d942ceSSteven Rostedt	    my $rvalue = $2;
113477d942ceSSteven Rostedt
113577d942ceSSteven Rostedt	    # process config variables.
113677d942ceSSteven Rostedt	    # Config variables are only active while reading the
113777d942ceSSteven Rostedt	    # config and can be defined anywhere. They also ignore
113877d942ceSSteven Rostedt	    # TEST_START and DEFAULTS, but are skipped if they are in
113977d942ceSSteven Rostedt	    # on of these sections that have SKIP defined.
114077d942ceSSteven Rostedt	    # The save variable can be
114177d942ceSSteven Rostedt	    # defined multiple times and the new one simply overrides
114277d942ceSSteven Rostedt	    # the prevous one.
114377d942ceSSteven Rostedt	    set_variable($lvalue, $rvalue);
114477d942ceSSteven Rostedt
1145a57419b3SSteven Rostedt	} else {
1146a57419b3SSteven Rostedt	    die "$name: $.: Garbage found in config\n$_";
1147a57419b3SSteven Rostedt	}
11482545eb61SSteven Rostedt    }
11492545eb61SSteven Rostedt
1150a57419b3SSteven Rostedt    if ($test_num) {
1151a57419b3SSteven Rostedt	$test_num += $repeat - 1;
1152a57419b3SSteven Rostedt	$opt{"NUM_TESTS"} = $test_num;
1153a57419b3SSteven Rostedt    }
1154a57419b3SSteven Rostedt
11552ed3b161SSteven Rostedt    close($in);
11562ed3b161SSteven Rostedt
11572ed3b161SSteven Rostedt    $$current_test_num = $test_num;
11582ed3b161SSteven Rostedt
11592ed3b161SSteven Rostedt    return $test_case;
11602ed3b161SSteven Rostedt}
11612ed3b161SSteven Rostedt
1162c4261d0fSSteven Rostedtsub get_test_case {
1163c4261d0fSSteven Rostedt	print "What test case would you like to run?\n";
1164c4261d0fSSteven Rostedt	print " (build, install or boot)\n";
1165edbd0edeSScott Wood	print " Other tests are available but require editing ktest.conf\n";
1166edbd0edeSScott Wood	print " (see tools/testing/ktest/sample.conf)\n";
1167c4261d0fSSteven Rostedt	my $ans = <STDIN>;
1168c4261d0fSSteven Rostedt	chomp $ans;
1169c4261d0fSSteven Rostedt	$default{"TEST_TYPE"} = $ans;
1170c4261d0fSSteven Rostedt}
1171c4261d0fSSteven Rostedt
11722ed3b161SSteven Rostedtsub read_config {
11732ed3b161SSteven Rostedt    my ($config) = @_;
11742ed3b161SSteven Rostedt
11752ed3b161SSteven Rostedt    my $test_case;
11762ed3b161SSteven Rostedt    my $test_num = 0;
11772ed3b161SSteven Rostedt
11782ed3b161SSteven Rostedt    $test_case = __read_config $config, \$test_num;
11792ed3b161SSteven Rostedt
11808d1491baSSteven Rostedt    # make sure we have all mandatory configs
11815269faadSSatoru Takeuchi    get_mandatory_configs;
11828d1491baSSteven Rostedt
11830df213caSSteven Rostedt    # was a test specified?
11840df213caSSteven Rostedt    if (!$test_case) {
11850df213caSSteven Rostedt	print "No test case specified.\n";
1186c4261d0fSSteven Rostedt	get_test_case;
11870df213caSSteven Rostedt    }
11880df213caSSteven Rostedt
1189a75fececSSteven Rostedt    # set any defaults
1190a75fececSSteven Rostedt
1191a75fececSSteven Rostedt    foreach my $default (keys %default) {
1192a75fececSSteven Rostedt	if (!defined($opt{$default})) {
1193a75fececSSteven Rostedt	    $opt{$default} = $default{$default};
1194a75fececSSteven Rostedt	}
1195a75fececSSteven Rostedt    }
11969cc9e091SSteven Rostedt
11979cc9e091SSteven Rostedt    if ($opt{"IGNORE_UNUSED"} == 1) {
11989cc9e091SSteven Rostedt	return;
11999cc9e091SSteven Rostedt    }
12009cc9e091SSteven Rostedt
12019cc9e091SSteven Rostedt    my %not_used;
12029cc9e091SSteven Rostedt
12039cc9e091SSteven Rostedt    # check if there are any stragglers (typos?)
12049cc9e091SSteven Rostedt    foreach my $option (keys %opt) {
12059cc9e091SSteven Rostedt	my $op = $option;
12069cc9e091SSteven Rostedt	# remove per test labels.
12079cc9e091SSteven Rostedt	$op =~ s/\[.*\]//;
12089cc9e091SSteven Rostedt	if (!exists($option_map{$op}) &&
12099cc9e091SSteven Rostedt	    !exists($default{$op}) &&
12109cc9e091SSteven Rostedt	    !exists($used_options{$op})) {
12119cc9e091SSteven Rostedt	    $not_used{$op} = 1;
12129cc9e091SSteven Rostedt	}
12139cc9e091SSteven Rostedt    }
12149cc9e091SSteven Rostedt
12159cc9e091SSteven Rostedt    if (%not_used) {
12169cc9e091SSteven Rostedt	my $s = "s are";
12179cc9e091SSteven Rostedt	$s = " is" if (keys %not_used == 1);
12189cc9e091SSteven Rostedt	print "The following option$s not used; could be a typo:\n";
12199cc9e091SSteven Rostedt	foreach my $option (keys %not_used) {
12209cc9e091SSteven Rostedt	    print "$option\n";
12219cc9e091SSteven Rostedt	}
12229cc9e091SSteven Rostedt	print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
12239cc9e091SSteven Rostedt	if (!read_yn "Do you want to continue?") {
12249cc9e091SSteven Rostedt	    exit -1;
12259cc9e091SSteven Rostedt	}
12269cc9e091SSteven Rostedt    }
12272545eb61SSteven Rostedt}
12282545eb61SSteven Rostedt
122923715c3cSSteven Rostedtsub __eval_option {
123004262be3SSteven Rostedt (Red Hat)    my ($name, $option, $i) = @_;
123123715c3cSSteven Rostedt
123223715c3cSSteven Rostedt    # Add space to evaluate the character before $
123323715c3cSSteven Rostedt    $option = " $option";
123423715c3cSSteven Rostedt    my $retval = "";
1235f9dfb65bSRabin Vincent    my $repeated = 0;
1236f9dfb65bSRabin Vincent    my $parent = 0;
1237f9dfb65bSRabin Vincent
1238f9dfb65bSRabin Vincent    foreach my $test (keys %repeat_tests) {
1239f9dfb65bSRabin Vincent	if ($i >= $test &&
1240f9dfb65bSRabin Vincent	    $i < $test + $repeat_tests{$test}) {
1241f9dfb65bSRabin Vincent
1242f9dfb65bSRabin Vincent	    $repeated = 1;
1243f9dfb65bSRabin Vincent	    $parent = $test;
1244f9dfb65bSRabin Vincent	    last;
1245f9dfb65bSRabin Vincent	}
1246f9dfb65bSRabin Vincent    }
124723715c3cSSteven Rostedt
124823715c3cSSteven Rostedt    while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
124923715c3cSSteven Rostedt	my $start = $1;
125023715c3cSSteven Rostedt	my $var = $2;
125123715c3cSSteven Rostedt	my $end = $3;
125223715c3cSSteven Rostedt
125323715c3cSSteven Rostedt	# Append beginning of line
125423715c3cSSteven Rostedt	$retval = "$retval$start";
125523715c3cSSteven Rostedt
125623715c3cSSteven Rostedt	# If the iteration option OPT[$i] exists, then use that.
125723715c3cSSteven Rostedt	# otherwise see if the default OPT (without [$i]) exists.
125823715c3cSSteven Rostedt
125923715c3cSSteven Rostedt	my $o = "$var\[$i\]";
1260f9dfb65bSRabin Vincent	my $parento = "$var\[$parent\]";
126123715c3cSSteven Rostedt
126204262be3SSteven Rostedt (Red Hat)	# If a variable contains itself, use the default var
126304262be3SSteven Rostedt (Red Hat)	if (($var eq $name) && defined($opt{$var})) {
126404262be3SSteven Rostedt (Red Hat)	    $o = $opt{$var};
126504262be3SSteven Rostedt (Red Hat)	    $retval = "$retval$o";
126604262be3SSteven Rostedt (Red Hat)	} elsif (defined($opt{$o})) {
126723715c3cSSteven Rostedt	    $o = $opt{$o};
126823715c3cSSteven Rostedt	    $retval = "$retval$o";
1269f9dfb65bSRabin Vincent	} elsif ($repeated && defined($opt{$parento})) {
1270f9dfb65bSRabin Vincent	    $o = $opt{$parento};
1271f9dfb65bSRabin Vincent	    $retval = "$retval$o";
127223715c3cSSteven Rostedt	} elsif (defined($opt{$var})) {
127323715c3cSSteven Rostedt	    $o = $opt{$var};
127423715c3cSSteven Rostedt	    $retval = "$retval$o";
12758e80bf05SSteven Rostedt (Red Hat)	} elsif ($var eq "KERNEL_VERSION" && defined($make)) {
12768e80bf05SSteven Rostedt (Red Hat)	    # special option KERNEL_VERSION uses kernel version
12778e80bf05SSteven Rostedt (Red Hat)	    get_version();
12788e80bf05SSteven Rostedt (Red Hat)	    $retval = "$retval$version";
127923715c3cSSteven Rostedt	} else {
128023715c3cSSteven Rostedt	    $retval = "$retval\$\{$var\}";
128123715c3cSSteven Rostedt	}
128223715c3cSSteven Rostedt
128323715c3cSSteven Rostedt	$option = $end;
128423715c3cSSteven Rostedt    }
128523715c3cSSteven Rostedt
128623715c3cSSteven Rostedt    $retval = "$retval$option";
128723715c3cSSteven Rostedt
128823715c3cSSteven Rostedt    $retval =~ s/^ //;
128923715c3cSSteven Rostedt
129023715c3cSSteven Rostedt    return $retval;
129123715c3cSSteven Rostedt}
129223715c3cSSteven Rostedt
1293c75d22d9SSteven Rostedt (Red Hat)sub process_evals {
1294c75d22d9SSteven Rostedt (Red Hat)    my ($name, $option, $i) = @_;
1295c75d22d9SSteven Rostedt (Red Hat)
1296c75d22d9SSteven Rostedt (Red Hat)    my $option_name = "$name\[$i\]";
1297c75d22d9SSteven Rostedt (Red Hat)    my $ev;
1298c75d22d9SSteven Rostedt (Red Hat)
1299c75d22d9SSteven Rostedt (Red Hat)    my $old_option = $option;
1300c75d22d9SSteven Rostedt (Red Hat)
1301c75d22d9SSteven Rostedt (Red Hat)    if (defined($evals{$option_name})) {
1302c75d22d9SSteven Rostedt (Red Hat)	$ev = $evals{$option_name};
1303c75d22d9SSteven Rostedt (Red Hat)    } elsif (defined($evals{$name})) {
1304c75d22d9SSteven Rostedt (Red Hat)	$ev = $evals{$name};
1305c75d22d9SSteven Rostedt (Red Hat)    } else {
1306c75d22d9SSteven Rostedt (Red Hat)	return $option;
1307c75d22d9SSteven Rostedt (Red Hat)    }
1308c75d22d9SSteven Rostedt (Red Hat)
1309c75d22d9SSteven Rostedt (Red Hat)    for my $e (@{$ev}) {
1310c75d22d9SSteven Rostedt (Red Hat)	eval "\$option =~ $e";
1311c75d22d9SSteven Rostedt (Red Hat)    }
1312c75d22d9SSteven Rostedt (Red Hat)
1313c75d22d9SSteven Rostedt (Red Hat)    if ($option ne $old_option) {
1314c75d22d9SSteven Rostedt (Red Hat)	doprint("$name changed from '$old_option' to '$option'\n");
1315c75d22d9SSteven Rostedt (Red Hat)    }
1316c75d22d9SSteven Rostedt (Red Hat)
1317c75d22d9SSteven Rostedt (Red Hat)    return $option;
1318c75d22d9SSteven Rostedt (Red Hat)}
1319c75d22d9SSteven Rostedt (Red Hat)
132023715c3cSSteven Rostedtsub eval_option {
132104262be3SSteven Rostedt (Red Hat)    my ($name, $option, $i) = @_;
132223715c3cSSteven Rostedt
132323715c3cSSteven Rostedt    my $prev = "";
132423715c3cSSteven Rostedt
132523715c3cSSteven Rostedt    # Since an option can evaluate to another option,
132623715c3cSSteven Rostedt    # keep iterating until we do not evaluate any more
132723715c3cSSteven Rostedt    # options.
132823715c3cSSteven Rostedt    my $r = 0;
132923715c3cSSteven Rostedt    while ($prev ne $option) {
133023715c3cSSteven Rostedt	# Check for recursive evaluations.
133123715c3cSSteven Rostedt	# 100 deep should be more than enough.
133223715c3cSSteven Rostedt	if ($r++ > 100) {
133323715c3cSSteven Rostedt	    die "Over 100 evaluations accurred with $option\n" .
133423715c3cSSteven Rostedt		"Check for recursive variables\n";
133523715c3cSSteven Rostedt	}
133623715c3cSSteven Rostedt	$prev = $option;
133704262be3SSteven Rostedt (Red Hat)	$option = __eval_option($name, $option, $i);
133823715c3cSSteven Rostedt    }
133923715c3cSSteven Rostedt
1340c75d22d9SSteven Rostedt (Red Hat)    $option = process_evals($name, $option, $i);
1341c75d22d9SSteven Rostedt (Red Hat)
134223715c3cSSteven Rostedt    return $option;
134323715c3cSSteven Rostedt}
134423715c3cSSteven Rostedt
13457faafbd6SSteven Rostedtsub run_command;
13462728be41SAndrew Jonessub start_monitor;
13472728be41SAndrew Jonessub end_monitor;
13482728be41SAndrew Jonessub wait_for_monitor;
13497faafbd6SSteven Rostedt
13507faafbd6SSteven Rostedtsub reboot {
13512728be41SAndrew Jones    my ($time) = @_;
13526474ace9SSteven Rostedt (VMware)    my $powercycle = 0;
13532728be41SAndrew Jones
13543e1d3678SSteven Rostedt (VMware)    # test if the machine can be connected to within a few seconds
13553e1d3678SSteven Rostedt (VMware)    my $stat = run_ssh("echo check machine status", $connect_timeout);
13566474ace9SSteven Rostedt (VMware)    if (!$stat) {
13576474ace9SSteven Rostedt (VMware)	doprint("power cycle\n");
13586474ace9SSteven Rostedt (VMware)	$powercycle = 1;
13596474ace9SSteven Rostedt (VMware)    }
13606474ace9SSteven Rostedt (VMware)
13616474ace9SSteven Rostedt (VMware)    if ($powercycle) {
13626474ace9SSteven Rostedt (VMware)	run_command "$power_cycle";
13636474ace9SSteven Rostedt (VMware)
13646474ace9SSteven Rostedt (VMware)	start_monitor;
13656474ace9SSteven Rostedt (VMware)	# flush out current monitor
13666474ace9SSteven Rostedt (VMware)	# May contain the reboot success line
13676474ace9SSteven Rostedt (VMware)	wait_for_monitor 1;
13686474ace9SSteven Rostedt (VMware)
13696474ace9SSteven Rostedt (VMware)    } else {
1370a4968722SSteven Rostedt	# Make sure everything has been written to disk
1371a4968722SSteven Rostedt	run_ssh("sync");
1372a4968722SSteven Rostedt
13732b803365SSteven Rostedt	if (defined($time)) {
13742b803365SSteven Rostedt	    start_monitor;
13752b803365SSteven Rostedt	    # flush out current monitor
13762b803365SSteven Rostedt	    # May contain the reboot success line
13772b803365SSteven Rostedt	    wait_for_monitor 1;
13782b803365SSteven Rostedt	}
13792b803365SSteven Rostedt
13807faafbd6SSteven Rostedt	# try to reboot normally
1381e48c5293SSteven Rostedt	if (run_command $reboot) {
1382576f627cSSteven Rostedt	    if (defined($powercycle_after_reboot)) {
1383576f627cSSteven Rostedt		sleep $powercycle_after_reboot;
1384576f627cSSteven Rostedt		run_command "$power_cycle";
1385576f627cSSteven Rostedt	    }
1386576f627cSSteven Rostedt	} else {
13877faafbd6SSteven Rostedt	    # nope? power cycle it.
1388a75fececSSteven Rostedt	    run_command "$power_cycle";
13897faafbd6SSteven Rostedt	}
13906474ace9SSteven Rostedt (VMware)    }
13912728be41SAndrew Jones
13922728be41SAndrew Jones    if (defined($time)) {
13934c0b67a2SSteven Rostedt (Red Hat)
13944c0b67a2SSteven Rostedt (Red Hat)	# We only want to get to the new kernel, don't fail
13954c0b67a2SSteven Rostedt (Red Hat)	# if we stumble over a call trace.
13964c0b67a2SSteven Rostedt (Red Hat)	my $save_ignore_errors = $ignore_errors;
13974c0b67a2SSteven Rostedt (Red Hat)	$ignore_errors = 1;
13984c0b67a2SSteven Rostedt (Red Hat)
1399d6845536SSteven Rostedt (Red Hat)	# Look for the good kernel to boot
1400d6845536SSteven Rostedt (Red Hat)	if (wait_for_monitor($time, "Linux version")) {
1401407b95b7SSteven Rostedt	    # reboot got stuck?
14028a80c727SSteven Rostedt	    doprint "Reboot did not finish. Forcing power cycle\n";
1403407b95b7SSteven Rostedt	    run_command "$power_cycle";
1404407b95b7SSteven Rostedt	}
1405d6845536SSteven Rostedt (Red Hat)
14064c0b67a2SSteven Rostedt (Red Hat)	$ignore_errors = $save_ignore_errors;
14074c0b67a2SSteven Rostedt (Red Hat)
1408d6845536SSteven Rostedt (Red Hat)	# Still need to wait for the reboot to finish
1409d6845536SSteven Rostedt (Red Hat)	wait_for_monitor($time, $reboot_success_line);
1410d6845536SSteven Rostedt (Red Hat)
14112728be41SAndrew Jones	end_monitor;
14122728be41SAndrew Jones    }
14137faafbd6SSteven Rostedt}
14147faafbd6SSteven Rostedt
1415bc7c5803SSteven Rostedtsub reboot_to_good {
1416bc7c5803SSteven Rostedt    my ($time) = @_;
1417bc7c5803SSteven Rostedt
1418bc7c5803SSteven Rostedt    if (defined($switch_to_good)) {
1419bc7c5803SSteven Rostedt	run_command $switch_to_good;
1420bc7c5803SSteven Rostedt    }
1421bc7c5803SSteven Rostedt
1422bc7c5803SSteven Rostedt    reboot $time;
1423bc7c5803SSteven Rostedt}
1424bc7c5803SSteven Rostedt
1425576f627cSSteven Rostedtsub do_not_reboot {
1426576f627cSSteven Rostedt    my $i = $iteration;
1427576f627cSSteven Rostedt
14284ab1cce5SSteven Rostedt    return $test_type eq "build" || $no_reboot ||
1429576f627cSSteven Rostedt	($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1430649c0f12SScott Wood	($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build") ||
1431649c0f12SScott Wood	($test_type eq "config_bisect" && $opt{"CONFIG_BISECT_TYPE[$i]"} eq "build");
1432576f627cSSteven Rostedt}
1433576f627cSSteven Rostedt
14345c42fc5bSSteven Rostedtsub dodie {
14355a391fbfSSteven Rostedt    doprint "CRITICAL FAILURE... ", @_, "\n";
14365c42fc5bSSteven Rostedt
1437576f627cSSteven Rostedt    my $i = $iteration;
1438576f627cSSteven Rostedt
1439576f627cSSteven Rostedt    if ($reboot_on_error && !do_not_reboot) {
1440576f627cSSteven Rostedt
144175c3fda7SSteven Rostedt	doprint "REBOOTING\n";
1442bc7c5803SSteven Rostedt	reboot_to_good;
144375c3fda7SSteven Rostedt
1444a75fececSSteven Rostedt    } elsif ($poweroff_on_error && defined($power_off)) {
14455c42fc5bSSteven Rostedt	doprint "POWERING OFF\n";
1446a75fececSSteven Rostedt	`$power_off`;
14475c42fc5bSSteven Rostedt    }
144875c3fda7SSteven Rostedt
1449f80802cbSSteven Rostedt    if (defined($opt{"LOG_FILE"})) {
1450f80802cbSSteven Rostedt	print " See $opt{LOG_FILE} for more info.\n";
1451f80802cbSSteven Rostedt    }
1452f80802cbSSteven Rostedt
1453*2ceb2d85STim Tianyang Chen    if ($email_on_error) {
1454*2ceb2d85STim Tianyang Chen        send_email("KTEST: critical failure for your [$test_type] test",
1455*2ceb2d85STim Tianyang Chen                "Your test started at $script_start_time has failed with:\n@_\n");
1456*2ceb2d85STim Tianyang Chen    }
1457*2ceb2d85STim Tianyang Chen
14581cb9e642SJosh Poimboeuf    if ($monitor_cnt) {
14591cb9e642SJosh Poimboeuf	    # restore terminal settings
14601cb9e642SJosh Poimboeuf	    system("stty $stty_orig");
14611cb9e642SJosh Poimboeuf    }
14621cb9e642SJosh Poimboeuf
14632e07c9f5SSteven Rostedt (VMware)    if (defined($post_test)) {
14642e07c9f5SSteven Rostedt (VMware)	run_command $post_test;
14652e07c9f5SSteven Rostedt (VMware)    }
14662e07c9f5SSteven Rostedt (VMware)
1467576f627cSSteven Rostedt    die @_, "\n";
14685c42fc5bSSteven Rostedt}
14695c42fc5bSSteven Rostedt
14709f2cdcbbSJosh Poimboeufsub create_pty {
14719f2cdcbbSJosh Poimboeuf    my ($ptm, $pts) = @_;
14729f2cdcbbSJosh Poimboeuf    my $tmp;
14739f2cdcbbSJosh Poimboeuf    my $TIOCSPTLCK = 0x40045431;
14749f2cdcbbSJosh Poimboeuf    my $TIOCGPTN = 0x80045430;
14757faafbd6SSteven Rostedt
14769f2cdcbbSJosh Poimboeuf    sysopen($ptm, "/dev/ptmx", O_RDWR | O_NONBLOCK) or
14779f2cdcbbSJosh Poimboeuf	dodie "Cant open /dev/ptmx";
14789f2cdcbbSJosh Poimboeuf
14799f2cdcbbSJosh Poimboeuf    # unlockpt()
14809f2cdcbbSJosh Poimboeuf    $tmp = pack("i", 0);
14819f2cdcbbSJosh Poimboeuf    ioctl($ptm, $TIOCSPTLCK, $tmp) or
14829f2cdcbbSJosh Poimboeuf	dodie "ioctl TIOCSPTLCK for /dev/ptmx failed";
14839f2cdcbbSJosh Poimboeuf
14849f2cdcbbSJosh Poimboeuf    # ptsname()
14859f2cdcbbSJosh Poimboeuf    ioctl($ptm, $TIOCGPTN, $tmp) or
14869f2cdcbbSJosh Poimboeuf	dodie "ioctl TIOCGPTN for /dev/ptmx failed";
14879f2cdcbbSJosh Poimboeuf    $tmp = unpack("i", $tmp);
14889f2cdcbbSJosh Poimboeuf
14899f2cdcbbSJosh Poimboeuf    sysopen($pts, "/dev/pts/$tmp", O_RDWR | O_NONBLOCK) or
14909f2cdcbbSJosh Poimboeuf	dodie "Can't open /dev/pts/$tmp";
14919f2cdcbbSJosh Poimboeuf}
14929f2cdcbbSJosh Poimboeuf
14939f2cdcbbSJosh Poimboeufsub exec_console {
14949f2cdcbbSJosh Poimboeuf    my ($ptm, $pts) = @_;
14959f2cdcbbSJosh Poimboeuf
14969f2cdcbbSJosh Poimboeuf    close($ptm);
14979f2cdcbbSJosh Poimboeuf
14989f2cdcbbSJosh Poimboeuf    close(\*STDIN);
14999f2cdcbbSJosh Poimboeuf    close(\*STDOUT);
15009f2cdcbbSJosh Poimboeuf    close(\*STDERR);
15019f2cdcbbSJosh Poimboeuf
15029f2cdcbbSJosh Poimboeuf    open(\*STDIN, '<&', $pts);
15039f2cdcbbSJosh Poimboeuf    open(\*STDOUT, '>&', $pts);
15049f2cdcbbSJosh Poimboeuf    open(\*STDERR, '>&', $pts);
15059f2cdcbbSJosh Poimboeuf
15069f2cdcbbSJosh Poimboeuf    close($pts);
15079f2cdcbbSJosh Poimboeuf
15089f2cdcbbSJosh Poimboeuf    exec $console or
15091cb9e642SJosh Poimboeuf	die "Can't open console $console";
15109f2cdcbbSJosh Poimboeuf}
15119f2cdcbbSJosh Poimboeuf
15129f2cdcbbSJosh Poimboeufsub open_console {
15139f2cdcbbSJosh Poimboeuf    my ($ptm) = @_;
15149f2cdcbbSJosh Poimboeuf    my $pts = \*PTSFD;
15159f2cdcbbSJosh Poimboeuf    my $pid;
15167faafbd6SSteven Rostedt
151798842782SJosh Poimboeuf    # save terminal settings
15189d2f7f05SJosh Poimboeuf    $stty_orig = `stty -g`;
15199d2f7f05SJosh Poimboeuf
15209d2f7f05SJosh Poimboeuf    # place terminal in cbreak mode so that stdin can be read one character at
15219d2f7f05SJosh Poimboeuf    # a time without having to wait for a newline
15229d2f7f05SJosh Poimboeuf    system("stty -icanon -echo -icrnl");
152398842782SJosh Poimboeuf
15249f2cdcbbSJosh Poimboeuf    create_pty($ptm, $pts);
15257faafbd6SSteven Rostedt
15269f2cdcbbSJosh Poimboeuf    $pid = fork;
15279f2cdcbbSJosh Poimboeuf
15289f2cdcbbSJosh Poimboeuf    if (!$pid) {
15299f2cdcbbSJosh Poimboeuf	# child
15309f2cdcbbSJosh Poimboeuf	exec_console($ptm, $pts)
15319f2cdcbbSJosh Poimboeuf    }
15329f2cdcbbSJosh Poimboeuf
15339f2cdcbbSJosh Poimboeuf    # parent
15349f2cdcbbSJosh Poimboeuf    close($pts);
15357faafbd6SSteven Rostedt
15367faafbd6SSteven Rostedt    return $pid;
15379f2cdcbbSJosh Poimboeuf
15389f2cdcbbSJosh Poimboeuf    open(PTSFD, "Stop perl from warning about single use of PTSFD");
15397faafbd6SSteven Rostedt}
15407faafbd6SSteven Rostedt
15417faafbd6SSteven Rostedtsub close_console {
15427faafbd6SSteven Rostedt    my ($fp, $pid) = @_;
15437faafbd6SSteven Rostedt
15447faafbd6SSteven Rostedt    doprint "kill child process $pid\n";
15455a5d8e48SSatoru Takeuchi    kill $close_console_signal, $pid;
15467faafbd6SSteven Rostedt
15479f23b129SSteven Rostedt (VMware)    doprint "wait for child process $pid to exit\n";
15489f23b129SSteven Rostedt (VMware)    waitpid($pid, 0);
15499f23b129SSteven Rostedt (VMware)
15507faafbd6SSteven Rostedt    print "closing!\n";
15517faafbd6SSteven Rostedt    close($fp);
155298842782SJosh Poimboeuf
155398842782SJosh Poimboeuf    # restore terminal settings
15549d2f7f05SJosh Poimboeuf    system("stty $stty_orig");
15557faafbd6SSteven Rostedt}
15567faafbd6SSteven Rostedt
15577faafbd6SSteven Rostedtsub start_monitor {
15587faafbd6SSteven Rostedt    if ($monitor_cnt++) {
15597faafbd6SSteven Rostedt	return;
15607faafbd6SSteven Rostedt    }
15617faafbd6SSteven Rostedt    $monitor_fp = \*MONFD;
15627faafbd6SSteven Rostedt    $monitor_pid = open_console $monitor_fp;
1563a75fececSSteven Rostedt
1564a75fececSSteven Rostedt    return;
1565a75fececSSteven Rostedt
1566a75fececSSteven Rostedt    open(MONFD, "Stop perl from warning about single use of MONFD");
15677faafbd6SSteven Rostedt}
15687faafbd6SSteven Rostedt
15697faafbd6SSteven Rostedtsub end_monitor {
1570319ab14fSSteven Rostedt (Red Hat)    return if (!defined $console);
15717faafbd6SSteven Rostedt    if (--$monitor_cnt) {
15727faafbd6SSteven Rostedt	return;
15737faafbd6SSteven Rostedt    }
15747faafbd6SSteven Rostedt    close_console($monitor_fp, $monitor_pid);
15757faafbd6SSteven Rostedt}
15767faafbd6SSteven Rostedt
15777faafbd6SSteven Rostedtsub wait_for_monitor {
15782b803365SSteven Rostedt    my ($time, $stop) = @_;
15792b803365SSteven Rostedt    my $full_line = "";
15807faafbd6SSteven Rostedt    my $line;
15812b803365SSteven Rostedt    my $booted = 0;
1582407b95b7SSteven Rostedt    my $start_time = time;
15838a80c727SSteven Rostedt    my $skip_call_trace = 0;
15848a80c727SSteven Rostedt    my $bug = 0;
15858a80c727SSteven Rostedt    my $bug_ignored = 0;
1586407b95b7SSteven Rostedt    my $now;
15877faafbd6SSteven Rostedt
1588a75fececSSteven Rostedt    doprint "** Wait for monitor to settle down **\n";
15897faafbd6SSteven Rostedt
15907faafbd6SSteven Rostedt    # read the monitor and wait for the system to calm down
15912b803365SSteven Rostedt    while (!$booted) {
15927faafbd6SSteven Rostedt	$line = wait_for_input($monitor_fp, $time);
15932b803365SSteven Rostedt	last if (!defined($line));
15942b803365SSteven Rostedt	print "$line";
15952b803365SSteven Rostedt	$full_line .= $line;
15962b803365SSteven Rostedt
15972b803365SSteven Rostedt	if (defined($stop) && $full_line =~ /$stop/) {
15982b803365SSteven Rostedt	    doprint "wait for monitor detected $stop\n";
15992b803365SSteven Rostedt	    $booted = 1;
16002b803365SSteven Rostedt	}
16012b803365SSteven Rostedt
16028a80c727SSteven Rostedt	if ($full_line =~ /\[ backtrace testing \]/) {
16038a80c727SSteven Rostedt	    $skip_call_trace = 1;
16048a80c727SSteven Rostedt	}
16058a80c727SSteven Rostedt
16068a80c727SSteven Rostedt	if ($full_line =~ /call trace:/i) {
16078a80c727SSteven Rostedt	    if (!$bug && !$skip_call_trace) {
16088a80c727SSteven Rostedt		if ($ignore_errors) {
16098a80c727SSteven Rostedt		    $bug_ignored = 1;
16108a80c727SSteven Rostedt		} else {
16118a80c727SSteven Rostedt		    $bug = 1;
16128a80c727SSteven Rostedt		}
16138a80c727SSteven Rostedt	    }
16148a80c727SSteven Rostedt	}
16158a80c727SSteven Rostedt
16168a80c727SSteven Rostedt	if ($full_line =~ /\[ end of backtrace testing \]/) {
16178a80c727SSteven Rostedt	    $skip_call_trace = 0;
16188a80c727SSteven Rostedt	}
16198a80c727SSteven Rostedt
16208a80c727SSteven Rostedt	if ($full_line =~ /Kernel panic -/) {
16218a80c727SSteven Rostedt	    $bug = 1;
16228a80c727SSteven Rostedt	}
16238a80c727SSteven Rostedt
16242b803365SSteven Rostedt	if ($line =~ /\n/) {
16252b803365SSteven Rostedt	    $full_line = "";
16262b803365SSteven Rostedt	}
1627407b95b7SSteven Rostedt	$now = time;
1628407b95b7SSteven Rostedt	if ($now - $start_time >= $max_monitor_wait) {
1629407b95b7SSteven Rostedt	    doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1630407b95b7SSteven Rostedt	    return 1;
1631407b95b7SSteven Rostedt	}
16322b803365SSteven Rostedt    }
1633a75fececSSteven Rostedt    print "** Monitor flushed **\n";
1634995bc431SSteven Rostedt (Red Hat)
1635995bc431SSteven Rostedt (Red Hat)    # if stop is defined but wasn't hit, return error
1636995bc431SSteven Rostedt (Red Hat)    # used by reboot (which wants to see a reboot)
1637995bc431SSteven Rostedt (Red Hat)    if (defined($stop) && !$booted) {
1638995bc431SSteven Rostedt (Red Hat)	$bug = 1;
1639995bc431SSteven Rostedt (Red Hat)    }
16408a80c727SSteven Rostedt    return $bug;
16417faafbd6SSteven Rostedt}
16427faafbd6SSteven Rostedt
1643de5b6e3bSRabin Vincentsub save_logs {
1644de5b6e3bSRabin Vincent	my ($result, $basedir) = @_;
1645de5b6e3bSRabin Vincent	my @t = localtime;
1646de5b6e3bSRabin Vincent	my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1647de5b6e3bSRabin Vincent		1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1648de5b6e3bSRabin Vincent
1649de5b6e3bSRabin Vincent	my $type = $build_type;
1650de5b6e3bSRabin Vincent	if ($type =~ /useconfig/) {
1651de5b6e3bSRabin Vincent	    $type = "useconfig";
1652de5b6e3bSRabin Vincent	}
1653de5b6e3bSRabin Vincent
1654de5b6e3bSRabin Vincent	my $dir = "$machine-$test_type-$type-$result-$date";
1655de5b6e3bSRabin Vincent
1656de5b6e3bSRabin Vincent	$dir = "$basedir/$dir";
1657de5b6e3bSRabin Vincent
1658de5b6e3bSRabin Vincent	if (!-d $dir) {
1659de5b6e3bSRabin Vincent	    mkpath($dir) or
1660de5b6e3bSRabin Vincent		die "can't create $dir";
1661de5b6e3bSRabin Vincent	}
1662de5b6e3bSRabin Vincent
1663de5b6e3bSRabin Vincent	my %files = (
1664de5b6e3bSRabin Vincent		"config" => $output_config,
1665de5b6e3bSRabin Vincent		"buildlog" => $buildlog,
1666de5b6e3bSRabin Vincent		"dmesg" => $dmesg,
1667de5b6e3bSRabin Vincent		"testlog" => $testlog,
1668de5b6e3bSRabin Vincent	);
1669de5b6e3bSRabin Vincent
1670de5b6e3bSRabin Vincent	while (my ($name, $source) = each(%files)) {
1671de5b6e3bSRabin Vincent		if (-f "$source") {
1672de5b6e3bSRabin Vincent			cp "$source", "$dir/$name" or
1673de5b6e3bSRabin Vincent				die "failed to copy $source";
1674de5b6e3bSRabin Vincent		}
1675de5b6e3bSRabin Vincent	}
1676de5b6e3bSRabin Vincent
1677de5b6e3bSRabin Vincent	doprint "*** Saved info to $dir ***\n";
1678de5b6e3bSRabin Vincent}
1679de5b6e3bSRabin Vincent
16802b7d9b21SSteven Rostedtsub fail {
16812b7d9b21SSteven Rostedt
1682a75fececSSteven Rostedt	if ($die_on_failure) {
16832b7d9b21SSteven Rostedt		dodie @_;
16842b7d9b21SSteven Rostedt	}
16852b7d9b21SSteven Rostedt
1686a75fececSSteven Rostedt	doprint "FAILED\n";
16877faafbd6SSteven Rostedt
1688576f627cSSteven Rostedt	my $i = $iteration;
1689576f627cSSteven Rostedt
1690a75fececSSteven Rostedt	# no need to reboot for just building.
1691576f627cSSteven Rostedt	if (!do_not_reboot) {
16927faafbd6SSteven Rostedt	    doprint "REBOOTING\n";
1693bc7c5803SSteven Rostedt	    reboot_to_good $sleep_time;
1694a75fececSSteven Rostedt	}
16957faafbd6SSteven Rostedt
16969064af52SSteven Rostedt	my $name = "";
16979064af52SSteven Rostedt
16989064af52SSteven Rostedt	if (defined($test_name)) {
16999064af52SSteven Rostedt	    $name = " ($test_name)";
17009064af52SSteven Rostedt	}
17019064af52SSteven Rostedt
17024bf6e1fcSSteven Rostedt (Red Hat)	print_times;
17034bf6e1fcSSteven Rostedt (Red Hat)
1704576f627cSSteven Rostedt	doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1705576f627cSSteven Rostedt	doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
17069064af52SSteven Rostedt	doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1707576f627cSSteven Rostedt	doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1708576f627cSSteven Rostedt	doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1709a75fececSSteven Rostedt
1710de5b6e3bSRabin Vincent	if (defined($store_failures)) {
1711de5b6e3bSRabin Vincent	    save_logs "fail", $store_failures;
1712cccae1a6SSteven Rostedt        }
1713cccae1a6SSteven Rostedt
17142e07c9f5SSteven Rostedt (VMware)	if (defined($post_test)) {
17152e07c9f5SSteven Rostedt (VMware)		run_command $post_test;
17162e07c9f5SSteven Rostedt (VMware)	}
17172e07c9f5SSteven Rostedt (VMware)
17182b7d9b21SSteven Rostedt	return 1;
17192b7d9b21SSteven Rostedt}
17202b7d9b21SSteven Rostedt
17212545eb61SSteven Rostedtsub run_command {
17226e98d1b4SSteven Rostedt (VMware)    my ($command, $redirect, $timeout) = @_;
1723b53486e0SSteven Rostedt (Red Hat)    my $start_time;
1724b53486e0SSteven Rostedt (Red Hat)    my $end_time;
1725d6ce2a0bSSteven Rostedt    my $dolog = 0;
1726d6ce2a0bSSteven Rostedt    my $dord = 0;
1727b337f979SSteven Rostedt (VMware)    my $dostdout = 0;
1728d6ce2a0bSSteven Rostedt    my $pid;
1729d6ce2a0bSSteven Rostedt
1730e48c5293SSteven Rostedt    $command =~ s/\$SSH_USER/$ssh_user/g;
1731e48c5293SSteven Rostedt    $command =~ s/\$MACHINE/$machine/g;
1732e48c5293SSteven Rostedt
1733d6ce2a0bSSteven Rostedt    doprint("$command ... ");
17346e98d1b4SSteven Rostedt (VMware)    $start_time = time;
1735d6ce2a0bSSteven Rostedt
1736d6ce2a0bSSteven Rostedt    $pid = open(CMD, "$command 2>&1 |") or
17372b7d9b21SSteven Rostedt	(fail "unable to exec $command" and return 0);
17382545eb61SSteven Rostedt
17392545eb61SSteven Rostedt    if (defined($opt{"LOG_FILE"})) {
1740d6ce2a0bSSteven Rostedt	open(LOG, ">>$opt{LOG_FILE}") or
1741d6ce2a0bSSteven Rostedt	    dodie "failed to write to log";
1742d6ce2a0bSSteven Rostedt	$dolog = 1;
17436c5ee0beSSteven Rostedt    }
17446c5ee0beSSteven Rostedt
17456c5ee0beSSteven Rostedt    if (defined($redirect)) {
1746b337f979SSteven Rostedt (VMware)	if ($redirect eq 1) {
1747b337f979SSteven Rostedt (VMware)	    $dostdout = 1;
1748b337f979SSteven Rostedt (VMware)	    # Have the output of the command on its own line
1749b337f979SSteven Rostedt (VMware)	    doprint "\n";
1750b337f979SSteven Rostedt (VMware)	} else {
1751d6ce2a0bSSteven Rostedt	    open (RD, ">$redirect") or
1752d6ce2a0bSSteven Rostedt		dodie "failed to write to redirect $redirect";
1753d6ce2a0bSSteven Rostedt	    $dord = 1;
17542545eb61SSteven Rostedt	}
1755b337f979SSteven Rostedt (VMware)    }
17562545eb61SSteven Rostedt
17576e98d1b4SSteven Rostedt (VMware)    my $hit_timeout = 0;
17586e98d1b4SSteven Rostedt (VMware)
17596e98d1b4SSteven Rostedt (VMware)    while (1) {
17606e98d1b4SSteven Rostedt (VMware)	my $fp = \*CMD;
17616e98d1b4SSteven Rostedt (VMware)	if (defined($timeout)) {
17626e98d1b4SSteven Rostedt (VMware)	    doprint "timeout = $timeout\n";
17636e98d1b4SSteven Rostedt (VMware)	}
17646e98d1b4SSteven Rostedt (VMware)	my $line = wait_for_input($fp, $timeout);
17656e98d1b4SSteven Rostedt (VMware)	if (!defined($line)) {
17666e98d1b4SSteven Rostedt (VMware)	    my $now = time;
17676e98d1b4SSteven Rostedt (VMware)	    if (defined($timeout) && (($now - $start_time) >= $timeout)) {
17686e98d1b4SSteven Rostedt (VMware)		doprint "Hit timeout of $timeout, killing process\n";
17696e98d1b4SSteven Rostedt (VMware)		$hit_timeout = 1;
17706e98d1b4SSteven Rostedt (VMware)		kill 9, $pid;
17716e98d1b4SSteven Rostedt (VMware)	    }
17726e98d1b4SSteven Rostedt (VMware)	    last;
17736e98d1b4SSteven Rostedt (VMware)	}
17746e98d1b4SSteven Rostedt (VMware)	print LOG $line if ($dolog);
17756e98d1b4SSteven Rostedt (VMware)	print RD $line if ($dord);
1776b337f979SSteven Rostedt (VMware)	print $line if ($dostdout);
1777d6ce2a0bSSteven Rostedt    }
17782545eb61SSteven Rostedt
1779d6ce2a0bSSteven Rostedt    waitpid($pid, 0);
17805739438bSSteven Rostedt (VMware)    # shift 8 for real exit status
17815739438bSSteven Rostedt (VMware)    $run_command_status = $? >> 8;
17822545eb61SSteven Rostedt
1783d6ce2a0bSSteven Rostedt    close(CMD);
1784d6ce2a0bSSteven Rostedt    close(LOG) if ($dolog);
1785d6ce2a0bSSteven Rostedt    close(RD)  if ($dord);
1786d6ce2a0bSSteven Rostedt
1787b53486e0SSteven Rostedt (Red Hat)    $end_time = time;
1788b53486e0SSteven Rostedt (Red Hat)    my $delta = $end_time - $start_time;
1789b53486e0SSteven Rostedt (Red Hat)
1790b53486e0SSteven Rostedt (Red Hat)    if ($delta == 1) {
1791b53486e0SSteven Rostedt (Red Hat)	doprint "[1 second] ";
1792b53486e0SSteven Rostedt (Red Hat)    } else {
1793b53486e0SSteven Rostedt (Red Hat)	doprint "[$delta seconds] ";
1794b53486e0SSteven Rostedt (Red Hat)    }
1795b53486e0SSteven Rostedt (Red Hat)
17965739438bSSteven Rostedt (VMware)    if ($hit_timeout) {
17975739438bSSteven Rostedt (VMware)	$run_command_status = 1;
17985739438bSSteven Rostedt (VMware)    }
17995739438bSSteven Rostedt (VMware)
18005739438bSSteven Rostedt (VMware)    if ($run_command_status) {
18012545eb61SSteven Rostedt	doprint "FAILED!\n";
18022545eb61SSteven Rostedt    } else {
18032545eb61SSteven Rostedt	doprint "SUCCESS\n";
18042545eb61SSteven Rostedt    }
18052545eb61SSteven Rostedt
18065739438bSSteven Rostedt (VMware)    return !$run_command_status;
18075f9b6cedSSteven Rostedt}
18085f9b6cedSSteven Rostedt
1809e48c5293SSteven Rostedtsub run_ssh {
18106e98d1b4SSteven Rostedt (VMware)    my ($cmd, $timeout) = @_;
1811e48c5293SSteven Rostedt    my $cp_exec = $ssh_exec;
1812e48c5293SSteven Rostedt
1813e48c5293SSteven Rostedt    $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
18146e98d1b4SSteven Rostedt (VMware)    return run_command "$cp_exec", undef , $timeout;
1815e48c5293SSteven Rostedt}
1816e48c5293SSteven Rostedt
1817e48c5293SSteven Rostedtsub run_scp {
181802ad2617SSteven Rostedt    my ($src, $dst, $cp_scp) = @_;
1819e48c5293SSteven Rostedt
1820e48c5293SSteven Rostedt    $cp_scp =~ s/\$SRC_FILE/$src/g;
1821e48c5293SSteven Rostedt    $cp_scp =~ s/\$DST_FILE/$dst/g;
1822e48c5293SSteven Rostedt
1823e48c5293SSteven Rostedt    return run_command "$cp_scp";
1824e48c5293SSteven Rostedt}
1825e48c5293SSteven Rostedt
182602ad2617SSteven Rostedtsub run_scp_install {
182702ad2617SSteven Rostedt    my ($src, $dst) = @_;
182802ad2617SSteven Rostedt
182902ad2617SSteven Rostedt    my $cp_scp = $scp_to_target_install;
183002ad2617SSteven Rostedt
183102ad2617SSteven Rostedt    return run_scp($src, $dst, $cp_scp);
183202ad2617SSteven Rostedt}
183302ad2617SSteven Rostedt
183402ad2617SSteven Rostedtsub run_scp_mod {
183502ad2617SSteven Rostedt    my ($src, $dst) = @_;
183602ad2617SSteven Rostedt
183702ad2617SSteven Rostedt    my $cp_scp = $scp_to_target;
183802ad2617SSteven Rostedt
183902ad2617SSteven Rostedt    return run_scp($src, $dst, $cp_scp);
184002ad2617SSteven Rostedt}
184102ad2617SSteven Rostedt
1842a15ba913SSteven Rostedtsub get_grub2_index {
1843a15ba913SSteven Rostedt
1844752d9665SSteven Rostedt (Red Hat)    return if (defined($grub_number) && defined($last_grub_menu) &&
1845df5f7c66SSteven Rostedt (Red Hat)	       $last_grub_menu eq $grub_menu && defined($last_machine) &&
1846df5f7c66SSteven Rostedt (Red Hat)	       $last_machine eq $machine);
1847a15ba913SSteven Rostedt
1848a15ba913SSteven Rostedt    doprint "Find grub2 menu ... ";
1849a15ba913SSteven Rostedt    $grub_number = -1;
1850a15ba913SSteven Rostedt
1851a15ba913SSteven Rostedt    my $ssh_grub = $ssh_exec;
1852a15ba913SSteven Rostedt    $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1853a15ba913SSteven Rostedt
1854a15ba913SSteven Rostedt    open(IN, "$ssh_grub |")
1855a15ba913SSteven Rostedt	or die "unable to get $grub_file";
1856a15ba913SSteven Rostedt
1857a15ba913SSteven Rostedt    my $found = 0;
1858a15ba913SSteven Rostedt
1859a15ba913SSteven Rostedt    while (<IN>) {
1860a15ba913SSteven Rostedt	if (/^menuentry.*$grub_menu/) {
1861a15ba913SSteven Rostedt	    $grub_number++;
1862a15ba913SSteven Rostedt	    $found = 1;
1863a15ba913SSteven Rostedt	    last;
1864a15ba913SSteven Rostedt	} elsif (/^menuentry\s/) {
1865a15ba913SSteven Rostedt	    $grub_number++;
1866a15ba913SSteven Rostedt	}
1867a15ba913SSteven Rostedt    }
1868a15ba913SSteven Rostedt    close(IN);
1869a15ba913SSteven Rostedt
1870a15ba913SSteven Rostedt    die "Could not find '$grub_menu' in $grub_file on $machine"
1871a15ba913SSteven Rostedt	if (!$found);
1872a15ba913SSteven Rostedt    doprint "$grub_number\n";
1873752d9665SSteven Rostedt (Red Hat)    $last_grub_menu = $grub_menu;
1874df5f7c66SSteven Rostedt (Red Hat)    $last_machine = $machine;
1875a15ba913SSteven Rostedt}
1876a15ba913SSteven Rostedt
18775f9b6cedSSteven Rostedtsub get_grub_index {
18785f9b6cedSSteven Rostedt
1879a15ba913SSteven Rostedt    if ($reboot_type eq "grub2") {
1880a15ba913SSteven Rostedt	get_grub2_index;
1881a15ba913SSteven Rostedt	return;
1882a15ba913SSteven Rostedt    }
1883a15ba913SSteven Rostedt
1884a75fececSSteven Rostedt    if ($reboot_type ne "grub") {
1885a75fececSSteven Rostedt	return;
1886a75fececSSteven Rostedt    }
1887752d9665SSteven Rostedt (Red Hat)    return if (defined($grub_number) && defined($last_grub_menu) &&
1888df5f7c66SSteven Rostedt (Red Hat)	       $last_grub_menu eq $grub_menu && defined($last_machine) &&
1889df5f7c66SSteven Rostedt (Red Hat)	       $last_machine eq $machine);
18905f9b6cedSSteven Rostedt
18915f9b6cedSSteven Rostedt    doprint "Find grub menu ... ";
18925f9b6cedSSteven Rostedt    $grub_number = -1;
1893e48c5293SSteven Rostedt
1894e48c5293SSteven Rostedt    my $ssh_grub = $ssh_exec;
1895e48c5293SSteven Rostedt    $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1896e48c5293SSteven Rostedt
1897e48c5293SSteven Rostedt    open(IN, "$ssh_grub |")
18985f9b6cedSSteven Rostedt	or die "unable to get menu.lst";
1899e48c5293SSteven Rostedt
1900eaa1fe25SSteven Rostedt    my $found = 0;
1901eaa1fe25SSteven Rostedt
19025f9b6cedSSteven Rostedt    while (<IN>) {
1903a75fececSSteven Rostedt	if (/^\s*title\s+$grub_menu\s*$/) {
19045f9b6cedSSteven Rostedt	    $grub_number++;
1905eaa1fe25SSteven Rostedt	    $found = 1;
19065f9b6cedSSteven Rostedt	    last;
19075f9b6cedSSteven Rostedt	} elsif (/^\s*title\s/) {
19085f9b6cedSSteven Rostedt	    $grub_number++;
19095f9b6cedSSteven Rostedt	}
19105f9b6cedSSteven Rostedt    }
19115f9b6cedSSteven Rostedt    close(IN);
19125f9b6cedSSteven Rostedt
1913a75fececSSteven Rostedt    die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1914eaa1fe25SSteven Rostedt	if (!$found);
19155f9b6cedSSteven Rostedt    doprint "$grub_number\n";
1916752d9665SSteven Rostedt (Red Hat)    $last_grub_menu = $grub_menu;
1917df5f7c66SSteven Rostedt (Red Hat)    $last_machine = $machine;
19182545eb61SSteven Rostedt}
19192545eb61SSteven Rostedt
19202545eb61SSteven Rostedtsub wait_for_input
19212545eb61SSteven Rostedt{
19222545eb61SSteven Rostedt    my ($fp, $time) = @_;
1923f7c6401fSSteven Rostedt (VMware)    my $start_time;
19242545eb61SSteven Rostedt    my $rin;
19259d2f7f05SJosh Poimboeuf    my $rout;
19269d2f7f05SJosh Poimboeuf    my $nr;
19279d2f7f05SJosh Poimboeuf    my $buf;
19282545eb61SSteven Rostedt    my $line;
19292545eb61SSteven Rostedt    my $ch;
19302545eb61SSteven Rostedt
19312545eb61SSteven Rostedt    if (!defined($time)) {
19322545eb61SSteven Rostedt	$time = $timeout;
19332545eb61SSteven Rostedt    }
19342545eb61SSteven Rostedt
19352545eb61SSteven Rostedt    $rin = '';
19362545eb61SSteven Rostedt    vec($rin, fileno($fp), 1) = 1;
19379d2f7f05SJosh Poimboeuf    vec($rin, fileno(\*STDIN), 1) = 1;
19389d2f7f05SJosh Poimboeuf
1939f7c6401fSSteven Rostedt (VMware)    $start_time = time;
1940f7c6401fSSteven Rostedt (VMware)
19419d2f7f05SJosh Poimboeuf    while (1) {
19429d2f7f05SJosh Poimboeuf	$nr = select($rout=$rin, undef, undef, $time);
19439d2f7f05SJosh Poimboeuf
1944f7c6401fSSteven Rostedt (VMware)	last if ($nr <= 0);
19459d2f7f05SJosh Poimboeuf
19469d2f7f05SJosh Poimboeuf	# copy data from stdin to the console
19479d2f7f05SJosh Poimboeuf	if (vec($rout, fileno(\*STDIN), 1) == 1) {
194899c014a8SSteven Rostedt (VMware)	    $nr = sysread(\*STDIN, $buf, 1000);
194999c014a8SSteven Rostedt (VMware)	    syswrite($fp, $buf, $nr) if ($nr > 0);
19509d2f7f05SJosh Poimboeuf	}
19512545eb61SSteven Rostedt
1952f7c6401fSSteven Rostedt (VMware)	# The timeout is based on time waiting for the fp data
1953f7c6401fSSteven Rostedt (VMware)	if (vec($rout, fileno($fp), 1) != 1) {
1954f7c6401fSSteven Rostedt (VMware)	    last if (defined($time) && (time - $start_time > $time));
19552545eb61SSteven Rostedt	    next;
19562545eb61SSteven Rostedt	}
19572545eb61SSteven Rostedt
19582545eb61SSteven Rostedt	$line = "";
19592545eb61SSteven Rostedt
19602545eb61SSteven Rostedt	# try to read one char at a time
19612545eb61SSteven Rostedt	while (sysread $fp, $ch, 1) {
19622545eb61SSteven Rostedt	    $line .= $ch;
19632545eb61SSteven Rostedt	    last if ($ch eq "\n");
19642545eb61SSteven Rostedt	}
19652545eb61SSteven Rostedt
1966f7c6401fSSteven Rostedt (VMware)	last if (!length($line));
19672545eb61SSteven Rostedt
19682545eb61SSteven Rostedt	return $line;
19692545eb61SSteven Rostedt    }
1970f7c6401fSSteven Rostedt (VMware)    return undef;
19719d2f7f05SJosh Poimboeuf}
19722545eb61SSteven Rostedt
197375c3fda7SSteven Rostedtsub reboot_to {
1974bc7c5803SSteven Rostedt    if (defined($switch_to_test)) {
1975bc7c5803SSteven Rostedt	run_command $switch_to_test;
1976bc7c5803SSteven Rostedt    }
1977bc7c5803SSteven Rostedt
1978a75fececSSteven Rostedt    if ($reboot_type eq "grub") {
1979c54367f9SSteven Rostedt	run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1980a15ba913SSteven Rostedt    } elsif ($reboot_type eq "grub2") {
1981a15ba913SSteven Rostedt	run_ssh "$grub_reboot $grub_number";
19827786954cSSteven Rostedt    } elsif ($reboot_type eq "syslinux") {
19837786954cSSteven Rostedt	run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
198496f6a0dfSSteven Rostedt    } elsif (defined $reboot_script) {
1985a75fececSSteven Rostedt	run_command "$reboot_script";
19862545eb61SSteven Rostedt    }
198796f6a0dfSSteven Rostedt    reboot;
198896f6a0dfSSteven Rostedt}
19892545eb61SSteven Rostedt
1990a57419b3SSteven Rostedtsub get_sha1 {
1991a57419b3SSteven Rostedt    my ($commit) = @_;
1992a57419b3SSteven Rostedt
1993a57419b3SSteven Rostedt    doprint "git rev-list --max-count=1 $commit ... ";
1994a57419b3SSteven Rostedt    my $sha1 = `git rev-list --max-count=1 $commit`;
1995a57419b3SSteven Rostedt    my $ret = $?;
1996a57419b3SSteven Rostedt
1997a57419b3SSteven Rostedt    logit $sha1;
1998a57419b3SSteven Rostedt
1999a57419b3SSteven Rostedt    if ($ret) {
2000a57419b3SSteven Rostedt	doprint "FAILED\n";
2001a57419b3SSteven Rostedt	dodie "Failed to get git $commit";
2002a57419b3SSteven Rostedt    }
2003a57419b3SSteven Rostedt
2004a57419b3SSteven Rostedt    print "SUCCESS\n";
2005a57419b3SSteven Rostedt
2006a57419b3SSteven Rostedt    chomp $sha1;
2007a57419b3SSteven Rostedt
2008a57419b3SSteven Rostedt    return $sha1;
2009a57419b3SSteven Rostedt}
2010a57419b3SSteven Rostedt
20115a391fbfSSteven Rostedtsub monitor {
20122545eb61SSteven Rostedt    my $booted = 0;
20132545eb61SSteven Rostedt    my $bug = 0;
20146ca996ccSSteven Rostedt    my $bug_ignored = 0;
20155c42fc5bSSteven Rostedt    my $skip_call_trace = 0;
20162b7d9b21SSteven Rostedt    my $loops;
20172545eb61SSteven Rostedt
201838fa3dc1SSteven Rostedt (Red Hat)    my $start_time = time;
201938fa3dc1SSteven Rostedt (Red Hat)
20207faafbd6SSteven Rostedt    wait_for_monitor 5;
20212545eb61SSteven Rostedt
20222545eb61SSteven Rostedt    my $line;
20232545eb61SSteven Rostedt    my $full_line = "";
20242545eb61SSteven Rostedt
20257faafbd6SSteven Rostedt    open(DMESG, "> $dmesg") or
20267faafbd6SSteven Rostedt	die "unable to write to $dmesg";
20272545eb61SSteven Rostedt
202875c3fda7SSteven Rostedt    reboot_to;
20292545eb61SSteven Rostedt
20301c8a617aSSteven Rostedt    my $success_start;
20311c8a617aSSteven Rostedt    my $failure_start;
20322d01b26aSSteven Rostedt    my $monitor_start = time;
20332d01b26aSSteven Rostedt    my $done = 0;
2034f1a5b962SSteven Rostedt    my $version_found = 0;
20351c8a617aSSteven Rostedt
20362d01b26aSSteven Rostedt    while (!$done) {
20372545eb61SSteven Rostedt
2038ecaf8e52SSteven Rostedt	if ($bug && defined($stop_after_failure) &&
2039ecaf8e52SSteven Rostedt	    $stop_after_failure >= 0) {
2040ecaf8e52SSteven Rostedt	    my $time = $stop_after_failure - (time - $failure_start);
2041ecaf8e52SSteven Rostedt	    $line = wait_for_input($monitor_fp, $time);
2042ecaf8e52SSteven Rostedt	    if (!defined($line)) {
2043ecaf8e52SSteven Rostedt		doprint "bug timed out after $booted_timeout seconds\n";
2044ecaf8e52SSteven Rostedt		doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
2045ecaf8e52SSteven Rostedt		last;
2046ecaf8e52SSteven Rostedt	    }
2047ecaf8e52SSteven Rostedt	} elsif ($booted) {
2048a75fececSSteven Rostedt	    $line = wait_for_input($monitor_fp, $booted_timeout);
2049cd4f1d53SSteven Rostedt	    if (!defined($line)) {
2050cd4f1d53SSteven Rostedt		my $s = $booted_timeout == 1 ? "" : "s";
2051cd4f1d53SSteven Rostedt		doprint "Successful boot found: break after $booted_timeout second$s\n";
2052cd4f1d53SSteven Rostedt		last;
2053cd4f1d53SSteven Rostedt	    }
20542b7d9b21SSteven Rostedt	} else {
20557faafbd6SSteven Rostedt	    $line = wait_for_input($monitor_fp);
2056cd4f1d53SSteven Rostedt	    if (!defined($line)) {
2057cd4f1d53SSteven Rostedt		my $s = $timeout == 1 ? "" : "s";
2058cd4f1d53SSteven Rostedt		doprint "Timed out after $timeout second$s\n";
2059cd4f1d53SSteven Rostedt		last;
20602b7d9b21SSteven Rostedt	    }
2061cd4f1d53SSteven Rostedt	}
20622545eb61SSteven Rostedt
20632545eb61SSteven Rostedt	doprint $line;
20647faafbd6SSteven Rostedt	print DMESG $line;
20652545eb61SSteven Rostedt
20662545eb61SSteven Rostedt	# we are not guaranteed to get a full line
20672545eb61SSteven Rostedt	$full_line .= $line;
20682545eb61SSteven Rostedt
2069a75fececSSteven Rostedt	if ($full_line =~ /$success_line/) {
20702545eb61SSteven Rostedt	    $booted = 1;
20711c8a617aSSteven Rostedt	    $success_start = time;
20721c8a617aSSteven Rostedt	}
20731c8a617aSSteven Rostedt
20741c8a617aSSteven Rostedt	if ($booted && defined($stop_after_success) &&
20751c8a617aSSteven Rostedt	    $stop_after_success >= 0) {
20761c8a617aSSteven Rostedt	    my $now = time;
20771c8a617aSSteven Rostedt	    if ($now - $success_start >= $stop_after_success) {
20781c8a617aSSteven Rostedt		doprint "Test forced to stop after $stop_after_success seconds after success\n";
20791c8a617aSSteven Rostedt		last;
20801c8a617aSSteven Rostedt	    }
20812545eb61SSteven Rostedt	}
20822545eb61SSteven Rostedt
20835c42fc5bSSteven Rostedt	if ($full_line =~ /\[ backtrace testing \]/) {
20845c42fc5bSSteven Rostedt	    $skip_call_trace = 1;
20855c42fc5bSSteven Rostedt	}
20865c42fc5bSSteven Rostedt
20872545eb61SSteven Rostedt	if ($full_line =~ /call trace:/i) {
20886ca996ccSSteven Rostedt	    if (!$bug && !$skip_call_trace) {
20896ca996ccSSteven Rostedt		if ($ignore_errors) {
20906ca996ccSSteven Rostedt		    $bug_ignored = 1;
20916ca996ccSSteven Rostedt		} else {
20921c8a617aSSteven Rostedt		    $bug = 1;
20931c8a617aSSteven Rostedt		    $failure_start = time;
20941c8a617aSSteven Rostedt		}
20951c8a617aSSteven Rostedt	    }
20966ca996ccSSteven Rostedt	}
20971c8a617aSSteven Rostedt
20981c8a617aSSteven Rostedt	if ($bug && defined($stop_after_failure) &&
20991c8a617aSSteven Rostedt	    $stop_after_failure >= 0) {
21001c8a617aSSteven Rostedt	    my $now = time;
21011c8a617aSSteven Rostedt	    if ($now - $failure_start >= $stop_after_failure) {
21021c8a617aSSteven Rostedt		doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
21031c8a617aSSteven Rostedt		last;
21041c8a617aSSteven Rostedt	    }
21055c42fc5bSSteven Rostedt	}
21065c42fc5bSSteven Rostedt
21075c42fc5bSSteven Rostedt	if ($full_line =~ /\[ end of backtrace testing \]/) {
21085c42fc5bSSteven Rostedt	    $skip_call_trace = 0;
21095c42fc5bSSteven Rostedt	}
21105c42fc5bSSteven Rostedt
21115c42fc5bSSteven Rostedt	if ($full_line =~ /Kernel panic -/) {
211210abf118SSteven Rostedt	    $failure_start = time;
21132545eb61SSteven Rostedt	    $bug = 1;
21142545eb61SSteven Rostedt	}
21152545eb61SSteven Rostedt
2116f1a5b962SSteven Rostedt	# Detect triple faults by testing the banner
2117f1a5b962SSteven Rostedt	if ($full_line =~ /\bLinux version (\S+).*\n/) {
2118f1a5b962SSteven Rostedt	    if ($1 eq $version) {
2119f1a5b962SSteven Rostedt		$version_found = 1;
2120f1a5b962SSteven Rostedt	    } elsif ($version_found && $detect_triplefault) {
2121f1a5b962SSteven Rostedt		# We already booted into the kernel we are testing,
2122f1a5b962SSteven Rostedt		# but now we booted into another kernel?
2123f1a5b962SSteven Rostedt		# Consider this a triple fault.
21248b513d0cSMasanari Iida		doprint "Already booted in Linux kernel $version, but now\n";
2125f1a5b962SSteven Rostedt		doprint "we booted into Linux kernel $1.\n";
2126f1a5b962SSteven Rostedt		doprint "Assuming that this is a triple fault.\n";
2127f1a5b962SSteven Rostedt		doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
2128f1a5b962SSteven Rostedt		last;
2129f1a5b962SSteven Rostedt	    }
2130f1a5b962SSteven Rostedt	}
2131f1a5b962SSteven Rostedt
21322545eb61SSteven Rostedt	if ($line =~ /\n/) {
21332545eb61SSteven Rostedt	    $full_line = "";
21342545eb61SSteven Rostedt	}
21352d01b26aSSteven Rostedt
21362d01b26aSSteven Rostedt	if ($stop_test_after > 0 && !$booted && !$bug) {
21372d01b26aSSteven Rostedt	    if (time - $monitor_start > $stop_test_after) {
21384d62bf51SSteven Rostedt		doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
21392d01b26aSSteven Rostedt		$done = 1;
21402d01b26aSSteven Rostedt	    }
21412d01b26aSSteven Rostedt	}
21422545eb61SSteven Rostedt    }
21432545eb61SSteven Rostedt
214438fa3dc1SSteven Rostedt (Red Hat)    my $end_time = time;
214538fa3dc1SSteven Rostedt (Red Hat)    $reboot_time = $end_time - $start_time;
214638fa3dc1SSteven Rostedt (Red Hat)
21477faafbd6SSteven Rostedt    close(DMESG);
21482545eb61SSteven Rostedt
21492545eb61SSteven Rostedt    if ($bug) {
21502b7d9b21SSteven Rostedt	return 0 if ($in_bisect);
2151576f627cSSteven Rostedt	fail "failed - got a bug report" and return 0;
21522545eb61SSteven Rostedt    }
21535f9b6cedSSteven Rostedt
2154a75fececSSteven Rostedt    if (!$booted) {
2155a75fececSSteven Rostedt	return 0 if ($in_bisect);
2156576f627cSSteven Rostedt	fail "failed - never got a boot prompt." and return 0;
2157a75fececSSteven Rostedt    }
2158a75fececSSteven Rostedt
21596ca996ccSSteven Rostedt    if ($bug_ignored) {
21606ca996ccSSteven Rostedt	doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
21616ca996ccSSteven Rostedt    }
21626ca996ccSSteven Rostedt
21632b7d9b21SSteven Rostedt    return 1;
21642545eb61SSteven Rostedt}
21652545eb61SSteven Rostedt
21662b29b2f8SSteven Rostedtsub eval_kernel_version {
21672b29b2f8SSteven Rostedt    my ($option) = @_;
21682b29b2f8SSteven Rostedt
21692b29b2f8SSteven Rostedt    $option =~ s/\$KERNEL_VERSION/$version/g;
21702b29b2f8SSteven Rostedt
21712b29b2f8SSteven Rostedt    return $option;
21722b29b2f8SSteven Rostedt}
21732b29b2f8SSteven Rostedt
2174db05cfefSSteven Rostedtsub do_post_install {
2175db05cfefSSteven Rostedt
2176db05cfefSSteven Rostedt    return if (!defined($post_install));
2177db05cfefSSteven Rostedt
21782b29b2f8SSteven Rostedt    my $cp_post_install = eval_kernel_version $post_install;
2179db05cfefSSteven Rostedt    run_command "$cp_post_install" or
2180db05cfefSSteven Rostedt	dodie "Failed to run post install";
2181db05cfefSSteven Rostedt}
2182db05cfefSSteven Rostedt
2183e1a6c3d7SSteven Rostedt# Sometimes the reboot fails, and will hang. We try to ssh to the box
2184e1a6c3d7SSteven Rostedt# and if we fail, we force another reboot, that should powercycle it.
2185e1a6c3d7SSteven Rostedtsub test_booted {
2186e1a6c3d7SSteven Rostedt    if (!run_ssh "echo testing connection") {
2187e1a6c3d7SSteven Rostedt	reboot $sleep_time;
2188e1a6c3d7SSteven Rostedt    }
2189e1a6c3d7SSteven Rostedt}
2190e1a6c3d7SSteven Rostedt
21912545eb61SSteven Rostedtsub install {
21922545eb61SSteven Rostedt
2193e0a8742eSSteven Rostedt    return if ($no_install);
2194e0a8742eSSteven Rostedt
219538fa3dc1SSteven Rostedt (Red Hat)    my $start_time = time;
219638fa3dc1SSteven Rostedt (Red Hat)
2197e5c2ec11SSteven Rostedt    if (defined($pre_install)) {
2198e5c2ec11SSteven Rostedt	my $cp_pre_install = eval_kernel_version $pre_install;
2199e5c2ec11SSteven Rostedt	run_command "$cp_pre_install" or
2200e5c2ec11SSteven Rostedt	    dodie "Failed to run pre install";
2201e5c2ec11SSteven Rostedt    }
2202e5c2ec11SSteven Rostedt
22032b29b2f8SSteven Rostedt    my $cp_target = eval_kernel_version $target_image;
22042b29b2f8SSteven Rostedt
2205e1a6c3d7SSteven Rostedt    test_booted;
2206e1a6c3d7SSteven Rostedt
220702ad2617SSteven Rostedt    run_scp_install "$outputdir/$build_target", "$cp_target" or
22085c42fc5bSSteven Rostedt	dodie "failed to copy image";
22095f9b6cedSSteven Rostedt
22105f9b6cedSSteven Rostedt    my $install_mods = 0;
22115f9b6cedSSteven Rostedt
22125f9b6cedSSteven Rostedt    # should we process modules?
22135f9b6cedSSteven Rostedt    $install_mods = 0;
221451ad1dd1SSteven Rostedt    open(IN, "$output_config") or dodie("Can't read config file");
22155f9b6cedSSteven Rostedt    while (<IN>) {
22165f9b6cedSSteven Rostedt	if (/CONFIG_MODULES(=y)?/) {
22178bc5e4eaSSteven Rostedt	    if (defined($1)) {
22188bc5e4eaSSteven Rostedt		$install_mods = 1;
22195f9b6cedSSteven Rostedt		last;
22205f9b6cedSSteven Rostedt	    }
22215f9b6cedSSteven Rostedt	}
22228bc5e4eaSSteven Rostedt    }
22235f9b6cedSSteven Rostedt    close(IN);
22245f9b6cedSSteven Rostedt
22255f9b6cedSSteven Rostedt    if (!$install_mods) {
2226db05cfefSSteven Rostedt	do_post_install;
22275f9b6cedSSteven Rostedt	doprint "No modules needed\n";
222838fa3dc1SSteven Rostedt (Red Hat)	my $end_time = time;
222938fa3dc1SSteven Rostedt (Red Hat)	$install_time = $end_time - $start_time;
22305f9b6cedSSteven Rostedt	return;
22312545eb61SSteven Rostedt    }
22322545eb61SSteven Rostedt
2233627977d8SSteven Rostedt    run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
22345f9b6cedSSteven Rostedt	dodie "Failed to install modules";
22355f9b6cedSSteven Rostedt
22362545eb61SSteven Rostedt    my $modlib = "/lib/modules/$version";
2237a57419b3SSteven Rostedt    my $modtar = "ktest-mods.tar.bz2";
22382545eb61SSteven Rostedt
2239e48c5293SSteven Rostedt    run_ssh "rm -rf $modlib" or
22405c42fc5bSSteven Rostedt	dodie "failed to remove old mods: $modlib";
22412545eb61SSteven Rostedt
22425c42fc5bSSteven Rostedt    # would be nice if scp -r did not follow symbolic links
2243a75fececSSteven Rostedt    run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
22445c42fc5bSSteven Rostedt	dodie "making tarball";
22455c42fc5bSSteven Rostedt
224602ad2617SSteven Rostedt    run_scp_mod "$tmpdir/$modtar", "/tmp" or
22475c42fc5bSSteven Rostedt	dodie "failed to copy modules";
22485c42fc5bSSteven Rostedt
2249a75fececSSteven Rostedt    unlink "$tmpdir/$modtar";
22505c42fc5bSSteven Rostedt
2251e7b13441SSteven Rostedt    run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
22525c42fc5bSSteven Rostedt	dodie "failed to tar modules";
22535c42fc5bSSteven Rostedt
2254e48c5293SSteven Rostedt    run_ssh "rm -f /tmp/$modtar";
22558b37ca8cSSteven Rostedt
2256db05cfefSSteven Rostedt    do_post_install;
225738fa3dc1SSteven Rostedt (Red Hat)
225838fa3dc1SSteven Rostedt (Red Hat)    my $end_time = time;
225938fa3dc1SSteven Rostedt (Red Hat)    $install_time = $end_time - $start_time;
22602545eb61SSteven Rostedt}
22612545eb61SSteven Rostedt
2262ddf607e5SSteven Rostedtsub get_version {
2263ddf607e5SSteven Rostedt    # get the release name
2264683a3e64SSteven Rostedt    return if ($have_version);
2265ddf607e5SSteven Rostedt    doprint "$make kernelrelease ... ";
226617150fefSSteven Rostedt (Red Hat)    $version = `$make -s kernelrelease | tail -1`;
2267ddf607e5SSteven Rostedt    chomp($version);
2268ddf607e5SSteven Rostedt    doprint "$version\n";
2269683a3e64SSteven Rostedt    $have_version = 1;
2270ddf607e5SSteven Rostedt}
2271ddf607e5SSteven Rostedt
227264d98283SSteven Rostedt (Red Hat)sub start_monitor_and_install {
22739f7424ccSSteven Rostedt    # Make sure the stable kernel has finished booting
2274319ab14fSSteven Rostedt (Red Hat)
2275319ab14fSSteven Rostedt (Red Hat)    # Install bisects, don't need console
2276319ab14fSSteven Rostedt (Red Hat)    if (defined $console) {
22779f7424ccSSteven Rostedt	start_monitor;
22789f7424ccSSteven Rostedt	wait_for_monitor 5;
22799f7424ccSSteven Rostedt	end_monitor;
2280319ab14fSSteven Rostedt (Red Hat)    }
22819f7424ccSSteven Rostedt
2282ddf607e5SSteven Rostedt    get_grub_index;
2283ddf607e5SSteven Rostedt    get_version;
2284ddf607e5SSteven Rostedt    install;
2285ddf607e5SSteven Rostedt
2286319ab14fSSteven Rostedt (Red Hat)    start_monitor if (defined $console);
2287ddf607e5SSteven Rostedt    return monitor;
2288ddf607e5SSteven Rostedt}
2289ddf607e5SSteven Rostedt
22904283b169SSteven Rostedt (Red Hat)my $check_build_re = ".*:.*(warning|error|Error):.*";
22914283b169SSteven Rostedt (Red Hat)my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
22924283b169SSteven Rostedt (Red Hat)
22937328735cSSteven Rostedt (Red Hat)sub process_warning_line {
22947328735cSSteven Rostedt (Red Hat)    my ($line) = @_;
22957328735cSSteven Rostedt (Red Hat)
22967328735cSSteven Rostedt (Red Hat)    chomp $line;
22977328735cSSteven Rostedt (Red Hat)
22987328735cSSteven Rostedt (Red Hat)    # for distcc heterogeneous systems, some compilers
22997328735cSSteven Rostedt (Red Hat)    # do things differently causing warning lines
23007328735cSSteven Rostedt (Red Hat)    # to be slightly different. This makes an attempt
23017328735cSSteven Rostedt (Red Hat)    # to fixe those issues.
23027328735cSSteven Rostedt (Red Hat)
23037328735cSSteven Rostedt (Red Hat)    # chop off the index into the line
23047328735cSSteven Rostedt (Red Hat)    # using distcc, some compilers give different indexes
23057328735cSSteven Rostedt (Red Hat)    # depending on white space
23067328735cSSteven Rostedt (Red Hat)    $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
23077328735cSSteven Rostedt (Red Hat)
23087328735cSSteven Rostedt (Red Hat)    # Some compilers use UTF-8 extended for quotes and some don't.
23097328735cSSteven Rostedt (Red Hat)    $line =~ s/$utf8_quote/'/g;
23107328735cSSteven Rostedt (Red Hat)
23117328735cSSteven Rostedt (Red Hat)    return $line;
23127328735cSSteven Rostedt (Red Hat)}
23137328735cSSteven Rostedt (Red Hat)
23144283b169SSteven Rostedt (Red Hat)# Read buildlog and check against warnings file for any
23154283b169SSteven Rostedt (Red Hat)# new warnings.
23164283b169SSteven Rostedt (Red Hat)#
23174283b169SSteven Rostedt (Red Hat)# Returns 1 if OK
23184283b169SSteven Rostedt (Red Hat)#         0 otherwise
23196c5ee0beSSteven Rostedtsub check_buildlog {
23204283b169SSteven Rostedt (Red Hat)    return 1 if (!defined $warnings_file);
23214283b169SSteven Rostedt (Red Hat)
23224283b169SSteven Rostedt (Red Hat)    my %warnings_list;
23234283b169SSteven Rostedt (Red Hat)
23244283b169SSteven Rostedt (Red Hat)    # Failed builds should not reboot the target
23254283b169SSteven Rostedt (Red Hat)    my $save_no_reboot = $no_reboot;
23264283b169SSteven Rostedt (Red Hat)    $no_reboot = 1;
23274283b169SSteven Rostedt (Red Hat)
23284283b169SSteven Rostedt (Red Hat)    if (-f $warnings_file) {
23294283b169SSteven Rostedt (Red Hat)	open(IN, $warnings_file) or
23304283b169SSteven Rostedt (Red Hat)	    dodie "Error opening $warnings_file";
23314283b169SSteven Rostedt (Red Hat)
23324283b169SSteven Rostedt (Red Hat)	while (<IN>) {
23334283b169SSteven Rostedt (Red Hat)	    if (/$check_build_re/) {
23347328735cSSteven Rostedt (Red Hat)		my $warning = process_warning_line $_;
23357328735cSSteven Rostedt (Red Hat)
23367328735cSSteven Rostedt (Red Hat)		$warnings_list{$warning} = 1;
23374283b169SSteven Rostedt (Red Hat)	    }
23384283b169SSteven Rostedt (Red Hat)	}
23394283b169SSteven Rostedt (Red Hat)	close(IN);
23404283b169SSteven Rostedt (Red Hat)    }
23414283b169SSteven Rostedt (Red Hat)
23424283b169SSteven Rostedt (Red Hat)    # If warnings file didn't exist, and WARNINGS_FILE exist,
23434283b169SSteven Rostedt (Red Hat)    # then we fail on any warning!
23444283b169SSteven Rostedt (Red Hat)
23454283b169SSteven Rostedt (Red Hat)    open(IN, $buildlog) or dodie "Can't open $buildlog";
23464283b169SSteven Rostedt (Red Hat)    while (<IN>) {
23474283b169SSteven Rostedt (Red Hat)	if (/$check_build_re/) {
23487328735cSSteven Rostedt (Red Hat)	    my $warning = process_warning_line $_;
23494283b169SSteven Rostedt (Red Hat)
23507328735cSSteven Rostedt (Red Hat)	    if (!defined $warnings_list{$warning}) {
23514283b169SSteven Rostedt (Red Hat)		fail "New warning found (not in $warnings_file)\n$_\n";
23524283b169SSteven Rostedt (Red Hat)		$no_reboot = $save_no_reboot;
23534283b169SSteven Rostedt (Red Hat)		return 0;
23544283b169SSteven Rostedt (Red Hat)	    }
23554283b169SSteven Rostedt (Red Hat)	}
23564283b169SSteven Rostedt (Red Hat)    }
23574283b169SSteven Rostedt (Red Hat)    $no_reboot = $save_no_reboot;
23584283b169SSteven Rostedt (Red Hat)    close(IN);
23594283b169SSteven Rostedt (Red Hat)}
23604283b169SSteven Rostedt (Red Hat)
23614283b169SSteven Rostedt (Red Hat)sub check_patch_buildlog {
23626c5ee0beSSteven Rostedt    my ($patch) = @_;
23636c5ee0beSSteven Rostedt
23646c5ee0beSSteven Rostedt    my @files = `git show $patch | diffstat -l`;
23656c5ee0beSSteven Rostedt
236635275685SSteven Rostedt (Red Hat)    foreach my $file (@files) {
236735275685SSteven Rostedt (Red Hat)	chomp $file;
236835275685SSteven Rostedt (Red Hat)    }
236935275685SSteven Rostedt (Red Hat)
23706c5ee0beSSteven Rostedt    open(IN, "git show $patch |") or
23716c5ee0beSSteven Rostedt	dodie "failed to show $patch";
23726c5ee0beSSteven Rostedt    while (<IN>) {
23736c5ee0beSSteven Rostedt	if (m,^--- a/(.*),) {
23746c5ee0beSSteven Rostedt	    chomp $1;
23756c5ee0beSSteven Rostedt	    $files[$#files] = $1;
23766c5ee0beSSteven Rostedt	}
23776c5ee0beSSteven Rostedt    }
23786c5ee0beSSteven Rostedt    close(IN);
23796c5ee0beSSteven Rostedt
23806c5ee0beSSteven Rostedt    open(IN, $buildlog) or dodie "Can't open $buildlog";
23816c5ee0beSSteven Rostedt    while (<IN>) {
23826c5ee0beSSteven Rostedt	if (/^\s*(.*?):.*(warning|error)/) {
23836c5ee0beSSteven Rostedt	    my $err = $1;
23846c5ee0beSSteven Rostedt	    foreach my $file (@files) {
2385a75fececSSteven Rostedt		my $fullpath = "$builddir/$file";
23866c5ee0beSSteven Rostedt		if ($file eq $err || $fullpath eq $err) {
23872b7d9b21SSteven Rostedt		    fail "$file built with warnings" and return 0;
23886c5ee0beSSteven Rostedt		}
23896c5ee0beSSteven Rostedt	    }
23906c5ee0beSSteven Rostedt	}
23916c5ee0beSSteven Rostedt    }
23926c5ee0beSSteven Rostedt    close(IN);
23932b7d9b21SSteven Rostedt
23942b7d9b21SSteven Rostedt    return 1;
23956c5ee0beSSteven Rostedt}
23966c5ee0beSSteven Rostedt
2397fcb3f16aSSteven Rostedtsub apply_min_config {
2398fcb3f16aSSteven Rostedt    my $outconfig = "$output_config.new";
2399612b9e9bSSteven Rostedt
2400fcb3f16aSSteven Rostedt    # Read the config file and remove anything that
2401fcb3f16aSSteven Rostedt    # is in the force_config hash (from minconfig and others)
2402fcb3f16aSSteven Rostedt    # then add the force config back.
2403fcb3f16aSSteven Rostedt
2404fcb3f16aSSteven Rostedt    doprint "Applying minimum configurations into $output_config.new\n";
2405fcb3f16aSSteven Rostedt
2406fcb3f16aSSteven Rostedt    open (OUT, ">$outconfig") or
2407fcb3f16aSSteven Rostedt	dodie "Can't create $outconfig";
2408fcb3f16aSSteven Rostedt
2409fcb3f16aSSteven Rostedt    if (-f $output_config) {
2410fcb3f16aSSteven Rostedt	open (IN, $output_config) or
2411fcb3f16aSSteven Rostedt	    dodie "Failed to open $output_config";
2412fcb3f16aSSteven Rostedt	while (<IN>) {
2413fcb3f16aSSteven Rostedt	    if (/^(# )?(CONFIG_[^\s=]*)/) {
2414fcb3f16aSSteven Rostedt		next if (defined($force_config{$2}));
2415fcb3f16aSSteven Rostedt	    }
2416fcb3f16aSSteven Rostedt	    print OUT;
2417fcb3f16aSSteven Rostedt	}
2418fcb3f16aSSteven Rostedt	close IN;
2419fcb3f16aSSteven Rostedt    }
2420fcb3f16aSSteven Rostedt    foreach my $config (keys %force_config) {
2421fcb3f16aSSteven Rostedt	print OUT "$force_config{$config}\n";
2422fcb3f16aSSteven Rostedt    }
2423fcb3f16aSSteven Rostedt    close OUT;
2424fcb3f16aSSteven Rostedt
2425fcb3f16aSSteven Rostedt    run_command "mv $outconfig $output_config";
2426fcb3f16aSSteven Rostedt}
2427fcb3f16aSSteven Rostedt
2428fcb3f16aSSteven Rostedtsub make_oldconfig {
2429fcb3f16aSSteven Rostedt
24304c4ab120SSteven Rostedt    my @force_list = keys %force_config;
24314c4ab120SSteven Rostedt
24324c4ab120SSteven Rostedt    if ($#force_list >= 0) {
2433fcb3f16aSSteven Rostedt	apply_min_config;
24344c4ab120SSteven Rostedt    }
2435fcb3f16aSSteven Rostedt
2436fb16d891SAdam Lee    if (!run_command "$make olddefconfig") {
2437fb16d891SAdam Lee	# Perhaps olddefconfig doesn't exist in this version of the kernel
243818925170SSteven Rostedt	# try oldnoconfig
243918925170SSteven Rostedt	doprint "olddefconfig failed, trying make oldnoconfig\n";
244018925170SSteven Rostedt	if (!run_command "$make oldnoconfig") {
244118925170SSteven Rostedt	    doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2442612b9e9bSSteven Rostedt	    # try a yes '' | oldconfig
2443fcb3f16aSSteven Rostedt	    run_command "yes '' | $make oldconfig" or
2444612b9e9bSSteven Rostedt		dodie "failed make config oldconfig";
2445612b9e9bSSteven Rostedt	}
2446612b9e9bSSteven Rostedt    }
244718925170SSteven Rostedt}
2448612b9e9bSSteven Rostedt
2449fcb3f16aSSteven Rostedt# read a config file and use this to force new configs.
2450fcb3f16aSSteven Rostedtsub load_force_config {
2451fcb3f16aSSteven Rostedt    my ($config) = @_;
2452fcb3f16aSSteven Rostedt
2453cf79fab6SSteven Rostedt    doprint "Loading force configs from $config\n";
2454fcb3f16aSSteven Rostedt    open(IN, $config) or
2455fcb3f16aSSteven Rostedt	dodie "failed to read $config";
2456fcb3f16aSSteven Rostedt    while (<IN>) {
2457fcb3f16aSSteven Rostedt	chomp;
2458fcb3f16aSSteven Rostedt	if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2459fcb3f16aSSteven Rostedt	    $force_config{$1} = $_;
2460fcb3f16aSSteven Rostedt	} elsif (/^# (CONFIG_\S*) is not set/) {
2461fcb3f16aSSteven Rostedt	    $force_config{$1} = $_;
2462fcb3f16aSSteven Rostedt	}
2463fcb3f16aSSteven Rostedt    }
2464fcb3f16aSSteven Rostedt    close IN;
2465fcb3f16aSSteven Rostedt}
2466fcb3f16aSSteven Rostedt
24672545eb61SSteven Rostedtsub build {
24682545eb61SSteven Rostedt    my ($type) = @_;
24692545eb61SSteven Rostedt
24707faafbd6SSteven Rostedt    unlink $buildlog;
24717faafbd6SSteven Rostedt
247238fa3dc1SSteven Rostedt (Red Hat)    my $start_time = time;
247338fa3dc1SSteven Rostedt (Red Hat)
24744ab1cce5SSteven Rostedt    # Failed builds should not reboot the target
24754ab1cce5SSteven Rostedt    my $save_no_reboot = $no_reboot;
24764ab1cce5SSteven Rostedt    $no_reboot = 1;
24774ab1cce5SSteven Rostedt
2478683a3e64SSteven Rostedt    # Calculate a new version from here.
2479683a3e64SSteven Rostedt    $have_version = 0;
2480683a3e64SSteven Rostedt
24810bd6c1a3SSteven Rostedt    if (defined($pre_build)) {
24820bd6c1a3SSteven Rostedt	my $ret = run_command $pre_build;
24830bd6c1a3SSteven Rostedt	if (!$ret && defined($pre_build_die) &&
24840bd6c1a3SSteven Rostedt	    $pre_build_die) {
24850bd6c1a3SSteven Rostedt	    dodie "failed to pre_build\n";
24860bd6c1a3SSteven Rostedt	}
24870bd6c1a3SSteven Rostedt    }
24880bd6c1a3SSteven Rostedt
248975c3fda7SSteven Rostedt    if ($type =~ /^useconfig:(.*)/) {
249051ad1dd1SSteven Rostedt	run_command "cp $1 $output_config" or
249175c3fda7SSteven Rostedt	    dodie "could not copy $1 to .config";
24925f9b6cedSSteven Rostedt
249375c3fda7SSteven Rostedt	$type = "oldconfig";
249475c3fda7SSteven Rostedt    }
249575c3fda7SSteven Rostedt
24965c42fc5bSSteven Rostedt    # old config can ask questions
24975c42fc5bSSteven Rostedt    if ($type eq "oldconfig") {
2498fb16d891SAdam Lee	$type = "olddefconfig";
249975c3fda7SSteven Rostedt
250075c3fda7SSteven Rostedt	# allow for empty configs
250151ad1dd1SSteven Rostedt	run_command "touch $output_config";
250275c3fda7SSteven Rostedt
250313488231SAndrew Jones	if (!$noclean) {
250451ad1dd1SSteven Rostedt	    run_command "mv $output_config $outputdir/config_temp" or
25055c42fc5bSSteven Rostedt		dodie "moving .config";
25065c42fc5bSSteven Rostedt
250713488231SAndrew Jones	    run_command "$make mrproper" or dodie "make mrproper";
25085c42fc5bSSteven Rostedt
250951ad1dd1SSteven Rostedt	    run_command "mv $outputdir/config_temp $output_config" or
25105c42fc5bSSteven Rostedt		dodie "moving config_temp";
251113488231SAndrew Jones	}
25125c42fc5bSSteven Rostedt
25135c42fc5bSSteven Rostedt    } elsif (!$noclean) {
251451ad1dd1SSteven Rostedt	unlink "$output_config";
25155f9b6cedSSteven Rostedt	run_command "$make mrproper" or
25165c42fc5bSSteven Rostedt	    dodie "make mrproper";
25175c42fc5bSSteven Rostedt    }
25182545eb61SSteven Rostedt
25192545eb61SSteven Rostedt    # add something to distinguish this build
2520a75fececSSteven Rostedt    open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2521a75fececSSteven Rostedt    print OUT "$localversion\n";
25222545eb61SSteven Rostedt    close(OUT);
25232545eb61SSteven Rostedt
25245f9b6cedSSteven Rostedt    if (defined($minconfig)) {
2525fcb3f16aSSteven Rostedt	load_force_config($minconfig);
25262545eb61SSteven Rostedt    }
25272545eb61SSteven Rostedt
2528fb16d891SAdam Lee    if ($type ne "olddefconfig") {
2529fcb3f16aSSteven Rostedt	run_command "$make $type" or
25305c42fc5bSSteven Rostedt	    dodie "failed make config";
2531612b9e9bSSteven Rostedt    }
2532fcb3f16aSSteven Rostedt    # Run old config regardless, to enforce min configurations
2533fcb3f16aSSteven Rostedt    make_oldconfig;
25342545eb61SSteven Rostedt
2535f983a2bcSSatoru Takeuchi    my $build_ret = run_command "$make $build_options", $buildlog;
25360bd6c1a3SSteven Rostedt
25370bd6c1a3SSteven Rostedt    if (defined($post_build)) {
2538683a3e64SSteven Rostedt	# Because a post build may change the kernel version
2539683a3e64SSteven Rostedt	# do it now.
2540683a3e64SSteven Rostedt	get_version;
25410bd6c1a3SSteven Rostedt	my $ret = run_command $post_build;
25420bd6c1a3SSteven Rostedt	if (!$ret && defined($post_build_die) &&
25430bd6c1a3SSteven Rostedt	    $post_build_die) {
25440bd6c1a3SSteven Rostedt	    dodie "failed to post_build\n";
25450bd6c1a3SSteven Rostedt	}
25460bd6c1a3SSteven Rostedt    }
25470bd6c1a3SSteven Rostedt
25480bd6c1a3SSteven Rostedt    if (!$build_ret) {
25495f9b6cedSSteven Rostedt	# bisect may need this to pass
25504ab1cce5SSteven Rostedt	if ($in_bisect) {
25514ab1cce5SSteven Rostedt	    $no_reboot = $save_no_reboot;
25524ab1cce5SSteven Rostedt	    return 0;
25534ab1cce5SSteven Rostedt	}
25542b7d9b21SSteven Rostedt	fail "failed build" and return 0;
25552545eb61SSteven Rostedt    }
25565f9b6cedSSteven Rostedt
25574ab1cce5SSteven Rostedt    $no_reboot = $save_no_reboot;
25584ab1cce5SSteven Rostedt
255938fa3dc1SSteven Rostedt (Red Hat)    my $end_time = time;
256038fa3dc1SSteven Rostedt (Red Hat)    $build_time = $end_time - $start_time;
256138fa3dc1SSteven Rostedt (Red Hat)
25622b7d9b21SSteven Rostedt    return 1;
25632545eb61SSteven Rostedt}
25642545eb61SSteven Rostedt
256575c3fda7SSteven Rostedtsub halt {
2566e48c5293SSteven Rostedt    if (!run_ssh "halt" or defined($power_off)) {
2567576f627cSSteven Rostedt	if (defined($poweroff_after_halt)) {
2568576f627cSSteven Rostedt	    sleep $poweroff_after_halt;
2569576f627cSSteven Rostedt	    run_command "$power_off";
2570576f627cSSteven Rostedt	}
2571576f627cSSteven Rostedt    } else {
257275c3fda7SSteven Rostedt	# nope? the zap it!
2573a75fececSSteven Rostedt	run_command "$power_off";
257475c3fda7SSteven Rostedt    }
257575c3fda7SSteven Rostedt}
257675c3fda7SSteven Rostedt
25775f9b6cedSSteven Rostedtsub success {
25785f9b6cedSSteven Rostedt    my ($i) = @_;
25795f9b6cedSSteven Rostedt
2580e48c5293SSteven Rostedt    $successes++;
2581e48c5293SSteven Rostedt
25829064af52SSteven Rostedt    my $name = "";
25839064af52SSteven Rostedt
25849064af52SSteven Rostedt    if (defined($test_name)) {
25859064af52SSteven Rostedt	$name = " ($test_name)";
25869064af52SSteven Rostedt    }
25879064af52SSteven Rostedt
25884bf6e1fcSSteven Rostedt (Red Hat)    print_times;
25894bf6e1fcSSteven Rostedt (Red Hat)
25905f9b6cedSSteven Rostedt    doprint "\n\n*******************************************\n";
25915f9b6cedSSteven Rostedt    doprint     "*******************************************\n";
25929064af52SSteven Rostedt    doprint     "KTEST RESULT: TEST $i$name SUCCESS!!!!         **\n";
25935f9b6cedSSteven Rostedt    doprint     "*******************************************\n";
25945f9b6cedSSteven Rostedt    doprint     "*******************************************\n";
25955f9b6cedSSteven Rostedt
2596de5b6e3bSRabin Vincent    if (defined($store_successes)) {
2597de5b6e3bSRabin Vincent        save_logs "success", $store_successes;
2598de5b6e3bSRabin Vincent    }
2599de5b6e3bSRabin Vincent
2600576f627cSSteven Rostedt    if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
2601a75fececSSteven Rostedt	doprint "Reboot and wait $sleep_time seconds\n";
2602bc7c5803SSteven Rostedt	reboot_to_good $sleep_time;
26035f9b6cedSSteven Rostedt    }
26042e07c9f5SSteven Rostedt (VMware)
26052e07c9f5SSteven Rostedt (VMware)    if (defined($post_test)) {
26062e07c9f5SSteven Rostedt (VMware)	run_command $post_test;
26072e07c9f5SSteven Rostedt (VMware)    }
26085f9b6cedSSteven Rostedt}
26095f9b6cedSSteven Rostedt
2610c960bb9fSSteven Rostedtsub answer_bisect {
2611c960bb9fSSteven Rostedt    for (;;) {
2612fee9d3e6SChris J Arges	doprint "Pass, fail, or skip? [p/f/s]";
2613c960bb9fSSteven Rostedt	my $ans = <STDIN>;
2614c960bb9fSSteven Rostedt	chomp $ans;
2615c960bb9fSSteven Rostedt	if ($ans eq "p" || $ans eq "P") {
2616c960bb9fSSteven Rostedt	    return 1;
2617c960bb9fSSteven Rostedt	} elsif ($ans eq "f" || $ans eq "F") {
2618c960bb9fSSteven Rostedt	    return 0;
2619fee9d3e6SChris J Arges	} elsif ($ans eq "s" || $ans eq "S") {
2620fee9d3e6SChris J Arges	    return -1;
2621c960bb9fSSteven Rostedt	} else {
2622fee9d3e6SChris J Arges	    print "Please answer 'p', 'f', or 's'\n";
2623c960bb9fSSteven Rostedt	}
2624c960bb9fSSteven Rostedt    }
2625c960bb9fSSteven Rostedt}
2626c960bb9fSSteven Rostedt
26275a391fbfSSteven Rostedtsub child_run_test {
26285a391fbfSSteven Rostedt
26297faafbd6SSteven Rostedt    # child should have no power
2630a75fececSSteven Rostedt    $reboot_on_error = 0;
2631a75fececSSteven Rostedt    $poweroff_on_error = 0;
2632a75fececSSteven Rostedt    $die_on_failure = 1;
26337faafbd6SSteven Rostedt
26345739438bSSteven Rostedt (VMware)    run_command $run_test, $testlog;
2635a9dd5d63SRabin Vincent
26365739438bSSteven Rostedt (VMware)    exit $run_command_status;
26375a391fbfSSteven Rostedt}
26385a391fbfSSteven Rostedt
26395a391fbfSSteven Rostedtmy $child_done;
26405a391fbfSSteven Rostedt
26415a391fbfSSteven Rostedtsub child_finished {
26425a391fbfSSteven Rostedt    $child_done = 1;
26435a391fbfSSteven Rostedt}
26445a391fbfSSteven Rostedt
26455a391fbfSSteven Rostedtsub do_run_test {
26465a391fbfSSteven Rostedt    my $child_pid;
26475a391fbfSSteven Rostedt    my $child_exit;
26485a391fbfSSteven Rostedt    my $line;
26495a391fbfSSteven Rostedt    my $full_line;
26505a391fbfSSteven Rostedt    my $bug = 0;
26519b1d367dSSteven Rostedt    my $bug_ignored = 0;
26525a391fbfSSteven Rostedt
265338fa3dc1SSteven Rostedt (Red Hat)    my $start_time = time;
265438fa3dc1SSteven Rostedt (Red Hat)
26557faafbd6SSteven Rostedt    wait_for_monitor 1;
26565a391fbfSSteven Rostedt
26577faafbd6SSteven Rostedt    doprint "run test $run_test\n";
26585a391fbfSSteven Rostedt
26595a391fbfSSteven Rostedt    $child_done = 0;
26605a391fbfSSteven Rostedt
26615a391fbfSSteven Rostedt    $SIG{CHLD} = qw(child_finished);
26625a391fbfSSteven Rostedt
26635a391fbfSSteven Rostedt    $child_pid = fork;
26645a391fbfSSteven Rostedt
26655a391fbfSSteven Rostedt    child_run_test if (!$child_pid);
26665a391fbfSSteven Rostedt
26675a391fbfSSteven Rostedt    $full_line = "";
26685a391fbfSSteven Rostedt
26695a391fbfSSteven Rostedt    do {
26707faafbd6SSteven Rostedt	$line = wait_for_input($monitor_fp, 1);
26715a391fbfSSteven Rostedt	if (defined($line)) {
26725a391fbfSSteven Rostedt
26735a391fbfSSteven Rostedt	    # we are not guaranteed to get a full line
26745a391fbfSSteven Rostedt	    $full_line .= $line;
26758ea0e063SSteven Rostedt	    doprint $line;
26765a391fbfSSteven Rostedt
26775a391fbfSSteven Rostedt	    if ($full_line =~ /call trace:/i) {
26789b1d367dSSteven Rostedt		if ($ignore_errors) {
26799b1d367dSSteven Rostedt		    $bug_ignored = 1;
26809b1d367dSSteven Rostedt		} else {
26815a391fbfSSteven Rostedt		    $bug = 1;
26825a391fbfSSteven Rostedt		}
26839b1d367dSSteven Rostedt	    }
26845a391fbfSSteven Rostedt
26855a391fbfSSteven Rostedt	    if ($full_line =~ /Kernel panic -/) {
26865a391fbfSSteven Rostedt		$bug = 1;
26875a391fbfSSteven Rostedt	    }
26885a391fbfSSteven Rostedt
26895a391fbfSSteven Rostedt	    if ($line =~ /\n/) {
26905a391fbfSSteven Rostedt		$full_line = "";
26915a391fbfSSteven Rostedt	    }
26925a391fbfSSteven Rostedt	}
26935a391fbfSSteven Rostedt    } while (!$child_done && !$bug);
26945a391fbfSSteven Rostedt
26959b1d367dSSteven Rostedt    if (!$bug && $bug_ignored) {
26969b1d367dSSteven Rostedt	doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
26979b1d367dSSteven Rostedt    }
26989b1d367dSSteven Rostedt
26995a391fbfSSteven Rostedt    if ($bug) {
27008ea0e063SSteven Rostedt	my $failure_start = time;
27018ea0e063SSteven Rostedt	my $now;
27028ea0e063SSteven Rostedt	do {
27038ea0e063SSteven Rostedt	    $line = wait_for_input($monitor_fp, 1);
27048ea0e063SSteven Rostedt	    if (defined($line)) {
27058ea0e063SSteven Rostedt		doprint $line;
27068ea0e063SSteven Rostedt	    }
27078ea0e063SSteven Rostedt	    $now = time;
27088ea0e063SSteven Rostedt	    if ($now - $failure_start >= $stop_after_failure) {
27098ea0e063SSteven Rostedt		last;
27108ea0e063SSteven Rostedt	    }
27118ea0e063SSteven Rostedt	} while (defined($line));
27128ea0e063SSteven Rostedt
27135a391fbfSSteven Rostedt	doprint "Detected kernel crash!\n";
27145a391fbfSSteven Rostedt	# kill the child with extreme prejudice
27155a391fbfSSteven Rostedt	kill 9, $child_pid;
27165a391fbfSSteven Rostedt    }
27175a391fbfSSteven Rostedt
27185a391fbfSSteven Rostedt    waitpid $child_pid, 0;
271932677207SSteven Rostedt (VMware)    $child_exit = $? >> 8;
27205a391fbfSSteven Rostedt
272138fa3dc1SSteven Rostedt (Red Hat)    my $end_time = time;
272238fa3dc1SSteven Rostedt (Red Hat)    $test_time = $end_time - $start_time;
272338fa3dc1SSteven Rostedt (Red Hat)
2724c5dacb88SSteven Rostedt    if (!$bug && $in_bisect) {
2725c5dacb88SSteven Rostedt	if (defined($bisect_ret_good)) {
2726c5dacb88SSteven Rostedt	    if ($child_exit == $bisect_ret_good) {
2727c5dacb88SSteven Rostedt		return 1;
2728c5dacb88SSteven Rostedt	    }
2729c5dacb88SSteven Rostedt	}
2730c5dacb88SSteven Rostedt	if (defined($bisect_ret_skip)) {
2731c5dacb88SSteven Rostedt	    if ($child_exit == $bisect_ret_skip) {
2732c5dacb88SSteven Rostedt		return -1;
2733c5dacb88SSteven Rostedt	    }
2734c5dacb88SSteven Rostedt	}
2735c5dacb88SSteven Rostedt	if (defined($bisect_ret_abort)) {
2736c5dacb88SSteven Rostedt	    if ($child_exit == $bisect_ret_abort) {
2737c5dacb88SSteven Rostedt		fail "test abort" and return -2;
2738c5dacb88SSteven Rostedt	    }
2739c5dacb88SSteven Rostedt	}
2740c5dacb88SSteven Rostedt	if (defined($bisect_ret_bad)) {
2741c5dacb88SSteven Rostedt	    if ($child_exit == $bisect_ret_skip) {
2742c5dacb88SSteven Rostedt		return 0;
2743c5dacb88SSteven Rostedt	    }
2744c5dacb88SSteven Rostedt	}
2745c5dacb88SSteven Rostedt	if (defined($bisect_ret_default)) {
2746c5dacb88SSteven Rostedt	    if ($bisect_ret_default eq "good") {
2747c5dacb88SSteven Rostedt		return 1;
2748c5dacb88SSteven Rostedt	    } elsif ($bisect_ret_default eq "bad") {
2749c5dacb88SSteven Rostedt		return 0;
2750c5dacb88SSteven Rostedt	    } elsif ($bisect_ret_default eq "skip") {
2751c5dacb88SSteven Rostedt		return -1;
2752c5dacb88SSteven Rostedt	    } elsif ($bisect_ret_default eq "abort") {
2753c5dacb88SSteven Rostedt		return -2;
2754c5dacb88SSteven Rostedt	    } else {
2755c5dacb88SSteven Rostedt		fail "unknown default action: $bisect_ret_default"
2756c5dacb88SSteven Rostedt		    and return -2;
2757c5dacb88SSteven Rostedt	    }
2758c5dacb88SSteven Rostedt	}
2759c5dacb88SSteven Rostedt    }
2760c5dacb88SSteven Rostedt
27615a391fbfSSteven Rostedt    if ($bug || $child_exit) {
27622b7d9b21SSteven Rostedt	return 0 if $in_bisect;
27632b7d9b21SSteven Rostedt	fail "test failed" and return 0;
27645a391fbfSSteven Rostedt    }
27652b7d9b21SSteven Rostedt    return 1;
27665a391fbfSSteven Rostedt}
27675a391fbfSSteven Rostedt
2768a75fececSSteven Rostedtsub run_git_bisect {
2769a75fececSSteven Rostedt    my ($command) = @_;
2770a75fececSSteven Rostedt
2771a75fececSSteven Rostedt    doprint "$command ... ";
2772a75fececSSteven Rostedt
2773a75fececSSteven Rostedt    my $output = `$command 2>&1`;
2774a75fececSSteven Rostedt    my $ret = $?;
2775a75fececSSteven Rostedt
2776a75fececSSteven Rostedt    logit $output;
2777a75fececSSteven Rostedt
2778a75fececSSteven Rostedt    if ($ret) {
2779a75fececSSteven Rostedt	doprint "FAILED\n";
2780a75fececSSteven Rostedt	dodie "Failed to git bisect";
2781a75fececSSteven Rostedt    }
2782a75fececSSteven Rostedt
2783a75fececSSteven Rostedt    doprint "SUCCESS\n";
2784a75fececSSteven Rostedt    if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2785a75fececSSteven Rostedt	doprint "$1 [$2]\n";
2786a75fececSSteven Rostedt    } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
2787b5f4aea6SSteven Rostedt	$bisect_bad_commit = $1;
2788a75fececSSteven Rostedt	doprint "Found bad commit... $1\n";
2789a75fececSSteven Rostedt	return 0;
2790a75fececSSteven Rostedt    } else {
2791a75fececSSteven Rostedt	# we already logged it, just print it now.
2792a75fececSSteven Rostedt	print $output;
2793a75fececSSteven Rostedt    }
2794a75fececSSteven Rostedt
2795a75fececSSteven Rostedt    return 1;
2796a75fececSSteven Rostedt}
2797a75fececSSteven Rostedt
2798c23dca7cSSteven Rostedtsub bisect_reboot {
2799c23dca7cSSteven Rostedt    doprint "Reboot and sleep $bisect_sleep_time seconds\n";
2800bc7c5803SSteven Rostedt    reboot_to_good $bisect_sleep_time;
2801c23dca7cSSteven Rostedt}
2802c23dca7cSSteven Rostedt
2803c23dca7cSSteven Rostedt# returns 1 on success, 0 on failure, -1 on skip
28040a05c769SSteven Rostedtsub run_bisect_test {
28050a05c769SSteven Rostedt    my ($type, $buildtype) = @_;
28065f9b6cedSSteven Rostedt
28072b7d9b21SSteven Rostedt    my $failed = 0;
28085f9b6cedSSteven Rostedt    my $result;
28095f9b6cedSSteven Rostedt    my $output;
28105f9b6cedSSteven Rostedt    my $ret;
28115f9b6cedSSteven Rostedt
28120a05c769SSteven Rostedt    $in_bisect = 1;
28130a05c769SSteven Rostedt
28140a05c769SSteven Rostedt    build $buildtype or $failed = 1;
28155f9b6cedSSteven Rostedt
28165f9b6cedSSteven Rostedt    if ($type ne "build") {
2817c23dca7cSSteven Rostedt	if ($failed && $bisect_skip) {
2818c23dca7cSSteven Rostedt	    $in_bisect = 0;
2819c23dca7cSSteven Rostedt	    return -1;
2820c23dca7cSSteven Rostedt	}
28217faafbd6SSteven Rostedt	dodie "Failed on build" if $failed;
28225f9b6cedSSteven Rostedt
28235f9b6cedSSteven Rostedt	# Now boot the box
282464d98283SSteven Rostedt (Red Hat)	start_monitor_and_install or $failed = 1;
28255f9b6cedSSteven Rostedt
28265f9b6cedSSteven Rostedt	if ($type ne "boot") {
2827c23dca7cSSteven Rostedt	    if ($failed && $bisect_skip) {
2828c23dca7cSSteven Rostedt		end_monitor;
2829c23dca7cSSteven Rostedt		bisect_reboot;
2830c23dca7cSSteven Rostedt		$in_bisect = 0;
2831c23dca7cSSteven Rostedt		return -1;
2832c23dca7cSSteven Rostedt	    }
28337faafbd6SSteven Rostedt	    dodie "Failed on boot" if $failed;
28345a391fbfSSteven Rostedt
28352b7d9b21SSteven Rostedt	    do_run_test or $failed = 1;
28365f9b6cedSSteven Rostedt	}
28377faafbd6SSteven Rostedt	end_monitor;
28385f9b6cedSSteven Rostedt    }
28395f9b6cedSSteven Rostedt
28405f9b6cedSSteven Rostedt    if ($failed) {
28410a05c769SSteven Rostedt	$result = 0;
28425f9b6cedSSteven Rostedt    } else {
28430a05c769SSteven Rostedt	$result = 1;
28445f9b6cedSSteven Rostedt    }
28454025bc62SSteven Rostedt
28464025bc62SSteven Rostedt    # reboot the box to a kernel we can ssh to
28474025bc62SSteven Rostedt    if ($type ne "build") {
28484025bc62SSteven Rostedt	bisect_reboot;
28494025bc62SSteven Rostedt    }
28500a05c769SSteven Rostedt    $in_bisect = 0;
28510a05c769SSteven Rostedt
28520a05c769SSteven Rostedt    return $result;
28530a05c769SSteven Rostedt}
28540a05c769SSteven Rostedt
28550a05c769SSteven Rostedtsub run_bisect {
28560a05c769SSteven Rostedt    my ($type) = @_;
28570a05c769SSteven Rostedt    my $buildtype = "oldconfig";
28580a05c769SSteven Rostedt
28590a05c769SSteven Rostedt    # We should have a minconfig to use?
28600a05c769SSteven Rostedt    if (defined($minconfig)) {
28610a05c769SSteven Rostedt	$buildtype = "useconfig:$minconfig";
28620a05c769SSteven Rostedt    }
28630a05c769SSteven Rostedt
2864961d9cacSSteven Rostedt (Red Hat)    # If the user sets bisect_tries to less than 1, then no tries
2865961d9cacSSteven Rostedt (Red Hat)    # is a success.
2866961d9cacSSteven Rostedt (Red Hat)    my $ret = 1;
2867961d9cacSSteven Rostedt (Red Hat)
2868961d9cacSSteven Rostedt (Red Hat)    # Still let the user manually decide that though.
2869961d9cacSSteven Rostedt (Red Hat)    if ($bisect_tries < 1 && $bisect_manual) {
2870961d9cacSSteven Rostedt (Red Hat)	$ret = answer_bisect;
2871961d9cacSSteven Rostedt (Red Hat)    }
2872961d9cacSSteven Rostedt (Red Hat)
2873961d9cacSSteven Rostedt (Red Hat)    for (my $i = 0; $i < $bisect_tries; $i++) {
2874961d9cacSSteven Rostedt (Red Hat)	if ($bisect_tries > 1) {
2875961d9cacSSteven Rostedt (Red Hat)	    my $t = $i + 1;
2876961d9cacSSteven Rostedt (Red Hat)	    doprint("Running bisect trial $t of $bisect_tries:\n");
2877961d9cacSSteven Rostedt (Red Hat)	}
2878961d9cacSSteven Rostedt (Red Hat)	$ret = run_bisect_test $type, $buildtype;
28790a05c769SSteven Rostedt
2880c960bb9fSSteven Rostedt	if ($bisect_manual) {
2881c960bb9fSSteven Rostedt	    $ret = answer_bisect;
2882c960bb9fSSteven Rostedt	}
28835f9b6cedSSteven Rostedt
2884961d9cacSSteven Rostedt (Red Hat)	last if (!$ret);
2885961d9cacSSteven Rostedt (Red Hat)    }
2886961d9cacSSteven Rostedt (Red Hat)
2887d6ce2a0bSSteven Rostedt    # Are we looking for where it worked, not failed?
28885158ba3eSRuss Dill    if ($reverse_bisect && $ret >= 0) {
28890a05c769SSteven Rostedt	$ret = !$ret;
2890d6ce2a0bSSteven Rostedt    }
2891d6ce2a0bSSteven Rostedt
2892c23dca7cSSteven Rostedt    if ($ret > 0) {
28930a05c769SSteven Rostedt	return "good";
2894c23dca7cSSteven Rostedt    } elsif ($ret == 0) {
28950a05c769SSteven Rostedt	return  "bad";
2896c23dca7cSSteven Rostedt    } elsif ($bisect_skip) {
2897c23dca7cSSteven Rostedt	doprint "HIT A BAD COMMIT ... SKIPPING\n";
2898c23dca7cSSteven Rostedt	return "skip";
28990a05c769SSteven Rostedt    }
29005f9b6cedSSteven Rostedt}
29015f9b6cedSSteven Rostedt
2902dad98754SSteven Rostedtsub update_bisect_replay {
2903dad98754SSteven Rostedt    my $tmp_log = "$tmpdir/ktest_bisect_log";
2904dad98754SSteven Rostedt    run_command "git bisect log > $tmp_log" or
2905dad98754SSteven Rostedt	die "can't create bisect log";
2906dad98754SSteven Rostedt    return $tmp_log;
2907dad98754SSteven Rostedt}
2908dad98754SSteven Rostedt
29095f9b6cedSSteven Rostedtsub bisect {
29105f9b6cedSSteven Rostedt    my ($i) = @_;
29115f9b6cedSSteven Rostedt
29125f9b6cedSSteven Rostedt    my $result;
29135f9b6cedSSteven Rostedt
2914b5f4aea6SSteven Rostedt    die "BISECT_GOOD[$i] not defined\n"	if (!defined($bisect_good));
2915b5f4aea6SSteven Rostedt    die "BISECT_BAD[$i] not defined\n"	if (!defined($bisect_bad));
2916b5f4aea6SSteven Rostedt    die "BISECT_TYPE[$i] not defined\n"	if (!defined($bisect_type));
29175f9b6cedSSteven Rostedt
2918b5f4aea6SSteven Rostedt    my $good = $bisect_good;
2919b5f4aea6SSteven Rostedt    my $bad = $bisect_bad;
2920b5f4aea6SSteven Rostedt    my $type = $bisect_type;
2921b5f4aea6SSteven Rostedt    my $start = $bisect_start;
2922b5f4aea6SSteven Rostedt    my $replay = $bisect_replay;
2923b5f4aea6SSteven Rostedt    my $start_files = $bisect_files;
29243410f6fdSSteven Rostedt
29253410f6fdSSteven Rostedt    if (defined($start_files)) {
29263410f6fdSSteven Rostedt	$start_files = " -- " . $start_files;
29273410f6fdSSteven Rostedt    } else {
29283410f6fdSSteven Rostedt	$start_files = "";
29293410f6fdSSteven Rostedt    }
29305f9b6cedSSteven Rostedt
2931a57419b3SSteven Rostedt    # convert to true sha1's
2932a57419b3SSteven Rostedt    $good = get_sha1($good);
2933a57419b3SSteven Rostedt    $bad = get_sha1($bad);
2934a57419b3SSteven Rostedt
2935b5f4aea6SSteven Rostedt    if (defined($bisect_reverse) && $bisect_reverse == 1) {
2936d6ce2a0bSSteven Rostedt	doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2937d6ce2a0bSSteven Rostedt	$reverse_bisect = 1;
2938d6ce2a0bSSteven Rostedt    } else {
2939d6ce2a0bSSteven Rostedt	$reverse_bisect = 0;
2940d6ce2a0bSSteven Rostedt    }
2941d6ce2a0bSSteven Rostedt
29425a391fbfSSteven Rostedt    # Can't have a test without having a test to run
29435a391fbfSSteven Rostedt    if ($type eq "test" && !defined($run_test)) {
29445a391fbfSSteven Rostedt	$type = "boot";
29455a391fbfSSteven Rostedt    }
29465a391fbfSSteven Rostedt
2947dad98754SSteven Rostedt    # Check if a bisect was running
2948dad98754SSteven Rostedt    my $bisect_start_file = "$builddir/.git/BISECT_START";
2949dad98754SSteven Rostedt
2950b5f4aea6SSteven Rostedt    my $check = $bisect_check;
2951dad98754SSteven Rostedt    my $do_check = defined($check) && $check ne "0";
2952dad98754SSteven Rostedt
2953dad98754SSteven Rostedt    if ( -f $bisect_start_file ) {
2954dad98754SSteven Rostedt	print "Bisect in progress found\n";
2955dad98754SSteven Rostedt	if ($do_check) {
2956dad98754SSteven Rostedt	    print " If you say yes, then no checks of good or bad will be done\n";
2957dad98754SSteven Rostedt	}
2958dad98754SSteven Rostedt	if (defined($replay)) {
2959dad98754SSteven Rostedt	    print "** BISECT_REPLAY is defined in config file **";
2960dad98754SSteven Rostedt	    print " Ignore config option and perform new git bisect log?\n";
2961dad98754SSteven Rostedt	    if (read_ync " (yes, no, or cancel) ") {
2962dad98754SSteven Rostedt		$replay = update_bisect_replay;
2963dad98754SSteven Rostedt		$do_check = 0;
2964dad98754SSteven Rostedt	    }
2965dad98754SSteven Rostedt	} elsif (read_yn "read git log and continue?") {
2966dad98754SSteven Rostedt	    $replay = update_bisect_replay;
2967dad98754SSteven Rostedt	    $do_check = 0;
2968dad98754SSteven Rostedt	}
2969dad98754SSteven Rostedt    }
2970dad98754SSteven Rostedt
2971dad98754SSteven Rostedt    if ($do_check) {
2972a75fececSSteven Rostedt
2973a75fececSSteven Rostedt	# get current HEAD
2974a57419b3SSteven Rostedt	my $head = get_sha1("HEAD");
2975a75fececSSteven Rostedt
2976a75fececSSteven Rostedt	if ($check ne "good") {
2977a75fececSSteven Rostedt	    doprint "TESTING BISECT BAD [$bad]\n";
2978a75fececSSteven Rostedt	    run_command "git checkout $bad" or
2979a75fececSSteven Rostedt		die "Failed to checkout $bad";
2980a75fececSSteven Rostedt
2981a75fececSSteven Rostedt	    $result = run_bisect $type;
2982a75fececSSteven Rostedt
2983a75fececSSteven Rostedt	    if ($result ne "bad") {
2984a75fececSSteven Rostedt		fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2985a75fececSSteven Rostedt	    }
2986a75fececSSteven Rostedt	}
2987a75fececSSteven Rostedt
2988a75fececSSteven Rostedt	if ($check ne "bad") {
2989a75fececSSteven Rostedt	    doprint "TESTING BISECT GOOD [$good]\n";
2990a75fececSSteven Rostedt	    run_command "git checkout $good" or
2991a75fececSSteven Rostedt		die "Failed to checkout $good";
2992a75fececSSteven Rostedt
2993a75fececSSteven Rostedt	    $result = run_bisect $type;
2994a75fececSSteven Rostedt
2995a75fececSSteven Rostedt	    if ($result ne "good") {
2996a75fececSSteven Rostedt		fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2997a75fececSSteven Rostedt	    }
2998a75fececSSteven Rostedt	}
2999a75fececSSteven Rostedt
3000a75fececSSteven Rostedt	# checkout where we started
3001a75fececSSteven Rostedt	run_command "git checkout $head" or
3002a75fececSSteven Rostedt	    die "Failed to checkout $head";
3003a75fececSSteven Rostedt    }
3004a75fececSSteven Rostedt
30053410f6fdSSteven Rostedt    run_command "git bisect start$start_files" or
3006a75fececSSteven Rostedt	dodie "could not start bisect";
3007a75fececSSteven Rostedt
3008d832d743SSteven Rostedt (Red Hat)    if (defined($replay)) {
3009d832d743SSteven Rostedt (Red Hat)	run_command "git bisect replay $replay" or
3010d832d743SSteven Rostedt (Red Hat)	    dodie "failed to run replay";
3011d832d743SSteven Rostedt (Red Hat)    } else {
3012d832d743SSteven Rostedt (Red Hat)
3013a75fececSSteven Rostedt	run_command "git bisect good $good" or
3014a75fececSSteven Rostedt	    dodie "could not set bisect good to $good";
3015a75fececSSteven Rostedt
3016a75fececSSteven Rostedt	run_git_bisect "git bisect bad $bad" or
3017a75fececSSteven Rostedt	    dodie "could not set bisect bad to $bad";
3018a75fececSSteven Rostedt
3019a75fececSSteven Rostedt    }
3020a75fececSSteven Rostedt
3021a75fececSSteven Rostedt    if (defined($start)) {
3022a75fececSSteven Rostedt	run_command "git checkout $start" or
3023a75fececSSteven Rostedt	    dodie "failed to checkout $start";
3024a75fececSSteven Rostedt    }
3025a75fececSSteven Rostedt
3026a75fececSSteven Rostedt    my $test;
30275f9b6cedSSteven Rostedt    do {
30285f9b6cedSSteven Rostedt	$result = run_bisect $type;
3029a75fececSSteven Rostedt	$test = run_git_bisect "git bisect $result";
303038fa3dc1SSteven Rostedt (Red Hat)	print_times;
3031a75fececSSteven Rostedt    } while ($test);
30325f9b6cedSSteven Rostedt
30335f9b6cedSSteven Rostedt    run_command "git bisect log" or
30345f9b6cedSSteven Rostedt	dodie "could not capture git bisect log";
30355f9b6cedSSteven Rostedt
30365f9b6cedSSteven Rostedt    run_command "git bisect reset" or
30375f9b6cedSSteven Rostedt	dodie "could not reset git bisect";
30385f9b6cedSSteven Rostedt
3039b5f4aea6SSteven Rostedt    doprint "Bad commit was [$bisect_bad_commit]\n";
30405f9b6cedSSteven Rostedt
30410a05c769SSteven Rostedt    success $i;
30420a05c769SSteven Rostedt}
30430a05c769SSteven Rostedt
3044cf79fab6SSteven Rostedt# config_ignore holds the configs that were set (or unset) for
3045cf79fab6SSteven Rostedt# a good config and we will ignore these configs for the rest
3046cf79fab6SSteven Rostedt# of a config bisect. These configs stay as they were.
30470a05c769SSteven Rostedtmy %config_ignore;
3048cf79fab6SSteven Rostedt
3049cf79fab6SSteven Rostedt# config_set holds what all configs were set as.
30500a05c769SSteven Rostedtmy %config_set;
30510a05c769SSteven Rostedt
3052cf79fab6SSteven Rostedt# config_off holds the set of configs that the bad config had disabled.
3053cf79fab6SSteven Rostedt# We need to record them and set them in the .config when running
3054fb16d891SAdam Lee# olddefconfig, because olddefconfig keeps the defaults.
3055cf79fab6SSteven Rostedtmy %config_off;
3056cf79fab6SSteven Rostedt
3057cf79fab6SSteven Rostedt# config_off_tmp holds a set of configs to turn off for now
3058cf79fab6SSteven Rostedtmy @config_off_tmp;
3059cf79fab6SSteven Rostedt
3060cf79fab6SSteven Rostedt# config_list is the set of configs that are being tested
30610a05c769SSteven Rostedtmy %config_list;
30620a05c769SSteven Rostedtmy %null_config;
30630a05c769SSteven Rostedt
30640a05c769SSteven Rostedtmy %dependency;
30650a05c769SSteven Rostedt
30664c4ab120SSteven Rostedtsub assign_configs {
30674c4ab120SSteven Rostedt    my ($hash, $config) = @_;
30680a05c769SSteven Rostedt
30696071c22eSSteven Rostedt (Red Hat)    doprint "Reading configs from $config\n";
30706071c22eSSteven Rostedt (Red Hat)
30710a05c769SSteven Rostedt    open (IN, $config)
30720a05c769SSteven Rostedt	or dodie "Failed to read $config";
30730a05c769SSteven Rostedt
30740a05c769SSteven Rostedt    while (<IN>) {
30756071c22eSSteven Rostedt (Red Hat)	chomp;
30769bf71749SSteven Rostedt	if (/^((CONFIG\S*)=.*)/) {
30774c4ab120SSteven Rostedt	    ${$hash}{$2} = $1;
30786071c22eSSteven Rostedt (Red Hat)	} elsif (/^(# (CONFIG\S*) is not set)/) {
30796071c22eSSteven Rostedt (Red Hat)	    ${$hash}{$2} = $1;
30800a05c769SSteven Rostedt	}
30810a05c769SSteven Rostedt    }
30820a05c769SSteven Rostedt
30830a05c769SSteven Rostedt    close(IN);
30840a05c769SSteven Rostedt}
30850a05c769SSteven Rostedt
30864c4ab120SSteven Rostedtsub process_config_ignore {
30874c4ab120SSteven Rostedt    my ($config) = @_;
30884c4ab120SSteven Rostedt
30894c4ab120SSteven Rostedt    assign_configs \%config_ignore, $config;
30904c4ab120SSteven Rostedt}
30914c4ab120SSteven Rostedt
30920a05c769SSteven Rostedtsub get_dependencies {
30930a05c769SSteven Rostedt    my ($config) = @_;
30940a05c769SSteven Rostedt
30950a05c769SSteven Rostedt    my $arr = $dependency{$config};
30960a05c769SSteven Rostedt    if (!defined($arr)) {
30970a05c769SSteven Rostedt	return ();
30980a05c769SSteven Rostedt    }
30990a05c769SSteven Rostedt
31000a05c769SSteven Rostedt    my @deps = @{$arr};
31010a05c769SSteven Rostedt
31020a05c769SSteven Rostedt    foreach my $dep (@{$arr}) {
31030a05c769SSteven Rostedt	print "ADD DEP $dep\n";
31040a05c769SSteven Rostedt	@deps = (@deps, get_dependencies $dep);
31050a05c769SSteven Rostedt    }
31060a05c769SSteven Rostedt
31070a05c769SSteven Rostedt    return @deps;
31080a05c769SSteven Rostedt}
31090a05c769SSteven Rostedt
31106071c22eSSteven Rostedt (Red Hat)sub save_config {
31116071c22eSSteven Rostedt (Red Hat)    my ($pc, $file) = @_;
31120a05c769SSteven Rostedt
31136071c22eSSteven Rostedt (Red Hat)    my %configs = %{$pc};
31140a05c769SSteven Rostedt
31156071c22eSSteven Rostedt (Red Hat)    doprint "Saving configs into $file\n";
31160a05c769SSteven Rostedt
31176071c22eSSteven Rostedt (Red Hat)    open(OUT, ">$file") or dodie "Can not write to $file";
3118cf79fab6SSteven Rostedt
31196071c22eSSteven Rostedt (Red Hat)    foreach my $config (keys %configs) {
31206071c22eSSteven Rostedt (Red Hat)	print OUT "$configs{$config}\n";
31210a05c769SSteven Rostedt    }
31220a05c769SSteven Rostedt    close(OUT);
31236071c22eSSteven Rostedt (Red Hat)}
31246071c22eSSteven Rostedt (Red Hat)
31256071c22eSSteven Rostedt (Red Hat)sub create_config {
31266071c22eSSteven Rostedt (Red Hat)    my ($name, $pc) = @_;
31276071c22eSSteven Rostedt (Red Hat)
31286071c22eSSteven Rostedt (Red Hat)    doprint "Creating old config from $name configs\n";
31296071c22eSSteven Rostedt (Red Hat)
31306071c22eSSteven Rostedt (Red Hat)    save_config $pc, $output_config;
31310a05c769SSteven Rostedt
3132fcb3f16aSSteven Rostedt    make_oldconfig;
31330a05c769SSteven Rostedt}
31340a05c769SSteven Rostedt
31350a05c769SSteven Rostedtsub run_config_bisect_test {
31360a05c769SSteven Rostedt    my ($type) = @_;
31370a05c769SSteven Rostedt
31384cc559bdSSteven Rostedt (Red Hat)    my $ret = run_bisect_test $type, "oldconfig";
31394cc559bdSSteven Rostedt (Red Hat)
31404cc559bdSSteven Rostedt (Red Hat)    if ($bisect_manual) {
31414cc559bdSSteven Rostedt (Red Hat)	$ret = answer_bisect;
31424cc559bdSSteven Rostedt (Red Hat)    }
31434cc559bdSSteven Rostedt (Red Hat)
31444cc559bdSSteven Rostedt (Red Hat)    return $ret;
31450a05c769SSteven Rostedt}
31460a05c769SSteven Rostedt
3147a9adc261SScott Woodsub config_bisect_end {
3148a9adc261SScott Wood    my ($good, $bad) = @_;
3149b2b07ea2SSteven Rostedt (VMware)    my $diffexec = "diff -u";
31500a05c769SSteven Rostedt
3151b2b07ea2SSteven Rostedt (VMware)    if (-f "$builddir/scripts/diffconfig") {
3152b2b07ea2SSteven Rostedt (VMware)	$diffexec = "$builddir/scripts/diffconfig";
3153b2b07ea2SSteven Rostedt (VMware)    }
31540a05c769SSteven Rostedt    doprint "\n\n***************************************\n";
3155a9adc261SScott Wood    doprint "No more config bisecting possible.\n";
3156b2b07ea2SSteven Rostedt (VMware)    run_command "$diffexec $good $bad", 1;
31570a05c769SSteven Rostedt    doprint "***************************************\n\n";
31580a05c769SSteven Rostedt}
31590a05c769SSteven Rostedt
31606071c22eSSteven Rostedt (Red Hat)sub run_config_bisect {
3161a9adc261SScott Wood    my ($good, $bad, $last_result) = @_;
3162133087f0SSteven Rostedt (VMware)    my $reset = "";
3163a9adc261SScott Wood    my $cmd;
31646071c22eSSteven Rostedt (Red Hat)    my $ret;
31656071c22eSSteven Rostedt (Red Hat)
3166133087f0SSteven Rostedt (VMware)    if (!length($last_result)) {
3167133087f0SSteven Rostedt (VMware)	$reset = "-r";
3168133087f0SSteven Rostedt (VMware)    }
316940667fb5SSteven Rostedt (VMware)    run_command "$config_bisect_exec $reset -b $outputdir $good $bad $last_result", 1;
31706071c22eSSteven Rostedt (Red Hat)
3171a9adc261SScott Wood    # config-bisect returns:
3172a9adc261SScott Wood    #   0 if there is more to bisect
3173a9adc261SScott Wood    #   1 for finding a good config
3174a9adc261SScott Wood    #   2 if it can not find any more configs
3175a9adc261SScott Wood    #  -1 (255) on error
3176a9adc261SScott Wood    if ($run_command_status) {
3177a9adc261SScott Wood	return $run_command_status;
31786071c22eSSteven Rostedt (Red Hat)    }
31796071c22eSSteven Rostedt (Red Hat)
3180a9adc261SScott Wood    $ret = run_config_bisect_test $config_bisect_type;
31816071c22eSSteven Rostedt (Red Hat)    if ($ret) {
31826071c22eSSteven Rostedt (Red Hat)        doprint "NEW GOOD CONFIG\n";
3183a9adc261SScott Wood	# Return 3 for good config
3184a9adc261SScott Wood	return 3;
3185cf79fab6SSteven Rostedt    } else {
31866071c22eSSteven Rostedt (Red Hat)        doprint "NEW BAD CONFIG\n";
3187a9adc261SScott Wood	# Return 4 for bad config
3188a9adc261SScott Wood	return 4;
31896071c22eSSteven Rostedt (Red Hat)    }
31900a05c769SSteven Rostedt}
31910a05c769SSteven Rostedt
31920a05c769SSteven Rostedtsub config_bisect {
31930a05c769SSteven Rostedt    my ($i) = @_;
31940a05c769SSteven Rostedt
3195a9adc261SScott Wood    my $good_config;
3196a9adc261SScott Wood    my $bad_config;
3197a9adc261SScott Wood
31986071c22eSSteven Rostedt (Red Hat)    my $type = $config_bisect_type;
3199c4d1d11fSSteven Rostedt (Red Hat)    my $ret;
32000a05c769SSteven Rostedt
32016071c22eSSteven Rostedt (Red Hat)    $bad_config = $config_bisect;
32020a05c769SSteven Rostedt
320330f75da5SSteven Rostedt    if (defined($config_bisect_good)) {
32046071c22eSSteven Rostedt (Red Hat)	$good_config = $config_bisect_good;
32056071c22eSSteven Rostedt (Red Hat)    } elsif (defined($minconfig)) {
32066071c22eSSteven Rostedt (Red Hat)	$good_config = $minconfig;
32070a05c769SSteven Rostedt    } else {
32086071c22eSSteven Rostedt (Red Hat)	doprint "No config specified, checking if defconfig works";
3209c4d1d11fSSteven Rostedt (Red Hat)	$ret = run_bisect_test $type, "defconfig";
32106071c22eSSteven Rostedt (Red Hat)	if (!$ret) {
32116071c22eSSteven Rostedt (Red Hat)	    fail "Have no good config to compare with, please set CONFIG_BISECT_GOOD";
32126071c22eSSteven Rostedt (Red Hat)	    return 1;
32136071c22eSSteven Rostedt (Red Hat)	}
32146071c22eSSteven Rostedt (Red Hat)	$good_config = $output_config;
32150a05c769SSteven Rostedt    }
32160a05c769SSteven Rostedt
321740667fb5SSteven Rostedt (VMware)    if (!defined($config_bisect_exec)) {
321840667fb5SSteven Rostedt (VMware)	# First check the location that ktest.pl ran
321940667fb5SSteven Rostedt (VMware)	my @locations = ( "$pwd/config-bisect.pl",
322040667fb5SSteven Rostedt (VMware)			  "$dirname/config-bisect.pl",
322140667fb5SSteven Rostedt (VMware)			  "$builddir/tools/testing/ktest/config-bisect.pl",
322240667fb5SSteven Rostedt (VMware)			  undef );
322340667fb5SSteven Rostedt (VMware)	foreach my $loc (@locations) {
322440667fb5SSteven Rostedt (VMware)	    doprint "loc = $loc\n";
322540667fb5SSteven Rostedt (VMware)	    $config_bisect_exec = $loc;
322640667fb5SSteven Rostedt (VMware)	    last if (defined($config_bisect_exec && -x $config_bisect_exec));
322740667fb5SSteven Rostedt (VMware)	}
322840667fb5SSteven Rostedt (VMware)	if (!defined($config_bisect_exec)) {
322940667fb5SSteven Rostedt (VMware)	    fail "Could not find an executable config-bisect.pl\n",
323040667fb5SSteven Rostedt (VMware)		"  Set CONFIG_BISECT_EXEC to point to config-bisect.pl";
323140667fb5SSteven Rostedt (VMware)	    return 1;
323240667fb5SSteven Rostedt (VMware)	}
323340667fb5SSteven Rostedt (VMware)    }
323440667fb5SSteven Rostedt (VMware)
32356071c22eSSteven Rostedt (Red Hat)    # we don't want min configs to cause issues here.
32366071c22eSSteven Rostedt (Red Hat)    doprint "Disabling 'MIN_CONFIG' for this test\n";
32376071c22eSSteven Rostedt (Red Hat)    undef $minconfig;
32380a05c769SSteven Rostedt
32396071c22eSSteven Rostedt (Red Hat)    my %good_configs;
32406071c22eSSteven Rostedt (Red Hat)    my %bad_configs;
32416071c22eSSteven Rostedt (Red Hat)    my %tmp_configs;
32420a05c769SSteven Rostedt
32435a57299aSSteven Rostedt (VMware)    if (-f "$tmpdir/good_config.tmp" || -f "$tmpdir/bad_config.tmp") {
32445a57299aSSteven Rostedt (VMware)	if (read_yn "Interrupted config-bisect. Continue (n - will start new)?") {
32455a57299aSSteven Rostedt (VMware)	    if (-f "$tmpdir/good_config.tmp") {
32465a57299aSSteven Rostedt (VMware)		$good_config = "$tmpdir/good_config.tmp";
32475a57299aSSteven Rostedt (VMware)	    } else {
32485a57299aSSteven Rostedt (VMware)		$good_config = "$tmpdir/good_config";
32495a57299aSSteven Rostedt (VMware)	    }
32505a57299aSSteven Rostedt (VMware)	    if (-f "$tmpdir/bad_config.tmp") {
32515a57299aSSteven Rostedt (VMware)		$bad_config = "$tmpdir/bad_config.tmp";
32525a57299aSSteven Rostedt (VMware)	    } else {
32535a57299aSSteven Rostedt (VMware)		$bad_config = "$tmpdir/bad_config";
32545a57299aSSteven Rostedt (VMware)	    }
32555a57299aSSteven Rostedt (VMware)	}
32565a57299aSSteven Rostedt (VMware)    }
32576071c22eSSteven Rostedt (Red Hat)    doprint "Run good configs through make oldconfig\n";
32586071c22eSSteven Rostedt (Red Hat)    assign_configs \%tmp_configs, $good_config;
32596071c22eSSteven Rostedt (Red Hat)    create_config "$good_config", \%tmp_configs;
3260a9adc261SScott Wood    $good_config = "$tmpdir/good_config";
3261a9adc261SScott Wood    system("cp $output_config $good_config") == 0 or dodie "cp good config";
32620a05c769SSteven Rostedt
32636071c22eSSteven Rostedt (Red Hat)    doprint "Run bad configs through make oldconfig\n";
32646071c22eSSteven Rostedt (Red Hat)    assign_configs \%tmp_configs, $bad_config;
32656071c22eSSteven Rostedt (Red Hat)    create_config "$bad_config", \%tmp_configs;
32666071c22eSSteven Rostedt (Red Hat)    $bad_config = "$tmpdir/bad_config";
3267a9adc261SScott Wood    system("cp $output_config $bad_config") == 0 or dodie "cp bad config";
32680a05c769SSteven Rostedt
3269c4d1d11fSSteven Rostedt (Red Hat)    if (defined($config_bisect_check) && $config_bisect_check ne "0") {
3270c4d1d11fSSteven Rostedt (Red Hat)	if ($config_bisect_check ne "good") {
3271c4d1d11fSSteven Rostedt (Red Hat)	    doprint "Testing bad config\n";
3272c4d1d11fSSteven Rostedt (Red Hat)
3273c4d1d11fSSteven Rostedt (Red Hat)	    $ret = run_bisect_test $type, "useconfig:$bad_config";
3274c4d1d11fSSteven Rostedt (Red Hat)	    if ($ret) {
3275c4d1d11fSSteven Rostedt (Red Hat)		fail "Bad config succeeded when expected to fail!";
3276c4d1d11fSSteven Rostedt (Red Hat)		return 0;
3277c4d1d11fSSteven Rostedt (Red Hat)	    }
3278c4d1d11fSSteven Rostedt (Red Hat)	}
3279c4d1d11fSSteven Rostedt (Red Hat)	if ($config_bisect_check ne "bad") {
3280c4d1d11fSSteven Rostedt (Red Hat)	    doprint "Testing good config\n";
3281c4d1d11fSSteven Rostedt (Red Hat)
3282c4d1d11fSSteven Rostedt (Red Hat)	    $ret = run_bisect_test $type, "useconfig:$good_config";
3283c4d1d11fSSteven Rostedt (Red Hat)	    if (!$ret) {
3284c4d1d11fSSteven Rostedt (Red Hat)		fail "Good config failed when expected to succeed!";
3285c4d1d11fSSteven Rostedt (Red Hat)		return 0;
3286c4d1d11fSSteven Rostedt (Red Hat)	    }
3287c4d1d11fSSteven Rostedt (Red Hat)	}
3288c4d1d11fSSteven Rostedt (Red Hat)    }
3289b0918612SSteven Rostedt
3290a9adc261SScott Wood    my $last_run = "";
3291a9adc261SScott Wood
32920a05c769SSteven Rostedt    do {
3293a9adc261SScott Wood	$ret = run_config_bisect $good_config, $bad_config, $last_run;
3294a9adc261SScott Wood	if ($ret == 3) {
3295a9adc261SScott Wood	    $last_run = "good";
3296a9adc261SScott Wood	} elsif ($ret == 4) {
3297a9adc261SScott Wood	    $last_run = "bad";
3298a9adc261SScott Wood	}
329938fa3dc1SSteven Rostedt (Red Hat)	print_times;
3300a9adc261SScott Wood    } while ($ret == 3 || $ret == 4);
3301a9adc261SScott Wood
3302a9adc261SScott Wood    if ($ret == 2) {
3303a9adc261SScott Wood        config_bisect_end "$good_config.tmp", "$bad_config.tmp";
3304a9adc261SScott Wood    }
33050a05c769SSteven Rostedt
33060a05c769SSteven Rostedt    return $ret if ($ret < 0);
33075f9b6cedSSteven Rostedt
33085f9b6cedSSteven Rostedt    success $i;
33095f9b6cedSSteven Rostedt}
33105f9b6cedSSteven Rostedt
331127d934b2SSteven Rostedtsub patchcheck_reboot {
331227d934b2SSteven Rostedt    doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
3313bc7c5803SSteven Rostedt    reboot_to_good $patchcheck_sleep_time;
331427d934b2SSteven Rostedt}
331527d934b2SSteven Rostedt
33166c5ee0beSSteven Rostedtsub patchcheck {
33176c5ee0beSSteven Rostedt    my ($i) = @_;
33186c5ee0beSSteven Rostedt
33196c5ee0beSSteven Rostedt    die "PATCHCHECK_START[$i] not defined\n"
3320b5f4aea6SSteven Rostedt	if (!defined($patchcheck_start));
33216c5ee0beSSteven Rostedt    die "PATCHCHECK_TYPE[$i] not defined\n"
3322b5f4aea6SSteven Rostedt	if (!defined($patchcheck_type));
33236c5ee0beSSteven Rostedt
3324b5f4aea6SSteven Rostedt    my $start = $patchcheck_start;
33256c5ee0beSSteven Rostedt
332623a0e161SSteven Rostedt (Red Hat)    my $cherry = $patchcheck_cherry;
332723a0e161SSteven Rostedt (Red Hat)    if (!defined($cherry)) {
332823a0e161SSteven Rostedt (Red Hat)	$cherry = 0;
332923a0e161SSteven Rostedt (Red Hat)    }
333023a0e161SSteven Rostedt (Red Hat)
33316c5ee0beSSteven Rostedt    my $end = "HEAD";
3332b5f4aea6SSteven Rostedt    if (defined($patchcheck_end)) {
3333b5f4aea6SSteven Rostedt	$end = $patchcheck_end;
333423a0e161SSteven Rostedt (Red Hat)    } elsif ($cherry) {
333523a0e161SSteven Rostedt (Red Hat)	die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
33366c5ee0beSSteven Rostedt    }
33376c5ee0beSSteven Rostedt
3338a57419b3SSteven Rostedt    # Get the true sha1's since we can use things like HEAD~3
3339a57419b3SSteven Rostedt    $start = get_sha1($start);
3340a57419b3SSteven Rostedt    $end = get_sha1($end);
3341a57419b3SSteven Rostedt
3342b5f4aea6SSteven Rostedt    my $type = $patchcheck_type;
33436c5ee0beSSteven Rostedt
33446c5ee0beSSteven Rostedt    # Can't have a test without having a test to run
33456c5ee0beSSteven Rostedt    if ($type eq "test" && !defined($run_test)) {
33466c5ee0beSSteven Rostedt	$type = "boot";
33476c5ee0beSSteven Rostedt    }
33486c5ee0beSSteven Rostedt
334923a0e161SSteven Rostedt (Red Hat)    if ($cherry) {
335023a0e161SSteven Rostedt (Red Hat)	open (IN, "git cherry -v $start $end|") or
335123a0e161SSteven Rostedt (Red Hat)	    dodie "could not get git list";
335223a0e161SSteven Rostedt (Red Hat)    } else {
33536c5ee0beSSteven Rostedt	open (IN, "git log --pretty=oneline $end|") or
33546c5ee0beSSteven Rostedt	    dodie "could not get git list";
335523a0e161SSteven Rostedt (Red Hat)    }
33566c5ee0beSSteven Rostedt
33576c5ee0beSSteven Rostedt    my @list;
33586c5ee0beSSteven Rostedt
33596c5ee0beSSteven Rostedt    while (<IN>) {
33606c5ee0beSSteven Rostedt	chomp;
336123a0e161SSteven Rostedt (Red Hat)	# git cherry adds a '+' we want to remove
336223a0e161SSteven Rostedt (Red Hat)	s/^\+ //;
33636c5ee0beSSteven Rostedt	$list[$#list+1] = $_;
33646c5ee0beSSteven Rostedt	last if (/^$start/);
33656c5ee0beSSteven Rostedt    }
33666c5ee0beSSteven Rostedt    close(IN);
33676c5ee0beSSteven Rostedt
336823a0e161SSteven Rostedt (Red Hat)    if (!$cherry) {
33696c5ee0beSSteven Rostedt	if ($list[$#list] !~ /^$start/) {
33702b7d9b21SSteven Rostedt	    fail "SHA1 $start not found";
33716c5ee0beSSteven Rostedt	}
33726c5ee0beSSteven Rostedt
33736c5ee0beSSteven Rostedt	# go backwards in the list
33746c5ee0beSSteven Rostedt	@list = reverse @list;
337523a0e161SSteven Rostedt (Red Hat)    }
337623a0e161SSteven Rostedt (Red Hat)
337723a0e161SSteven Rostedt (Red Hat)    doprint("Going to test the following commits:\n");
337823a0e161SSteven Rostedt (Red Hat)    foreach my $l (@list) {
337923a0e161SSteven Rostedt (Red Hat)	doprint "$l\n";
338023a0e161SSteven Rostedt (Red Hat)    }
33816c5ee0beSSteven Rostedt
33826c5ee0beSSteven Rostedt    my $save_clean = $noclean;
33831990207dSSteven Rostedt    my %ignored_warnings;
33841990207dSSteven Rostedt
33851990207dSSteven Rostedt    if (defined($ignore_warnings)) {
33861990207dSSteven Rostedt	foreach my $sha1 (split /\s+/, $ignore_warnings) {
33871990207dSSteven Rostedt	    $ignored_warnings{$sha1} = 1;
33881990207dSSteven Rostedt	}
33891990207dSSteven Rostedt    }
33906c5ee0beSSteven Rostedt
33916c5ee0beSSteven Rostedt    $in_patchcheck = 1;
33926c5ee0beSSteven Rostedt    foreach my $item (@list) {
33936c5ee0beSSteven Rostedt	my $sha1 = $item;
33946c5ee0beSSteven Rostedt	$sha1 =~ s/^([[:xdigit:]]+).*/$1/;
33956c5ee0beSSteven Rostedt
33967c2c49ecSSteven Rostedt (Red Hat)	doprint "\nProcessing commit \"$item\"\n\n";
33976c5ee0beSSteven Rostedt
33986c5ee0beSSteven Rostedt	run_command "git checkout $sha1" or
33996c5ee0beSSteven Rostedt	    die "Failed to checkout $sha1";
34006c5ee0beSSteven Rostedt
34016c5ee0beSSteven Rostedt	# only clean on the first and last patch
34026c5ee0beSSteven Rostedt	if ($item eq $list[0] ||
34036c5ee0beSSteven Rostedt	    $item eq $list[$#list]) {
34046c5ee0beSSteven Rostedt	    $noclean = $save_clean;
34056c5ee0beSSteven Rostedt	} else {
34066c5ee0beSSteven Rostedt	    $noclean = 1;
34076c5ee0beSSteven Rostedt	}
34086c5ee0beSSteven Rostedt
34096c5ee0beSSteven Rostedt	if (defined($minconfig)) {
34102b7d9b21SSteven Rostedt	    build "useconfig:$minconfig" or return 0;
34116c5ee0beSSteven Rostedt	} else {
34126c5ee0beSSteven Rostedt	    # ?? no config to use?
34132b7d9b21SSteven Rostedt	    build "oldconfig" or return 0;
34146c5ee0beSSteven Rostedt	}
34156c5ee0beSSteven Rostedt
34164283b169SSteven Rostedt (Red Hat)	# No need to do per patch checking if warnings file exists
34174283b169SSteven Rostedt (Red Hat)	if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
34184283b169SSteven Rostedt (Red Hat)	    check_patch_buildlog $sha1 or return 0;
34191990207dSSteven Rostedt	}
34206c5ee0beSSteven Rostedt
34214283b169SSteven Rostedt (Red Hat)	check_buildlog or return 0;
34224283b169SSteven Rostedt (Red Hat)
34236c5ee0beSSteven Rostedt	next if ($type eq "build");
34246c5ee0beSSteven Rostedt
34257faafbd6SSteven Rostedt	my $failed = 0;
34267faafbd6SSteven Rostedt
342764d98283SSteven Rostedt (Red Hat)	start_monitor_and_install or $failed = 1;
34287faafbd6SSteven Rostedt
34297faafbd6SSteven Rostedt	if (!$failed && $type ne "boot"){
34307faafbd6SSteven Rostedt	    do_run_test or $failed = 1;
34317faafbd6SSteven Rostedt	}
34327faafbd6SSteven Rostedt	end_monitor;
343338fa3dc1SSteven Rostedt (Red Hat)	if ($failed) {
343438fa3dc1SSteven Rostedt (Red Hat)	    print_times;
343538fa3dc1SSteven Rostedt (Red Hat)	    return 0;
343638fa3dc1SSteven Rostedt (Red Hat)	}
343727d934b2SSteven Rostedt	patchcheck_reboot;
343838fa3dc1SSteven Rostedt (Red Hat)	print_times;
34396c5ee0beSSteven Rostedt    }
34406c5ee0beSSteven Rostedt    $in_patchcheck = 0;
34416c5ee0beSSteven Rostedt    success $i;
34422b7d9b21SSteven Rostedt
34432b7d9b21SSteven Rostedt    return 1;
34446c5ee0beSSteven Rostedt}
34456c5ee0beSSteven Rostedt
3446b9066f6cSSteven Rostedtmy %depends;
3447ac6974c7SSteven Rostedtmy %depcount;
3448b9066f6cSSteven Rostedtmy $iflevel = 0;
3449b9066f6cSSteven Rostedtmy @ifdeps;
3450b9066f6cSSteven Rostedt
3451b9066f6cSSteven Rostedt# prevent recursion
3452b9066f6cSSteven Rostedtmy %read_kconfigs;
3453b9066f6cSSteven Rostedt
3454ac6974c7SSteven Rostedtsub add_dep {
3455ac6974c7SSteven Rostedt    # $config depends on $dep
3456ac6974c7SSteven Rostedt    my ($config, $dep) = @_;
3457ac6974c7SSteven Rostedt
3458ac6974c7SSteven Rostedt    if (defined($depends{$config})) {
3459ac6974c7SSteven Rostedt	$depends{$config} .= " " . $dep;
3460ac6974c7SSteven Rostedt    } else {
3461ac6974c7SSteven Rostedt	$depends{$config} = $dep;
3462ac6974c7SSteven Rostedt    }
3463ac6974c7SSteven Rostedt
3464ac6974c7SSteven Rostedt    # record the number of configs depending on $dep
3465ac6974c7SSteven Rostedt    if (defined $depcount{$dep}) {
3466ac6974c7SSteven Rostedt	$depcount{$dep}++;
3467ac6974c7SSteven Rostedt    } else {
3468ac6974c7SSteven Rostedt	$depcount{$dep} = 1;
3469ac6974c7SSteven Rostedt    }
3470ac6974c7SSteven Rostedt}
3471ac6974c7SSteven Rostedt
3472b9066f6cSSteven Rostedt# taken from streamline_config.pl
3473b9066f6cSSteven Rostedtsub read_kconfig {
3474b9066f6cSSteven Rostedt    my ($kconfig) = @_;
3475b9066f6cSSteven Rostedt
3476b9066f6cSSteven Rostedt    my $state = "NONE";
3477b9066f6cSSteven Rostedt    my $config;
3478b9066f6cSSteven Rostedt    my @kconfigs;
3479b9066f6cSSteven Rostedt
3480b9066f6cSSteven Rostedt    my $cont = 0;
3481b9066f6cSSteven Rostedt    my $line;
3482b9066f6cSSteven Rostedt
3483b9066f6cSSteven Rostedt
3484b9066f6cSSteven Rostedt    if (! -f $kconfig) {
3485b9066f6cSSteven Rostedt	doprint "file $kconfig does not exist, skipping\n";
3486b9066f6cSSteven Rostedt	return;
3487b9066f6cSSteven Rostedt    }
3488b9066f6cSSteven Rostedt
3489b9066f6cSSteven Rostedt    open(KIN, "$kconfig")
3490b9066f6cSSteven Rostedt	or die "Can't open $kconfig";
3491b9066f6cSSteven Rostedt    while (<KIN>) {
3492b9066f6cSSteven Rostedt	chomp;
3493b9066f6cSSteven Rostedt
3494b9066f6cSSteven Rostedt	# Make sure that lines ending with \ continue
3495b9066f6cSSteven Rostedt	if ($cont) {
3496b9066f6cSSteven Rostedt	    $_ = $line . " " . $_;
3497b9066f6cSSteven Rostedt	}
3498b9066f6cSSteven Rostedt
3499b9066f6cSSteven Rostedt	if (s/\\$//) {
3500b9066f6cSSteven Rostedt	    $cont = 1;
3501b9066f6cSSteven Rostedt	    $line = $_;
3502b9066f6cSSteven Rostedt	    next;
3503b9066f6cSSteven Rostedt	}
3504b9066f6cSSteven Rostedt
3505b9066f6cSSteven Rostedt	$cont = 0;
3506b9066f6cSSteven Rostedt
3507b9066f6cSSteven Rostedt	# collect any Kconfig sources
3508b9066f6cSSteven Rostedt	if (/^source\s*"(.*)"/) {
3509b9066f6cSSteven Rostedt	    $kconfigs[$#kconfigs+1] = $1;
3510b9066f6cSSteven Rostedt	}
3511b9066f6cSSteven Rostedt
3512b9066f6cSSteven Rostedt	# configs found
3513b9066f6cSSteven Rostedt	if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3514b9066f6cSSteven Rostedt	    $state = "NEW";
3515b9066f6cSSteven Rostedt	    $config = $2;
3516b9066f6cSSteven Rostedt
3517b9066f6cSSteven Rostedt	    for (my $i = 0; $i < $iflevel; $i++) {
3518ac6974c7SSteven Rostedt		add_dep $config, $ifdeps[$i];
3519b9066f6cSSteven Rostedt	    }
3520b9066f6cSSteven Rostedt
3521b9066f6cSSteven Rostedt	# collect the depends for the config
3522b9066f6cSSteven Rostedt	} elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3523b9066f6cSSteven Rostedt
3524ac6974c7SSteven Rostedt	    add_dep $config, $1;
3525b9066f6cSSteven Rostedt
3526b9066f6cSSteven Rostedt	# Get the configs that select this config
3527ac6974c7SSteven Rostedt	} elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3528ac6974c7SSteven Rostedt
3529ac6974c7SSteven Rostedt	    # selected by depends on config
3530ac6974c7SSteven Rostedt	    add_dep $1, $config;
3531b9066f6cSSteven Rostedt
3532b9066f6cSSteven Rostedt	# Check for if statements
3533b9066f6cSSteven Rostedt	} elsif (/^if\s+(.*\S)\s*$/) {
3534b9066f6cSSteven Rostedt	    my $deps = $1;
3535b9066f6cSSteven Rostedt	    # remove beginning and ending non text
3536b9066f6cSSteven Rostedt	    $deps =~ s/^[^a-zA-Z0-9_]*//;
3537b9066f6cSSteven Rostedt	    $deps =~ s/[^a-zA-Z0-9_]*$//;
3538b9066f6cSSteven Rostedt
3539b9066f6cSSteven Rostedt	    my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3540b9066f6cSSteven Rostedt
3541b9066f6cSSteven Rostedt	    $ifdeps[$iflevel++] = join ':', @deps;
3542b9066f6cSSteven Rostedt
3543b9066f6cSSteven Rostedt	} elsif (/^endif/) {
3544b9066f6cSSteven Rostedt
3545b9066f6cSSteven Rostedt	    $iflevel-- if ($iflevel);
3546b9066f6cSSteven Rostedt
3547b9066f6cSSteven Rostedt	# stop on "help"
3548b9066f6cSSteven Rostedt	} elsif (/^\s*help\s*$/) {
3549b9066f6cSSteven Rostedt	    $state = "NONE";
3550b9066f6cSSteven Rostedt	}
3551b9066f6cSSteven Rostedt    }
3552b9066f6cSSteven Rostedt    close(KIN);
3553b9066f6cSSteven Rostedt
3554b9066f6cSSteven Rostedt    # read in any configs that were found.
3555b9066f6cSSteven Rostedt    foreach $kconfig (@kconfigs) {
3556b9066f6cSSteven Rostedt	if (!defined($read_kconfigs{$kconfig})) {
3557b9066f6cSSteven Rostedt	    $read_kconfigs{$kconfig} = 1;
3558b9066f6cSSteven Rostedt	    read_kconfig("$builddir/$kconfig");
3559b9066f6cSSteven Rostedt	}
3560b9066f6cSSteven Rostedt    }
3561b9066f6cSSteven Rostedt}
3562b9066f6cSSteven Rostedt
3563b9066f6cSSteven Rostedtsub read_depends {
3564b9066f6cSSteven Rostedt    # find out which arch this is by the kconfig file
3565b9066f6cSSteven Rostedt    open (IN, $output_config)
3566b9066f6cSSteven Rostedt	or dodie "Failed to read $output_config";
3567b9066f6cSSteven Rostedt    my $arch;
3568b9066f6cSSteven Rostedt    while (<IN>) {
3569b9066f6cSSteven Rostedt	if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3570b9066f6cSSteven Rostedt	    $arch = $1;
3571b9066f6cSSteven Rostedt	    last;
3572b9066f6cSSteven Rostedt	}
3573b9066f6cSSteven Rostedt    }
3574b9066f6cSSteven Rostedt    close IN;
3575b9066f6cSSteven Rostedt
3576b9066f6cSSteven Rostedt    if (!defined($arch)) {
3577b9066f6cSSteven Rostedt	doprint "Could not find arch from config file\n";
3578b9066f6cSSteven Rostedt	doprint "no dependencies used\n";
3579b9066f6cSSteven Rostedt	return;
3580b9066f6cSSteven Rostedt    }
3581b9066f6cSSteven Rostedt
3582b9066f6cSSteven Rostedt    # arch is really the subarch, we need to know
3583b9066f6cSSteven Rostedt    # what directory to look at.
3584b9066f6cSSteven Rostedt    if ($arch eq "i386" || $arch eq "x86_64") {
3585b9066f6cSSteven Rostedt	$arch = "x86";
3586b9066f6cSSteven Rostedt    } elsif ($arch =~ /^tile/) {
3587b9066f6cSSteven Rostedt	$arch = "tile";
3588b9066f6cSSteven Rostedt    }
3589b9066f6cSSteven Rostedt
3590b9066f6cSSteven Rostedt    my $kconfig = "$builddir/arch/$arch/Kconfig";
3591b9066f6cSSteven Rostedt
3592b9066f6cSSteven Rostedt    if (! -f $kconfig && $arch =~ /\d$/) {
3593b9066f6cSSteven Rostedt	my $orig = $arch;
3594b9066f6cSSteven Rostedt 	# some subarchs have numbers, truncate them
3595b9066f6cSSteven Rostedt	$arch =~ s/\d*$//;
3596b9066f6cSSteven Rostedt	$kconfig = "$builddir/arch/$arch/Kconfig";
3597b9066f6cSSteven Rostedt	if (! -f $kconfig) {
3598b9066f6cSSteven Rostedt	    doprint "No idea what arch dir $orig is for\n";
3599b9066f6cSSteven Rostedt	    doprint "no dependencies used\n";
3600b9066f6cSSteven Rostedt	    return;
3601b9066f6cSSteven Rostedt	}
3602b9066f6cSSteven Rostedt    }
3603b9066f6cSSteven Rostedt
3604b9066f6cSSteven Rostedt    read_kconfig($kconfig);
3605b9066f6cSSteven Rostedt}
3606b9066f6cSSteven Rostedt
36074c4ab120SSteven Rostedtsub make_new_config {
36084c4ab120SSteven Rostedt    my @configs = @_;
36094c4ab120SSteven Rostedt
36104c4ab120SSteven Rostedt    open (OUT, ">$output_config")
36114c4ab120SSteven Rostedt	or dodie "Failed to write $output_config";
36124c4ab120SSteven Rostedt
36134c4ab120SSteven Rostedt    foreach my $config (@configs) {
36144c4ab120SSteven Rostedt	print OUT "$config\n";
36154c4ab120SSteven Rostedt    }
36164c4ab120SSteven Rostedt    close OUT;
36174c4ab120SSteven Rostedt}
36184c4ab120SSteven Rostedt
3619ac6974c7SSteven Rostedtsub chomp_config {
3620ac6974c7SSteven Rostedt    my ($config) = @_;
3621ac6974c7SSteven Rostedt
3622ac6974c7SSteven Rostedt    $config =~ s/CONFIG_//;
3623ac6974c7SSteven Rostedt
3624ac6974c7SSteven Rostedt    return $config;
3625ac6974c7SSteven Rostedt}
3626ac6974c7SSteven Rostedt
3627b9066f6cSSteven Rostedtsub get_depends {
3628b9066f6cSSteven Rostedt    my ($dep) = @_;
3629b9066f6cSSteven Rostedt
3630ac6974c7SSteven Rostedt    my $kconfig = chomp_config $dep;
3631b9066f6cSSteven Rostedt
3632b9066f6cSSteven Rostedt    $dep = $depends{"$kconfig"};
3633b9066f6cSSteven Rostedt
3634b9066f6cSSteven Rostedt    # the dep string we have saves the dependencies as they
3635b9066f6cSSteven Rostedt    # were found, including expressions like ! && ||. We
3636b9066f6cSSteven Rostedt    # want to split this out into just an array of configs.
3637b9066f6cSSteven Rostedt
3638b9066f6cSSteven Rostedt    my $valid = "A-Za-z_0-9";
3639b9066f6cSSteven Rostedt
3640b9066f6cSSteven Rostedt    my @configs;
3641b9066f6cSSteven Rostedt
3642b9066f6cSSteven Rostedt    while ($dep =~ /[$valid]/) {
3643b9066f6cSSteven Rostedt
3644b9066f6cSSteven Rostedt	if ($dep =~ /^[^$valid]*([$valid]+)/) {
3645b9066f6cSSteven Rostedt	    my $conf = "CONFIG_" . $1;
3646b9066f6cSSteven Rostedt
3647b9066f6cSSteven Rostedt	    $configs[$#configs + 1] = $conf;
3648b9066f6cSSteven Rostedt
3649b9066f6cSSteven Rostedt	    $dep =~ s/^[^$valid]*[$valid]+//;
3650b9066f6cSSteven Rostedt	} else {
3651b9066f6cSSteven Rostedt	    die "this should never happen";
3652b9066f6cSSteven Rostedt	}
3653b9066f6cSSteven Rostedt    }
3654b9066f6cSSteven Rostedt
3655b9066f6cSSteven Rostedt    return @configs;
3656b9066f6cSSteven Rostedt}
3657b9066f6cSSteven Rostedt
3658b9066f6cSSteven Rostedtmy %min_configs;
3659b9066f6cSSteven Rostedtmy %keep_configs;
366043d1b651SSteven Rostedtmy %save_configs;
3661b9066f6cSSteven Rostedtmy %processed_configs;
3662b9066f6cSSteven Rostedtmy %nochange_config;
3663b9066f6cSSteven Rostedt
3664b9066f6cSSteven Rostedtsub test_this_config {
3665b9066f6cSSteven Rostedt    my ($config) = @_;
3666b9066f6cSSteven Rostedt
3667b9066f6cSSteven Rostedt    my $found;
3668b9066f6cSSteven Rostedt
3669b9066f6cSSteven Rostedt    # if we already processed this config, skip it
3670b9066f6cSSteven Rostedt    if (defined($processed_configs{$config})) {
3671b9066f6cSSteven Rostedt	return undef;
3672b9066f6cSSteven Rostedt    }
3673b9066f6cSSteven Rostedt    $processed_configs{$config} = 1;
3674b9066f6cSSteven Rostedt
3675b9066f6cSSteven Rostedt    # if this config failed during this round, skip it
3676b9066f6cSSteven Rostedt    if (defined($nochange_config{$config})) {
3677b9066f6cSSteven Rostedt	return undef;
3678b9066f6cSSteven Rostedt    }
3679b9066f6cSSteven Rostedt
3680ac6974c7SSteven Rostedt    my $kconfig = chomp_config $config;
3681b9066f6cSSteven Rostedt
3682b9066f6cSSteven Rostedt    # Test dependencies first
3683b9066f6cSSteven Rostedt    if (defined($depends{"$kconfig"})) {
3684b9066f6cSSteven Rostedt	my @parents = get_depends $config;
3685b9066f6cSSteven Rostedt	foreach my $parent (@parents) {
3686b9066f6cSSteven Rostedt	    # if the parent is in the min config, check it first
3687b9066f6cSSteven Rostedt	    next if (!defined($min_configs{$parent}));
3688b9066f6cSSteven Rostedt	    $found = test_this_config($parent);
3689b9066f6cSSteven Rostedt	    if (defined($found)) {
3690b9066f6cSSteven Rostedt		return $found;
3691b9066f6cSSteven Rostedt	    }
3692b9066f6cSSteven Rostedt	}
3693b9066f6cSSteven Rostedt    }
3694b9066f6cSSteven Rostedt
3695b9066f6cSSteven Rostedt    # Remove this config from the list of configs
3696fb16d891SAdam Lee    # do a make olddefconfig and then read the resulting
3697b9066f6cSSteven Rostedt    # .config to make sure it is missing the config that
3698b9066f6cSSteven Rostedt    # we had before
3699b9066f6cSSteven Rostedt    my %configs = %min_configs;
3700b9066f6cSSteven Rostedt    delete $configs{$config};
3701b9066f6cSSteven Rostedt    make_new_config ((values %configs), (values %keep_configs));
3702b9066f6cSSteven Rostedt    make_oldconfig;
3703b9066f6cSSteven Rostedt    undef %configs;
3704b9066f6cSSteven Rostedt    assign_configs \%configs, $output_config;
3705b9066f6cSSteven Rostedt
37069972fc0bSSteven Rostedt (Red Hat)    if (!defined($configs{$config}) || $configs{$config} =~ /^#/) {
37079972fc0bSSteven Rostedt (Red Hat)	return $config;
37089972fc0bSSteven Rostedt (Red Hat)    }
3709b9066f6cSSteven Rostedt
3710b9066f6cSSteven Rostedt    doprint "disabling config $config did not change .config\n";
3711b9066f6cSSteven Rostedt
3712b9066f6cSSteven Rostedt    $nochange_config{$config} = 1;
3713b9066f6cSSteven Rostedt
3714b9066f6cSSteven Rostedt    return undef;
3715b9066f6cSSteven Rostedt}
3716b9066f6cSSteven Rostedt
37174c4ab120SSteven Rostedtsub make_min_config {
37184c4ab120SSteven Rostedt    my ($i) = @_;
37194c4ab120SSteven Rostedt
3720ccc513b6SSteven Rostedt    my $type = $minconfig_type;
3721ccc513b6SSteven Rostedt    if ($type ne "boot" && $type ne "test") {
3722ccc513b6SSteven Rostedt	fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3723ccc513b6SSteven Rostedt	    " make_min_config works only with 'boot' and 'test'\n" and return;
3724ccc513b6SSteven Rostedt    }
3725ccc513b6SSteven Rostedt
37264c4ab120SSteven Rostedt    if (!defined($output_minconfig)) {
37274c4ab120SSteven Rostedt	fail "OUTPUT_MIN_CONFIG not defined" and return;
37284c4ab120SSteven Rostedt    }
372935ce5952SSteven Rostedt
373035ce5952SSteven Rostedt    # If output_minconfig exists, and the start_minconfig
373135ce5952SSteven Rostedt    # came from min_config, than ask if we should use
373235ce5952SSteven Rostedt    # that instead.
373335ce5952SSteven Rostedt    if (-f $output_minconfig && !$start_minconfig_defined) {
373435ce5952SSteven Rostedt	print "$output_minconfig exists\n";
373543de3316SSteven Rostedt	if (!defined($use_output_minconfig)) {
373635ce5952SSteven Rostedt	    if (read_yn " Use it as minconfig?") {
373735ce5952SSteven Rostedt		$start_minconfig = $output_minconfig;
373835ce5952SSteven Rostedt	    }
373943de3316SSteven Rostedt	} elsif ($use_output_minconfig > 0) {
374043de3316SSteven Rostedt	    doprint "Using $output_minconfig as MIN_CONFIG\n";
374143de3316SSteven Rostedt	    $start_minconfig = $output_minconfig;
374243de3316SSteven Rostedt	} else {
374343de3316SSteven Rostedt	    doprint "Set to still use MIN_CONFIG as starting point\n";
374443de3316SSteven Rostedt	}
374535ce5952SSteven Rostedt    }
374635ce5952SSteven Rostedt
37474c4ab120SSteven Rostedt    if (!defined($start_minconfig)) {
37484c4ab120SSteven Rostedt	fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
37494c4ab120SSteven Rostedt    }
37504c4ab120SSteven Rostedt
375135ce5952SSteven Rostedt    my $temp_config = "$tmpdir/temp_config";
375235ce5952SSteven Rostedt
37534c4ab120SSteven Rostedt    # First things first. We build an allnoconfig to find
37544c4ab120SSteven Rostedt    # out what the defaults are that we can't touch.
37554c4ab120SSteven Rostedt    # Some are selections, but we really can't handle selections.
37564c4ab120SSteven Rostedt
37574c4ab120SSteven Rostedt    my $save_minconfig = $minconfig;
37584c4ab120SSteven Rostedt    undef $minconfig;
37594c4ab120SSteven Rostedt
37604c4ab120SSteven Rostedt    run_command "$make allnoconfig" or return 0;
37614c4ab120SSteven Rostedt
3762b9066f6cSSteven Rostedt    read_depends;
3763b9066f6cSSteven Rostedt
37644c4ab120SSteven Rostedt    process_config_ignore $output_config;
3765b9066f6cSSteven Rostedt
376643d1b651SSteven Rostedt    undef %save_configs;
3767b9066f6cSSteven Rostedt    undef %min_configs;
37684c4ab120SSteven Rostedt
37694c4ab120SSteven Rostedt    if (defined($ignore_config)) {
37704c4ab120SSteven Rostedt	# make sure the file exists
37714c4ab120SSteven Rostedt	`touch $ignore_config`;
377243d1b651SSteven Rostedt	assign_configs \%save_configs, $ignore_config;
37734c4ab120SSteven Rostedt    }
37744c4ab120SSteven Rostedt
377543d1b651SSteven Rostedt    %keep_configs = %save_configs;
377643d1b651SSteven Rostedt
37774c4ab120SSteven Rostedt    doprint "Load initial configs from $start_minconfig\n";
37784c4ab120SSteven Rostedt
37794c4ab120SSteven Rostedt    # Look at the current min configs, and save off all the
37804c4ab120SSteven Rostedt    # ones that were set via the allnoconfig
37814c4ab120SSteven Rostedt    assign_configs \%min_configs, $start_minconfig;
37824c4ab120SSteven Rostedt
37834c4ab120SSteven Rostedt    my @config_keys = keys %min_configs;
37844c4ab120SSteven Rostedt
3785ac6974c7SSteven Rostedt    # All configs need a depcount
3786ac6974c7SSteven Rostedt    foreach my $config (@config_keys) {
3787ac6974c7SSteven Rostedt	my $kconfig = chomp_config $config;
3788ac6974c7SSteven Rostedt	if (!defined $depcount{$kconfig}) {
3789ac6974c7SSteven Rostedt		$depcount{$kconfig} = 0;
3790ac6974c7SSteven Rostedt	}
3791ac6974c7SSteven Rostedt    }
3792ac6974c7SSteven Rostedt
37934c4ab120SSteven Rostedt    # Remove anything that was set by the make allnoconfig
37944c4ab120SSteven Rostedt    # we shouldn't need them as they get set for us anyway.
37954c4ab120SSteven Rostedt    foreach my $config (@config_keys) {
37964c4ab120SSteven Rostedt	# Remove anything in the ignore_config
37974c4ab120SSteven Rostedt	if (defined($keep_configs{$config})) {
37984c4ab120SSteven Rostedt	    my $file = $ignore_config;
37994c4ab120SSteven Rostedt	    $file =~ s,.*/(.*?)$,$1,;
38004c4ab120SSteven Rostedt	    doprint "$config set by $file ... ignored\n";
38014c4ab120SSteven Rostedt	    delete $min_configs{$config};
38024c4ab120SSteven Rostedt	    next;
38034c4ab120SSteven Rostedt	}
38044c4ab120SSteven Rostedt	# But make sure the settings are the same. If a min config
38054c4ab120SSteven Rostedt	# sets a selection, we do not want to get rid of it if
38064c4ab120SSteven Rostedt	# it is not the same as what we have. Just move it into
38074c4ab120SSteven Rostedt	# the keep configs.
38084c4ab120SSteven Rostedt	if (defined($config_ignore{$config})) {
38094c4ab120SSteven Rostedt	    if ($config_ignore{$config} ne $min_configs{$config}) {
38104c4ab120SSteven Rostedt		doprint "$config is in allnoconfig as '$config_ignore{$config}'";
38114c4ab120SSteven Rostedt		doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
38124c4ab120SSteven Rostedt		$keep_configs{$config} = $min_configs{$config};
38134c4ab120SSteven Rostedt	    } else {
38144c4ab120SSteven Rostedt		doprint "$config set by allnoconfig ... ignored\n";
38154c4ab120SSteven Rostedt	    }
38164c4ab120SSteven Rostedt	    delete $min_configs{$config};
38174c4ab120SSteven Rostedt	}
38184c4ab120SSteven Rostedt    }
38194c4ab120SSteven Rostedt
38204c4ab120SSteven Rostedt    my $done = 0;
3821b9066f6cSSteven Rostedt    my $take_two = 0;
38224c4ab120SSteven Rostedt
38234c4ab120SSteven Rostedt    while (!$done) {
38244c4ab120SSteven Rostedt
38254c4ab120SSteven Rostedt	my $config;
38264c4ab120SSteven Rostedt	my $found;
38274c4ab120SSteven Rostedt
38284c4ab120SSteven Rostedt	# Now disable each config one by one and do a make oldconfig
38294c4ab120SSteven Rostedt	# till we find a config that changes our list.
38304c4ab120SSteven Rostedt
38314c4ab120SSteven Rostedt	my @test_configs = keys %min_configs;
3832ac6974c7SSteven Rostedt
3833ac6974c7SSteven Rostedt	# Sort keys by who is most dependent on
3834ac6974c7SSteven Rostedt	@test_configs = sort  { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3835ac6974c7SSteven Rostedt			  @test_configs ;
3836ac6974c7SSteven Rostedt
3837ac6974c7SSteven Rostedt	# Put configs that did not modify the config at the end.
38384c4ab120SSteven Rostedt	my $reset = 1;
38394c4ab120SSteven Rostedt	for (my $i = 0; $i < $#test_configs; $i++) {
38404c4ab120SSteven Rostedt	    if (!defined($nochange_config{$test_configs[0]})) {
38414c4ab120SSteven Rostedt		$reset = 0;
38424c4ab120SSteven Rostedt		last;
38434c4ab120SSteven Rostedt	    }
38444c4ab120SSteven Rostedt	    # This config didn't change the .config last time.
38454c4ab120SSteven Rostedt	    # Place it at the end
38464c4ab120SSteven Rostedt	    my $config = shift @test_configs;
38474c4ab120SSteven Rostedt	    push @test_configs, $config;
38484c4ab120SSteven Rostedt	}
38494c4ab120SSteven Rostedt
38504c4ab120SSteven Rostedt	# if every test config has failed to modify the .config file
38514c4ab120SSteven Rostedt	# in the past, then reset and start over.
38524c4ab120SSteven Rostedt	if ($reset) {
38534c4ab120SSteven Rostedt	    undef %nochange_config;
38544c4ab120SSteven Rostedt	}
38554c4ab120SSteven Rostedt
3856b9066f6cSSteven Rostedt	undef %processed_configs;
3857b9066f6cSSteven Rostedt
38584c4ab120SSteven Rostedt	foreach my $config (@test_configs) {
38594c4ab120SSteven Rostedt
3860b9066f6cSSteven Rostedt	    $found = test_this_config $config;
38614c4ab120SSteven Rostedt
3862b9066f6cSSteven Rostedt	    last if (defined($found));
38634c4ab120SSteven Rostedt
38644c4ab120SSteven Rostedt	    # oh well, try another config
38654c4ab120SSteven Rostedt	}
38664c4ab120SSteven Rostedt
38674c4ab120SSteven Rostedt	if (!defined($found)) {
3868b9066f6cSSteven Rostedt	    # we could have failed due to the nochange_config hash
3869b9066f6cSSteven Rostedt	    # reset and try again
3870b9066f6cSSteven Rostedt	    if (!$take_two) {
3871b9066f6cSSteven Rostedt		undef %nochange_config;
3872b9066f6cSSteven Rostedt		$take_two = 1;
3873b9066f6cSSteven Rostedt		next;
3874b9066f6cSSteven Rostedt	    }
38754c4ab120SSteven Rostedt	    doprint "No more configs found that we can disable\n";
38764c4ab120SSteven Rostedt	    $done = 1;
38774c4ab120SSteven Rostedt	    last;
38784c4ab120SSteven Rostedt	}
3879b9066f6cSSteven Rostedt	$take_two = 0;
38804c4ab120SSteven Rostedt
38814c4ab120SSteven Rostedt	$config = $found;
38824c4ab120SSteven Rostedt
38834c4ab120SSteven Rostedt	doprint "Test with $config disabled\n";
38844c4ab120SSteven Rostedt
38854c4ab120SSteven Rostedt	# set in_bisect to keep build and monitor from dieing
38864c4ab120SSteven Rostedt	$in_bisect = 1;
38874c4ab120SSteven Rostedt
38884c4ab120SSteven Rostedt	my $failed = 0;
3889bf1c95abSSteven Rostedt	build "oldconfig" or $failed = 1;
3890bf1c95abSSteven Rostedt	if (!$failed) {
389164d98283SSteven Rostedt (Red Hat)		start_monitor_and_install or $failed = 1;
3892ccc513b6SSteven Rostedt
3893ccc513b6SSteven Rostedt		if ($type eq "test" && !$failed) {
3894ccc513b6SSteven Rostedt		    do_run_test or $failed = 1;
3895ccc513b6SSteven Rostedt		}
3896ccc513b6SSteven Rostedt
38974c4ab120SSteven Rostedt		end_monitor;
3898bf1c95abSSteven Rostedt	}
38994c4ab120SSteven Rostedt
39004c4ab120SSteven Rostedt	$in_bisect = 0;
39014c4ab120SSteven Rostedt
39024c4ab120SSteven Rostedt	if ($failed) {
3903b9066f6cSSteven Rostedt	    doprint "$min_configs{$config} is needed to boot the box... keeping\n";
39044c4ab120SSteven Rostedt	    # this config is needed, add it to the ignore list.
39054c4ab120SSteven Rostedt	    $keep_configs{$config} = $min_configs{$config};
390643d1b651SSteven Rostedt	    $save_configs{$config} = $min_configs{$config};
39074c4ab120SSteven Rostedt	    delete $min_configs{$config};
390835ce5952SSteven Rostedt
390935ce5952SSteven Rostedt	    # update new ignore configs
391035ce5952SSteven Rostedt	    if (defined($ignore_config)) {
391135ce5952SSteven Rostedt		open (OUT, ">$temp_config")
391235ce5952SSteven Rostedt		    or die "Can't write to $temp_config";
391343d1b651SSteven Rostedt		foreach my $config (keys %save_configs) {
391443d1b651SSteven Rostedt		    print OUT "$save_configs{$config}\n";
391535ce5952SSteven Rostedt		}
391635ce5952SSteven Rostedt		close OUT;
391735ce5952SSteven Rostedt		run_command "mv $temp_config $ignore_config" or
391835ce5952SSteven Rostedt		    dodie "failed to copy update to $ignore_config";
391935ce5952SSteven Rostedt	    }
392035ce5952SSteven Rostedt
39214c4ab120SSteven Rostedt	} else {
39224c4ab120SSteven Rostedt	    # We booted without this config, remove it from the minconfigs.
39234c4ab120SSteven Rostedt	    doprint "$config is not needed, disabling\n";
39244c4ab120SSteven Rostedt
39254c4ab120SSteven Rostedt	    delete $min_configs{$config};
39264c4ab120SSteven Rostedt
39274c4ab120SSteven Rostedt	    # Also disable anything that is not enabled in this config
39284c4ab120SSteven Rostedt	    my %configs;
39294c4ab120SSteven Rostedt	    assign_configs \%configs, $output_config;
39304c4ab120SSteven Rostedt	    my @config_keys = keys %min_configs;
39314c4ab120SSteven Rostedt	    foreach my $config (@config_keys) {
39324c4ab120SSteven Rostedt		if (!defined($configs{$config})) {
39334c4ab120SSteven Rostedt		    doprint "$config is not set, disabling\n";
39344c4ab120SSteven Rostedt		    delete $min_configs{$config};
39354c4ab120SSteven Rostedt		}
39364c4ab120SSteven Rostedt	    }
39374c4ab120SSteven Rostedt
393822722799SPavel Machek	    # Save off all the current mandatory configs
393935ce5952SSteven Rostedt	    open (OUT, ">$temp_config")
394035ce5952SSteven Rostedt		or die "Can't write to $temp_config";
39414c4ab120SSteven Rostedt	    foreach my $config (keys %keep_configs) {
39424c4ab120SSteven Rostedt		print OUT "$keep_configs{$config}\n";
39434c4ab120SSteven Rostedt	    }
39444c4ab120SSteven Rostedt	    foreach my $config (keys %min_configs) {
39454c4ab120SSteven Rostedt		print OUT "$min_configs{$config}\n";
39464c4ab120SSteven Rostedt	    }
39474c4ab120SSteven Rostedt	    close OUT;
394835ce5952SSteven Rostedt
394935ce5952SSteven Rostedt	    run_command "mv $temp_config $output_minconfig" or
395035ce5952SSteven Rostedt		dodie "failed to copy update to $output_minconfig";
39514c4ab120SSteven Rostedt	}
39524c4ab120SSteven Rostedt
39534c4ab120SSteven Rostedt	doprint "Reboot and wait $sleep_time seconds\n";
3954bc7c5803SSteven Rostedt	reboot_to_good $sleep_time;
39554c4ab120SSteven Rostedt    }
39564c4ab120SSteven Rostedt
39574c4ab120SSteven Rostedt    success $i;
39584c4ab120SSteven Rostedt    return 1;
39594c4ab120SSteven Rostedt}
39604c4ab120SSteven Rostedt
39614283b169SSteven Rostedt (Red Hat)sub make_warnings_file {
39624283b169SSteven Rostedt (Red Hat)    my ($i) = @_;
39634283b169SSteven Rostedt (Red Hat)
39644283b169SSteven Rostedt (Red Hat)    if (!defined($warnings_file)) {
39654283b169SSteven Rostedt (Red Hat)	dodie "Must define WARNINGS_FILE for make_warnings_file test";
39664283b169SSteven Rostedt (Red Hat)    }
39674283b169SSteven Rostedt (Red Hat)
39684283b169SSteven Rostedt (Red Hat)    if ($build_type eq "nobuild") {
39694283b169SSteven Rostedt (Red Hat)	dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
39704283b169SSteven Rostedt (Red Hat)    }
39714283b169SSteven Rostedt (Red Hat)
39724283b169SSteven Rostedt (Red Hat)    build $build_type or dodie "Failed to build";
39734283b169SSteven Rostedt (Red Hat)
39744283b169SSteven Rostedt (Red Hat)    open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
39754283b169SSteven Rostedt (Red Hat)
39764283b169SSteven Rostedt (Red Hat)    open(IN, $buildlog) or dodie "Can't open $buildlog";
39774283b169SSteven Rostedt (Red Hat)    while (<IN>) {
39784283b169SSteven Rostedt (Red Hat)
39794283b169SSteven Rostedt (Red Hat)	# Some compilers use UTF-8 extended for quotes
39804283b169SSteven Rostedt (Red Hat)	# for distcc heterogeneous systems, this causes issues
39814283b169SSteven Rostedt (Red Hat)	s/$utf8_quote/'/g;
39824283b169SSteven Rostedt (Red Hat)
39834283b169SSteven Rostedt (Red Hat)	if (/$check_build_re/) {
39844283b169SSteven Rostedt (Red Hat)	    print OUT;
39854283b169SSteven Rostedt (Red Hat)	}
39864283b169SSteven Rostedt (Red Hat)    }
39874283b169SSteven Rostedt (Red Hat)    close(IN);
39884283b169SSteven Rostedt (Red Hat)
39894283b169SSteven Rostedt (Red Hat)    close(OUT);
39904283b169SSteven Rostedt (Red Hat)
39914283b169SSteven Rostedt (Red Hat)    success $i;
39924283b169SSteven Rostedt (Red Hat)}
39934283b169SSteven Rostedt (Red Hat)
39945269faadSSatoru Takeuchi$#ARGV < 1 or die "ktest.pl version: $VERSION\n   usage: ktest.pl [config-file]\n";
39952545eb61SSteven Rostedt
39968d1491baSSteven Rostedtif ($#ARGV == 0) {
39978d1491baSSteven Rostedt    $ktest_config = $ARGV[0];
39988d1491baSSteven Rostedt    if (! -f $ktest_config) {
39998d1491baSSteven Rostedt	print "$ktest_config does not exist.\n";
400035ce5952SSteven Rostedt	if (!read_yn "Create it?") {
40018d1491baSSteven Rostedt	    exit 0;
40028d1491baSSteven Rostedt	}
40038d1491baSSteven Rostedt    }
40048d1491baSSteven Rostedt}
40058d1491baSSteven Rostedt
40068d1491baSSteven Rostedtif (! -f $ktest_config) {
4007dbd3783bSSteven Rostedt    $newconfig = 1;
4008c4261d0fSSteven Rostedt    get_test_case;
40098d1491baSSteven Rostedt    open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
40108d1491baSSteven Rostedt    print OUT << "EOF"
40118d1491baSSteven Rostedt# Generated by ktest.pl
40128d1491baSSteven Rostedt#
40130e7a22deSSteven Rostedt
40140e7a22deSSteven Rostedt# PWD is a ktest.pl variable that will result in the process working
40150e7a22deSSteven Rostedt# directory that ktest.pl is executed in.
40160e7a22deSSteven Rostedt
40170e7a22deSSteven Rostedt# THIS_DIR is automatically assigned the PWD of the path that generated
40180e7a22deSSteven Rostedt# the config file. It is best to use this variable when assigning other
40190e7a22deSSteven Rostedt# directory paths within this directory. This allows you to easily
40200e7a22deSSteven Rostedt# move the test cases to other locations or to other machines.
40210e7a22deSSteven Rostedt#
40220e7a22deSSteven RostedtTHIS_DIR := $variable{"PWD"}
40230e7a22deSSteven Rostedt
40248d1491baSSteven Rostedt# Define each test with TEST_START
40258d1491baSSteven Rostedt# The config options below it will override the defaults
40268d1491baSSteven RostedtTEST_START
4027c4261d0fSSteven RostedtTEST_TYPE = $default{"TEST_TYPE"}
40288d1491baSSteven Rostedt
40298d1491baSSteven RostedtDEFAULTS
40308d1491baSSteven RostedtEOF
40318d1491baSSteven Rostedt;
40328d1491baSSteven Rostedt    close(OUT);
40338d1491baSSteven Rostedt}
40348d1491baSSteven Rostedtread_config $ktest_config;
40358d1491baSSteven Rostedt
403623715c3cSSteven Rostedtif (defined($opt{"LOG_FILE"})) {
403704262be3SSteven Rostedt (Red Hat)    $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
403823715c3cSSteven Rostedt}
403923715c3cSSteven Rostedt
40408d1491baSSteven Rostedt# Append any configs entered in manually to the config file.
40418d1491baSSteven Rostedtmy @new_configs = keys %entered_configs;
40428d1491baSSteven Rostedtif ($#new_configs >= 0) {
40438d1491baSSteven Rostedt    print "\nAppending entered in configs to $ktest_config\n";
40448d1491baSSteven Rostedt    open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
40458d1491baSSteven Rostedt    foreach my $config (@new_configs) {
40468d1491baSSteven Rostedt	print OUT "$config = $entered_configs{$config}\n";
40470e7a22deSSteven Rostedt	$opt{$config} = process_variables($entered_configs{$config});
40488d1491baSSteven Rostedt    }
40498d1491baSSteven Rostedt}
40502545eb61SSteven Rostedt
40512b7d9b21SSteven Rostedtif ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
40522b7d9b21SSteven Rostedt    unlink $opt{"LOG_FILE"};
40532b7d9b21SSteven Rostedt}
40542545eb61SSteven Rostedt
40552b7d9b21SSteven Rostedtdoprint "\n\nSTARTING AUTOMATED TESTS\n\n";
40562b7d9b21SSteven Rostedt
4057a57419b3SSteven Rostedtfor (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
4058a57419b3SSteven Rostedt
4059a57419b3SSteven Rostedt    if (!$i) {
4060a57419b3SSteven Rostedt	doprint "DEFAULT OPTIONS:\n";
4061a57419b3SSteven Rostedt    } else {
4062a57419b3SSteven Rostedt	doprint "\nTEST $i OPTIONS";
4063a57419b3SSteven Rostedt	if (defined($repeat_tests{$i})) {
4064a57419b3SSteven Rostedt	    $repeat = $repeat_tests{$i};
4065a57419b3SSteven Rostedt	    doprint " ITERATE $repeat";
4066a57419b3SSteven Rostedt	}
4067a57419b3SSteven Rostedt	doprint "\n";
4068a57419b3SSteven Rostedt    }
4069a57419b3SSteven Rostedt
40702b7d9b21SSteven Rostedt    foreach my $option (sort keys %opt) {
4071a57419b3SSteven Rostedt
4072a57419b3SSteven Rostedt	if ($option =~ /\[(\d+)\]$/) {
4073a57419b3SSteven Rostedt	    next if ($i != $1);
4074a57419b3SSteven Rostedt	} else {
4075a57419b3SSteven Rostedt	    next if ($i);
4076a57419b3SSteven Rostedt	}
4077a57419b3SSteven Rostedt
40782b7d9b21SSteven Rostedt	doprint "$option = $opt{$option}\n";
40792b7d9b21SSteven Rostedt    }
4080a57419b3SSteven Rostedt}
40812545eb61SSteven Rostedt
408222c37a9aSSteven Rostedt (Red Hat)sub option_defined {
408322c37a9aSSteven Rostedt (Red Hat)    my ($option) = @_;
408422c37a9aSSteven Rostedt (Red Hat)
408522c37a9aSSteven Rostedt (Red Hat)    if (defined($opt{$option}) && $opt{$option} !~ /^\s*$/) {
408622c37a9aSSteven Rostedt (Red Hat)	return 1;
408722c37a9aSSteven Rostedt (Red Hat)    }
408822c37a9aSSteven Rostedt (Red Hat)
408922c37a9aSSteven Rostedt (Red Hat)    return 0;
409022c37a9aSSteven Rostedt (Red Hat)}
409122c37a9aSSteven Rostedt (Red Hat)
40922a62512bSSteven Rostedtsub __set_test_option {
40935a391fbfSSteven Rostedt    my ($name, $i) = @_;
40945a391fbfSSteven Rostedt
40955a391fbfSSteven Rostedt    my $option = "$name\[$i\]";
40965a391fbfSSteven Rostedt
409722c37a9aSSteven Rostedt (Red Hat)    if (option_defined($option)) {
40985a391fbfSSteven Rostedt	return $opt{$option};
40995a391fbfSSteven Rostedt    }
41005a391fbfSSteven Rostedt
4101a57419b3SSteven Rostedt    foreach my $test (keys %repeat_tests) {
4102a57419b3SSteven Rostedt	if ($i >= $test &&
4103a57419b3SSteven Rostedt	    $i < $test + $repeat_tests{$test}) {
4104a57419b3SSteven Rostedt	    $option = "$name\[$test\]";
410522c37a9aSSteven Rostedt (Red Hat)	    if (option_defined($option)) {
4106a57419b3SSteven Rostedt		return $opt{$option};
4107a57419b3SSteven Rostedt	    }
4108a57419b3SSteven Rostedt	}
4109a57419b3SSteven Rostedt    }
4110a57419b3SSteven Rostedt
411122c37a9aSSteven Rostedt (Red Hat)    if (option_defined($name)) {
41125a391fbfSSteven Rostedt	return $opt{$name};
41135a391fbfSSteven Rostedt    }
41145a391fbfSSteven Rostedt
41155a391fbfSSteven Rostedt    return undef;
41165a391fbfSSteven Rostedt}
41175a391fbfSSteven Rostedt
41182a62512bSSteven Rostedtsub set_test_option {
41192a62512bSSteven Rostedt    my ($name, $i) = @_;
41202a62512bSSteven Rostedt
41212a62512bSSteven Rostedt    my $option = __set_test_option($name, $i);
41222a62512bSSteven Rostedt    return $option if (!defined($option));
41232a62512bSSteven Rostedt
412404262be3SSteven Rostedt (Red Hat)    return eval_option($name, $option, $i);
41252a62512bSSteven Rostedt}
41262a62512bSSteven Rostedt
4127*2ceb2d85STim Tianyang Chensub _mailx_send {
4128*2ceb2d85STim Tianyang Chen    my ($subject, $message) = @_;
4129*2ceb2d85STim Tianyang Chen    system("$mailer -s \'$subject\' $mailto <<< \'$message\'");
4130*2ceb2d85STim Tianyang Chen}
4131*2ceb2d85STim Tianyang Chen
4132*2ceb2d85STim Tianyang Chensub _sendmail_send {
4133*2ceb2d85STim Tianyang Chen    my ($subject, $message) = @_;
4134*2ceb2d85STim Tianyang Chen    system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto");
4135*2ceb2d85STim Tianyang Chen}
4136*2ceb2d85STim Tianyang Chen
4137*2ceb2d85STim Tianyang Chensub send_email {
4138*2ceb2d85STim Tianyang Chen    if (defined($mailto) && defined($mailer)) {
4139*2ceb2d85STim Tianyang Chen        if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);}
4140*2ceb2d85STim Tianyang Chen        elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);}
4141*2ceb2d85STim Tianyang Chen        else { doprint "\nYour mailer: $mailer is not supported.\n" }
4142*2ceb2d85STim Tianyang Chen    } else {
4143*2ceb2d85STim Tianyang Chen        print "No email sent: email or mailer not specified in config.\n"
4144*2ceb2d85STim Tianyang Chen    }
4145*2ceb2d85STim Tianyang Chen}
4146*2ceb2d85STim Tianyang Chen
41472545eb61SSteven Rostedt# First we need to do is the builds
4148a75fececSSteven Rostedtfor (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
41492545eb61SSteven Rostedt
41504ab1cce5SSteven Rostedt    # Do not reboot on failing test options
41514ab1cce5SSteven Rostedt    $no_reboot = 1;
4152759a3cc6SSteven Rostedt    $reboot_success = 0;
41534ab1cce5SSteven Rostedt
4154683a3e64SSteven Rostedt    $have_version = 0;
4155683a3e64SSteven Rostedt
4156576f627cSSteven Rostedt    $iteration = $i;
4157576f627cSSteven Rostedt
415838fa3dc1SSteven Rostedt (Red Hat)    $build_time = 0;
415938fa3dc1SSteven Rostedt (Red Hat)    $install_time = 0;
416038fa3dc1SSteven Rostedt (Red Hat)    $reboot_time = 0;
416138fa3dc1SSteven Rostedt (Red Hat)    $test_time = 0;
416238fa3dc1SSteven Rostedt (Red Hat)
4163c1434dccSSteven Rostedt    undef %force_config;
4164c1434dccSSteven Rostedt
4165a75fececSSteven Rostedt    my $makecmd = set_test_option("MAKE_CMD", $i);
4166a75fececSSteven Rostedt
41678e80bf05SSteven Rostedt (Red Hat)    $outputdir = set_test_option("OUTPUT_DIR", $i);
41688e80bf05SSteven Rostedt (Red Hat)    $builddir = set_test_option("BUILD_DIR", $i);
41698e80bf05SSteven Rostedt (Red Hat)
41708e80bf05SSteven Rostedt (Red Hat)    chdir $builddir || die "can't change directory to $builddir";
41718e80bf05SSteven Rostedt (Red Hat)
41728e80bf05SSteven Rostedt (Red Hat)    if (!-d $outputdir) {
41738e80bf05SSteven Rostedt (Red Hat)	mkpath($outputdir) or
41748e80bf05SSteven Rostedt (Red Hat)	    die "can't create $outputdir";
41758e80bf05SSteven Rostedt (Red Hat)    }
41768e80bf05SSteven Rostedt (Red Hat)
41778e80bf05SSteven Rostedt (Red Hat)    $make = "$makecmd O=$outputdir";
41788e80bf05SSteven Rostedt (Red Hat)
41799cc9e091SSteven Rostedt    # Load all the options into their mapped variable names
41809cc9e091SSteven Rostedt    foreach my $opt (keys %option_map) {
41819cc9e091SSteven Rostedt	${$option_map{$opt}} = set_test_option($opt, $i);
41829cc9e091SSteven Rostedt    }
4183b5f4aea6SSteven Rostedt
418435ce5952SSteven Rostedt    $start_minconfig_defined = 1;
418535ce5952SSteven Rostedt
4186921ed4c7SSteven Rostedt    # The first test may override the PRE_KTEST option
4187*2ceb2d85STim Tianyang Chen    if ($i == 1) {
4188*2ceb2d85STim Tianyang Chen        if (defined($pre_ktest)) {
4189921ed4c7SSteven Rostedt            doprint "\n";
4190921ed4c7SSteven Rostedt            run_command $pre_ktest;
4191921ed4c7SSteven Rostedt        }
4192*2ceb2d85STim Tianyang Chen        if ($email_when_started) {
4193*2ceb2d85STim Tianyang Chen            send_email("KTEST: Your [$test_type] test was started",
4194*2ceb2d85STim Tianyang Chen                "Your test was started on $script_start_time");
4195*2ceb2d85STim Tianyang Chen        }
4196*2ceb2d85STim Tianyang Chen    }
4197921ed4c7SSteven Rostedt
4198921ed4c7SSteven Rostedt    # Any test can override the POST_KTEST option
4199921ed4c7SSteven Rostedt    # The last test takes precedence.
4200921ed4c7SSteven Rostedt    if (defined($post_ktest)) {
4201921ed4c7SSteven Rostedt	$final_post_ktest = $post_ktest;
4202921ed4c7SSteven Rostedt    }
4203921ed4c7SSteven Rostedt
42044c4ab120SSteven Rostedt    if (!defined($start_minconfig)) {
420535ce5952SSteven Rostedt	$start_minconfig_defined = 0;
42064c4ab120SSteven Rostedt	$start_minconfig = $minconfig;
42074c4ab120SSteven Rostedt    }
42084c4ab120SSteven Rostedt
42098e80bf05SSteven Rostedt (Red Hat)    if (!-d $tmpdir) {
42108e80bf05SSteven Rostedt (Red Hat)	mkpath($tmpdir) or
42118e80bf05SSteven Rostedt (Red Hat)	    die "can't create $tmpdir";
4212a75fececSSteven Rostedt    }
4213a75fececSSteven Rostedt
4214e48c5293SSteven Rostedt    $ENV{"SSH_USER"} = $ssh_user;
4215e48c5293SSteven Rostedt    $ENV{"MACHINE"} = $machine;
4216e48c5293SSteven Rostedt
4217a75fececSSteven Rostedt    $buildlog = "$tmpdir/buildlog-$machine";
4218a9dd5d63SRabin Vincent    $testlog = "$tmpdir/testlog-$machine";
4219a75fececSSteven Rostedt    $dmesg = "$tmpdir/dmesg-$machine";
422051ad1dd1SSteven Rostedt    $output_config = "$outputdir/.config";
4221a75fececSSteven Rostedt
4222bb8474b1SSteven Rostedt    if (!$buildonly) {
4223bb8474b1SSteven Rostedt	$target = "$ssh_user\@$machine";
4224a75fececSSteven Rostedt	if ($reboot_type eq "grub") {
4225576f627cSSteven Rostedt	    dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4226a15ba913SSteven Rostedt	} elsif ($reboot_type eq "grub2") {
4227a15ba913SSteven Rostedt	    dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4228a15ba913SSteven Rostedt	    dodie "GRUB_FILE not defined" if (!defined($grub_file));
42297786954cSSteven Rostedt	} elsif ($reboot_type eq "syslinux") {
42307786954cSSteven Rostedt	    dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
4231a75fececSSteven Rostedt	}
4232bb8474b1SSteven Rostedt    }
4233a75fececSSteven Rostedt
4234a75fececSSteven Rostedt    my $run_type = $build_type;
4235a75fececSSteven Rostedt    if ($test_type eq "patchcheck") {
4236b5f4aea6SSteven Rostedt	$run_type = $patchcheck_type;
4237a75fececSSteven Rostedt    } elsif ($test_type eq "bisect") {
4238b5f4aea6SSteven Rostedt	$run_type = $bisect_type;
42390a05c769SSteven Rostedt    } elsif ($test_type eq "config_bisect") {
4240b5f4aea6SSteven Rostedt	$run_type = $config_bisect_type;
42414283b169SSteven Rostedt (Red Hat)    } elsif ($test_type eq "make_min_config") {
42424283b169SSteven Rostedt (Red Hat)	$run_type = "";
42434283b169SSteven Rostedt (Red Hat)    } elsif ($test_type eq "make_warnings_file") {
42444c4ab120SSteven Rostedt	$run_type = "";
42454c4ab120SSteven Rostedt    }
42464c4ab120SSteven Rostedt
4247a75fececSSteven Rostedt    # mistake in config file?
4248a75fececSSteven Rostedt    if (!defined($run_type)) {
4249a75fececSSteven Rostedt	$run_type = "ERROR";
4250a75fececSSteven Rostedt    }
42512545eb61SSteven Rostedt
4252e0a8742eSSteven Rostedt    my $installme = "";
4253e0a8742eSSteven Rostedt    $installme = " no_install" if ($no_install);
4254e0a8742eSSteven Rostedt
425518656c70SSteven Rostedt (Red Hat)    my $name = "";
425618656c70SSteven Rostedt (Red Hat)
425718656c70SSteven Rostedt (Red Hat)    if (defined($test_name)) {
425818656c70SSteven Rostedt (Red Hat)	$name = " ($test_name)";
425918656c70SSteven Rostedt (Red Hat)    }
426018656c70SSteven Rostedt (Red Hat)
42612545eb61SSteven Rostedt    doprint "\n\n";
426218656c70SSteven Rostedt (Red Hat)    doprint "RUNNING TEST $i of $opt{NUM_TESTS}$name with option $test_type $run_type$installme\n\n";
42637faafbd6SSteven Rostedt
4264921ed4c7SSteven Rostedt    if (defined($pre_test)) {
4265921ed4c7SSteven Rostedt	run_command $pre_test;
4266921ed4c7SSteven Rostedt    }
4267921ed4c7SSteven Rostedt
42687faafbd6SSteven Rostedt    unlink $dmesg;
42697faafbd6SSteven Rostedt    unlink $buildlog;
4270a9dd5d63SRabin Vincent    unlink $testlog;
42712545eb61SSteven Rostedt
4272250bae8bSSteven Rostedt    if (defined($addconfig)) {
4273250bae8bSSteven Rostedt	my $min = $minconfig;
42742b7d9b21SSteven Rostedt	if (!defined($minconfig)) {
4275250bae8bSSteven Rostedt	    $min = "";
4276250bae8bSSteven Rostedt	}
4277250bae8bSSteven Rostedt	run_command "cat $addconfig $min > $tmpdir/add_config" or
42782b7d9b21SSteven Rostedt	    dodie "Failed to create temp config";
42799be2e6b5SSteven Rostedt	$minconfig = "$tmpdir/add_config";
42802b7d9b21SSteven Rostedt    }
42812b7d9b21SSteven Rostedt
42826c5ee0beSSteven Rostedt    if (defined($checkout)) {
42836c5ee0beSSteven Rostedt	run_command "git checkout $checkout" or
42846c5ee0beSSteven Rostedt	    die "failed to checkout $checkout";
42856c5ee0beSSteven Rostedt    }
42866c5ee0beSSteven Rostedt
4287759a3cc6SSteven Rostedt    $no_reboot = 0;
4288759a3cc6SSteven Rostedt
4289648a182cSSteven Rostedt    # A test may opt to not reboot the box
4290648a182cSSteven Rostedt    if ($reboot_on_success) {
4291759a3cc6SSteven Rostedt	$reboot_success = 1;
4292648a182cSSteven Rostedt    }
42934ab1cce5SSteven Rostedt
4294a75fececSSteven Rostedt    if ($test_type eq "bisect") {
42955f9b6cedSSteven Rostedt	bisect $i;
42965f9b6cedSSteven Rostedt	next;
42970a05c769SSteven Rostedt    } elsif ($test_type eq "config_bisect") {
42980a05c769SSteven Rostedt	config_bisect $i;
42990a05c769SSteven Rostedt	next;
4300a75fececSSteven Rostedt    } elsif ($test_type eq "patchcheck") {
43016c5ee0beSSteven Rostedt	patchcheck $i;
43026c5ee0beSSteven Rostedt	next;
43034c4ab120SSteven Rostedt    } elsif ($test_type eq "make_min_config") {
43044c4ab120SSteven Rostedt	make_min_config $i;
43054c4ab120SSteven Rostedt	next;
43064283b169SSteven Rostedt (Red Hat)    } elsif ($test_type eq "make_warnings_file") {
43074283b169SSteven Rostedt (Red Hat)	$no_reboot = 1;
43084283b169SSteven Rostedt (Red Hat)	make_warnings_file $i;
43094283b169SSteven Rostedt (Red Hat)	next;
43105f9b6cedSSteven Rostedt    }
43115f9b6cedSSteven Rostedt
43127faafbd6SSteven Rostedt    if ($build_type ne "nobuild") {
43137faafbd6SSteven Rostedt	build $build_type or next;
43144283b169SSteven Rostedt (Red Hat)	check_buildlog or next;
43152545eb61SSteven Rostedt    }
43162545eb61SSteven Rostedt
4317cd8e368fSSteven Rostedt    if ($test_type eq "install") {
4318cd8e368fSSteven Rostedt	get_version;
4319cd8e368fSSteven Rostedt	install;
4320cd8e368fSSteven Rostedt	success $i;
4321cd8e368fSSteven Rostedt	next;
4322cd8e368fSSteven Rostedt    }
4323cd8e368fSSteven Rostedt
4324a75fececSSteven Rostedt    if ($test_type ne "build") {
43257faafbd6SSteven Rostedt	my $failed = 0;
432664d98283SSteven Rostedt (Red Hat)	start_monitor_and_install or $failed = 1;
4327a75fececSSteven Rostedt
4328a75fececSSteven Rostedt	if (!$failed && $test_type ne "boot" && defined($run_test)) {
43297faafbd6SSteven Rostedt	    do_run_test or $failed = 1;
43305a391fbfSSteven Rostedt	}
43317faafbd6SSteven Rostedt	end_monitor;
433238fa3dc1SSteven Rostedt (Red Hat)	if ($failed) {
433338fa3dc1SSteven Rostedt (Red Hat)	    print_times;
433438fa3dc1SSteven Rostedt (Red Hat)	    next;
4335a75fececSSteven Rostedt	}
433638fa3dc1SSteven Rostedt (Red Hat)    }
433738fa3dc1SSteven Rostedt (Red Hat)
433838fa3dc1SSteven Rostedt (Red Hat)    print_times;
43395a391fbfSSteven Rostedt
43405f9b6cedSSteven Rostedt    success $i;
434175c3fda7SSteven Rostedt}
43422545eb61SSteven Rostedt
4343921ed4c7SSteven Rostedtif (defined($final_post_ktest)) {
4344921ed4c7SSteven Rostedt    run_command $final_post_ktest;
4345921ed4c7SSteven Rostedt}
4346921ed4c7SSteven Rostedt
43475c42fc5bSSteven Rostedtif ($opt{"POWEROFF_ON_SUCCESS"}) {
434875c3fda7SSteven Rostedt    halt;
4349759a3cc6SSteven Rostedt} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
4350bc7c5803SSteven Rostedt    reboot_to_good;
4351648a182cSSteven Rostedt} elsif (defined($switch_to_good)) {
4352648a182cSSteven Rostedt    # still need to get to the good kernel
4353648a182cSSteven Rostedt    run_command $switch_to_good;
43545c42fc5bSSteven Rostedt}
435575c3fda7SSteven Rostedt
4356648a182cSSteven Rostedt
4357e48c5293SSteven Rostedtdoprint "\n    $successes of $opt{NUM_TESTS} tests were successful\n\n";
4358e48c5293SSteven Rostedt
4359*2ceb2d85STim Tianyang Chenif ($email_when_finished) {
4360*2ceb2d85STim Tianyang Chen    send_email("KTEST: Your [$test_type] test has finished!",
4361*2ceb2d85STim Tianyang Chen            "$successes of $opt{NUM_TESTS} tests started at $script_start_time were successful!");
4362*2ceb2d85STim Tianyang Chen}
43632545eb61SSteven Rostedtexit 0;
4364