4528 lines · 100.3 KB · Perl
RawDownload
#!/usr/bin/perl -w# SPDX-License-Identifier: GPL-2.0-only## Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.# use strict;use IPC::Open2;use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);use File::Path qw(mkpath);use File::Copy qw(cp);use FileHandle;use FindBin;use IO::Handle; my $VERSION = "0.2"; $| = 1; my %opt;my %repeat_tests;my %repeats;my %evals; #default optsmy %default = (    "MAILER"			=> "sendmail",	# default mailer    "EMAIL_ON_ERROR"		=> 1,    "EMAIL_WHEN_FINISHED"	=> 1,    "EMAIL_WHEN_CANCELED"	=> 0,    "EMAIL_WHEN_STARTED"	=> 0,    "NUM_TESTS"			=> 1,    "TEST_TYPE"			=> "build",    "BUILD_TYPE"		=> "oldconfig",    "MAKE_CMD"			=> "make",    "CLOSE_CONSOLE_SIGNAL"	=> "INT",    "TIMEOUT"			=> 120,    "TMP_DIR"			=> "/tmp/ktest/\${MACHINE}",    "SLEEP_TIME"		=> 60,		# sleep time between tests    "BUILD_NOCLEAN"		=> 0,    "REBOOT_ON_ERROR"		=> 0,    "POWEROFF_ON_ERROR"		=> 0,    "REBOOT_ON_SUCCESS"		=> 1,    "POWEROFF_ON_SUCCESS"	=> 0,    "BUILD_OPTIONS"		=> "",    "BISECT_SLEEP_TIME"		=> 60,		# sleep time between bisects    "PATCHCHECK_SLEEP_TIME"	=> 60, 		# sleep time between patch checks    "CLEAR_LOG"			=> 0,    "BISECT_MANUAL"		=> 0,    "BISECT_SKIP"		=> 1,    "BISECT_TRIES"		=> 1,    "MIN_CONFIG_TYPE"		=> "boot",    "SUCCESS_LINE"		=> "login:",    "DETECT_TRIPLE_FAULT"	=> 1,    "NO_INSTALL"		=> 0,    "BOOTED_TIMEOUT"		=> 1,    "DIE_ON_FAILURE"		=> 1,    "SSH_EXEC"			=> "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",    "SCP_TO_TARGET"		=> "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",    "SCP_TO_TARGET_INSTALL"	=> "\${SCP_TO_TARGET}",    "REBOOT"			=> "ssh \$SSH_USER\@\$MACHINE reboot",    "REBOOT_RETURN_CODE"	=> 255,    "STOP_AFTER_SUCCESS"	=> 10,    "STOP_AFTER_FAILURE"	=> 60,    "STOP_TEST_AFTER"		=> 600,    "MAX_MONITOR_WAIT"		=> 1800,    "GRUB_REBOOT"		=> "grub2-reboot",    "GRUB_BLS_GET"		=> "grubby --info=ALL",    "SYSLINUX"			=> "extlinux",    "SYSLINUX_PATH"		=> "/boot/extlinux",    "CONNECT_TIMEOUT"		=> 25, # required, and we will ask users if they don't have them but we keep the default# value something that is common.    "REBOOT_TYPE"		=> "grub",    "LOCALVERSION"		=> "-test",    "SSH_USER"			=> "root",    "BUILD_TARGET"	 	=> "arch/x86/boot/bzImage",    "TARGET_IMAGE"		=> "/boot/vmlinuz-test",     "LOG_FILE"			=> undef,    "IGNORE_UNUSED"		=> 0,); my $test_log_start = 0; my $ktest_config = "ktest.conf";my $version;my $have_version = 0;my $machine;my $last_machine;my $ssh_user;my $tmpdir;my $builddir;my $outputdir;my $output_config;my $test_type;my $build_type;my $build_options;my $final_post_ktest;my $pre_ktest;my $post_ktest;my $pre_test;my $pre_test_die;my $post_test;my $pre_build;my $post_build;my $pre_build_die;my $post_build_die;my $reboot_type;my $reboot_script;my $power_cycle;my $reboot;my $reboot_return_code;my $reboot_on_error;my $switch_to_good;my $switch_to_test;my $poweroff_on_error;my $reboot_on_success;my $die_on_failure;my $powercycle_after_reboot;my $poweroff_after_halt;my $max_monitor_wait;my $ssh_exec;my $scp_to_target;my $scp_to_target_install;my $power_off;my $grub_menu;my $last_grub_menu;my $grub_file;my $grub_number;my $grub_reboot;my $grub_bls_get;my $syslinux;my $syslinux_path;my $syslinux_label;my $target;my $make;my $pre_install;my $post_install;my $no_install;my $noclean;my $minconfig;my $start_minconfig;my $start_minconfig_defined;my $output_minconfig;my $minconfig_type;my $use_output_minconfig;my $warnings_file;my $ignore_config;my $ignore_errors;my $addconfig;my $in_bisect = 0;my $bisect_bad_commit = "";my $reverse_bisect;my $bisect_manual;my $bisect_skip;my $bisect_tries;my $config_bisect_good;my $bisect_ret_good;my $bisect_ret_bad;my $bisect_ret_skip;my $bisect_ret_abort;my $bisect_ret_default;my $in_patchcheck = 0;my $run_test;my $buildlog;my $testlog;my $dmesg;my $monitor_fp;my $monitor_pid;my $monitor_cnt = 0;my $sleep_time;my $bisect_sleep_time;my $patchcheck_sleep_time;my $ignore_warnings;my $store_failures;my $store_successes;my $test_name;my $timeout;my $connect_timeout;my $config_bisect_exec;my $booted_timeout;my $detect_triplefault;my $console;my $close_console_signal;my $reboot_success_line;my $success_line;my $stop_after_success;my $stop_after_failure;my $stop_test_after;my $build_target;my $target_image;my $checkout;my $localversion;my $iteration = 0;my $successes = 0;my $stty_orig;my $run_command_status = 0; my $bisect_good;my $bisect_bad;my $bisect_type;my $bisect_start;my $bisect_replay;my $bisect_files;my $bisect_reverse;my $bisect_check; my $config_bisect;my $config_bisect_type;my $config_bisect_check; my $patchcheck_type;my $patchcheck_start;my $patchcheck_cherry;my $patchcheck_end; my $build_time;my $install_time;my $reboot_time;my $test_time; my $pwd;my $dirname = $FindBin::Bin; my $mailto;my $mailer;my $mail_path;my $mail_max_size;my $mail_command;my $email_on_error;my $email_when_finished;my $email_when_started;my $email_when_canceled; my $script_start_time = localtime(); # set when a test is something other that just building or install# which would require more options.my $buildonly = 1; # tell build not to worry about warnings, even when WARNINGS_FILE is setmy $warnings_ok = 0; # set when creating a new configmy $newconfig = 0; my %entered_configs;my %config_help;my %variable; # force_config is the list of configs that we force enabled (or disabled)# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.my %force_config; # do not force reboots on config problemsmy $no_reboot = 1; # reboot on successmy $reboot_success = 0; my %option_map = (    "MAILTO"			=> \$mailto,    "MAILER"			=> \$mailer,    "MAIL_PATH"			=> \$mail_path,    "MAIL_MAX_SIZE"		=> \$mail_max_size,    "MAIL_COMMAND"		=> \$mail_command,    "EMAIL_ON_ERROR"		=> \$email_on_error,    "EMAIL_WHEN_FINISHED"	=> \$email_when_finished,    "EMAIL_WHEN_STARTED"	=> \$email_when_started,    "EMAIL_WHEN_CANCELED"	=> \$email_when_canceled,    "MACHINE"			=> \$machine,    "SSH_USER"			=> \$ssh_user,    "TMP_DIR"			=> \$tmpdir,    "OUTPUT_DIR"		=> \$outputdir,    "BUILD_DIR"			=> \$builddir,    "TEST_TYPE"			=> \$test_type,    "PRE_KTEST"			=> \$pre_ktest,    "POST_KTEST"		=> \$post_ktest,    "PRE_TEST"			=> \$pre_test,    "PRE_TEST_DIE"		=> \$pre_test_die,    "POST_TEST"			=> \$post_test,    "BUILD_TYPE"		=> \$build_type,    "BUILD_OPTIONS"		=> \$build_options,    "PRE_BUILD"			=> \$pre_build,    "POST_BUILD"		=> \$post_build,    "PRE_BUILD_DIE"		=> \$pre_build_die,    "POST_BUILD_DIE"		=> \$post_build_die,    "POWER_CYCLE"		=> \$power_cycle,    "REBOOT"			=> \$reboot,    "REBOOT_RETURN_CODE"	=> \$reboot_return_code,    "BUILD_NOCLEAN"		=> \$noclean,    "MIN_CONFIG"		=> \$minconfig,    "OUTPUT_MIN_CONFIG"		=> \$output_minconfig,    "START_MIN_CONFIG"		=> \$start_minconfig,    "MIN_CONFIG_TYPE"		=> \$minconfig_type,    "USE_OUTPUT_MIN_CONFIG"	=> \$use_output_minconfig,    "WARNINGS_FILE"		=> \$warnings_file,    "IGNORE_CONFIG"		=> \$ignore_config,    "TEST"			=> \$run_test,    "ADD_CONFIG"		=> \$addconfig,    "REBOOT_TYPE"		=> \$reboot_type,    "GRUB_MENU"			=> \$grub_menu,    "GRUB_FILE"			=> \$grub_file,    "GRUB_REBOOT"		=> \$grub_reboot,    "GRUB_BLS_GET"		=> \$grub_bls_get,    "SYSLINUX"			=> \$syslinux,    "SYSLINUX_PATH"		=> \$syslinux_path,    "SYSLINUX_LABEL"		=> \$syslinux_label,    "PRE_INSTALL"		=> \$pre_install,    "POST_INSTALL"		=> \$post_install,    "NO_INSTALL"		=> \$no_install,    "REBOOT_SCRIPT"		=> \$reboot_script,    "REBOOT_ON_ERROR"		=> \$reboot_on_error,    "SWITCH_TO_GOOD"		=> \$switch_to_good,    "SWITCH_TO_TEST"		=> \$switch_to_test,    "POWEROFF_ON_ERROR"		=> \$poweroff_on_error,    "REBOOT_ON_SUCCESS"		=> \$reboot_on_success,    "DIE_ON_FAILURE"		=> \$die_on_failure,    "POWER_OFF"			=> \$power_off,    "POWERCYCLE_AFTER_REBOOT"	=> \$powercycle_after_reboot,    "POWEROFF_AFTER_HALT"	=> \$poweroff_after_halt,    "MAX_MONITOR_WAIT"		=> \$max_monitor_wait,    "SLEEP_TIME"		=> \$sleep_time,    "BISECT_SLEEP_TIME"		=> \$bisect_sleep_time,    "PATCHCHECK_SLEEP_TIME"	=> \$patchcheck_sleep_time,    "IGNORE_WARNINGS"		=> \$ignore_warnings,    "IGNORE_ERRORS"		=> \$ignore_errors,    "BISECT_MANUAL"		=> \$bisect_manual,    "BISECT_SKIP"		=> \$bisect_skip,    "BISECT_TRIES"		=> \$bisect_tries,    "CONFIG_BISECT_GOOD"	=> \$config_bisect_good,    "BISECT_RET_GOOD"		=> \$bisect_ret_good,    "BISECT_RET_BAD"		=> \$bisect_ret_bad,    "BISECT_RET_SKIP"		=> \$bisect_ret_skip,    "BISECT_RET_ABORT"		=> \$bisect_ret_abort,    "BISECT_RET_DEFAULT"	=> \$bisect_ret_default,    "STORE_FAILURES"		=> \$store_failures,    "STORE_SUCCESSES"		=> \$store_successes,    "TEST_NAME"			=> \$test_name,    "TIMEOUT"			=> \$timeout,    "CONNECT_TIMEOUT"		=> \$connect_timeout,    "CONFIG_BISECT_EXEC"	=> \$config_bisect_exec,    "BOOTED_TIMEOUT"		=> \$booted_timeout,    "CONSOLE"			=> \$console,    "CLOSE_CONSOLE_SIGNAL"	=> \$close_console_signal,    "DETECT_TRIPLE_FAULT"	=> \$detect_triplefault,    "SUCCESS_LINE"		=> \$success_line,    "REBOOT_SUCCESS_LINE"	=> \$reboot_success_line,    "STOP_AFTER_SUCCESS"	=> \$stop_after_success,    "STOP_AFTER_FAILURE"	=> \$stop_after_failure,    "STOP_TEST_AFTER"		=> \$stop_test_after,    "BUILD_TARGET"		=> \$build_target,    "SSH_EXEC"			=> \$ssh_exec,    "SCP_TO_TARGET"		=> \$scp_to_target,    "SCP_TO_TARGET_INSTALL"	=> \$scp_to_target_install,    "CHECKOUT"			=> \$checkout,    "TARGET_IMAGE"		=> \$target_image,    "LOCALVERSION"		=> \$localversion,     "BISECT_GOOD"		=> \$bisect_good,    "BISECT_BAD"		=> \$bisect_bad,    "BISECT_TYPE"		=> \$bisect_type,    "BISECT_START"		=> \$bisect_start,    "BISECT_REPLAY"		=> \$bisect_replay,    "BISECT_FILES"		=> \$bisect_files,    "BISECT_REVERSE"		=> \$bisect_reverse,    "BISECT_CHECK"		=> \$bisect_check,     "CONFIG_BISECT"		=> \$config_bisect,    "CONFIG_BISECT_TYPE"	=> \$config_bisect_type,    "CONFIG_BISECT_CHECK"	=> \$config_bisect_check,     "PATCHCHECK_TYPE"		=> \$patchcheck_type,    "PATCHCHECK_START"		=> \$patchcheck_start,    "PATCHCHECK_CHERRY"		=> \$patchcheck_cherry,    "PATCHCHECK_END"		=> \$patchcheck_end,); # Options may be used by other options, record them.my %used_options; # default variables that can be usedchomp ($variable{"PWD"} = `pwd`);$pwd = $variable{"PWD"}; $config_help{"MACHINE"} = << "EOF" The machine hostname that you will test. For build only tests, it is still needed to differentiate log files.EOF    ;$config_help{"SSH_USER"} = << "EOF" The box is expected to have ssh on normal bootup, provide the user  (most likely root, since you need privileged operations)EOF    ;$config_help{"BUILD_DIR"} = << "EOF" The directory that contains the Linux source code (full path). You can use \${PWD} that will be the path where ktest.pl is run, or use \${THIS_DIR} which is assigned \${PWD} but may be changed later.EOF    ;$config_help{"OUTPUT_DIR"} = << "EOF" The directory that the objects will be built (full path). (can not be same as BUILD_DIR) You can use \${PWD} that will be the path where ktest.pl is run, or use \${THIS_DIR} which is assigned \${PWD} but may be changed later.EOF    ;$config_help{"BUILD_TARGET"} = << "EOF" The location of the compiled file to copy to the target. (relative to OUTPUT_DIR)EOF    ;$config_help{"BUILD_OPTIONS"} = << "EOF" Options to add to \"make\" when building. i.e.  -j20EOF    ;$config_help{"TARGET_IMAGE"} = << "EOF" The place to put your image on the test machine.EOF    ;$config_help{"POWER_CYCLE"} = << "EOF" A script or command to reboot the box.  Here is a digital loggers power switch example POWER_CYCLE = wget --no-proxy -O /dev/null -q  --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'  Here is an example to reboot a virtual box on the current host with the name "Guest". POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start GuestEOF    ;$config_help{"CONSOLE"} = << "EOF" The script or command that reads the console   If you use ttywatch server, something like the following would work.CONSOLE = nc -d localhost 3001  For a virtual machine with guest name "Guest".CONSOLE =  virsh console GuestEOF    ;$config_help{"LOCALVERSION"} = << "EOF" Required version ending to differentiate the test from other linux builds on the system.EOF    ;$config_help{"REBOOT_TYPE"} = << "EOF" Way to reboot the box to the test kernel. Only valid options so far are "grub", "grub2", "grub2bls", "syslinux", and "script".  If you specify grub, it will assume grub version 1 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU and select that target to reboot to the kernel. If this is not your setup, then specify "script" and have a command or script specified in REBOOT_SCRIPT to boot to the target.  The entry in /boot/grub/menu.lst must be entered in manually. The test will not modify that file.  If you specify grub2, then you also need to specify both \$GRUB_MENU and \$GRUB_FILE.  If you specify grub2bls, then you also need to specify \$GRUB_MENU.  If you specify syslinux, then you may use SYSLINUX to define the syslinux command (defaults to extlinux), and SYSLINUX_PATH to specify the path to the syslinux install (defaults to /boot/extlinux). But you have to specify SYSLINUX_LABEL to define the label to boot to for the test kernel.EOF    ;$config_help{"GRUB_MENU"} = << "EOF" The grub title name for the test kernel to boot (Only mandatory if REBOOT_TYPE = grub or grub2)  Note, ktest.pl will not update the grub menu.lst, you need to manually add an option for the test. ktest.pl will search the grub menu.lst for this option to find what kernel to reboot into.  For example, if in the /boot/grub/menu.lst the test kernel title has: title Test Kernel kernel vmlinuz-test GRUB_MENU = Test Kernel  For grub2, a search of \$GRUB_FILE is performed for the lines that begin with "menuentry". It will not detect submenus. The menu must be a non-nested menu. Add the quotes used in the menu to guarantee your selection, as the first menuentry with the content of \$GRUB_MENU that is found will be used.  For grub2bls, \$GRUB_MENU is searched on the result of \$GRUB_BLS_GET command for the lines that begin with "title".EOF    ;$config_help{"GRUB_FILE"} = << "EOF" If grub2 is used, the full path for the grub.cfg file is placed

Lines 1–500 of 4528.