Commit ed3854ff authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'ktest-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest

Pull ktest updates from Steven Rostedt:

 - Have config-bisect save the good/bad configs at each step.

 - Show log file location even on success

 - Add PRE_TEST_DIE to kill test if the PRE_TEST fails

 - Add a NOT operator for conditionals in config file

 - Add the log output of the last test when emailing on failure.

 - Other minor clean ups and small fixes.

* tag 'ktest-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest:
  ktest.pl: Fix spelling mistake "Cant" -> "Can't"
  ktest.pl: Change the logic to control the size of the log file emailed
  ktest.pl: Add MAIL_MAX_SIZE to limit the amount of log emailed
  ktest.pl: Add the log of last test in email on failure
  ktest.pl: Turn off buffering to the log file
  ktest.pl: Just open up the log file once
  ktest.pl: Add a NOT operator
  ktest.pl: Define PRE_TEST_DIE to kill the test if the PRE_TEST fails
  ktest.pl: Always show log file location if defined even on success
  ktest.pl: Have config-bisect save each config used in the bisect
parents 97d052ea ff131eff
...@@ -11,6 +11,7 @@ use File::Path qw(mkpath); ...@@ -11,6 +11,7 @@ use File::Path qw(mkpath);
use File::Copy qw(cp); use File::Copy qw(cp);
use FileHandle; use FileHandle;
use FindBin; use FindBin;
use IO::Handle;
my $VERSION = "0.2"; my $VERSION = "0.2";
...@@ -81,6 +82,8 @@ my %default = ( ...@@ -81,6 +82,8 @@ my %default = (
"IGNORE_UNUSED" => 0, "IGNORE_UNUSED" => 0,
); );
my $test_log_start = 0;
my $ktest_config = "ktest.conf"; my $ktest_config = "ktest.conf";
my $version; my $version;
my $have_version = 0; my $have_version = 0;
...@@ -98,6 +101,7 @@ my $final_post_ktest; ...@@ -98,6 +101,7 @@ my $final_post_ktest;
my $pre_ktest; my $pre_ktest;
my $post_ktest; my $post_ktest;
my $pre_test; my $pre_test;
my $pre_test_die;
my $post_test; my $post_test;
my $pre_build; my $pre_build;
my $post_build; my $post_build;
...@@ -223,6 +227,7 @@ my $dirname = $FindBin::Bin; ...@@ -223,6 +227,7 @@ my $dirname = $FindBin::Bin;
my $mailto; my $mailto;
my $mailer; my $mailer;
my $mail_path; my $mail_path;
my $mail_max_size;
my $mail_command; my $mail_command;
my $email_on_error; my $email_on_error;
my $email_when_finished; my $email_when_finished;
...@@ -259,6 +264,7 @@ my %option_map = ( ...@@ -259,6 +264,7 @@ my %option_map = (
"MAILTO" => \$mailto, "MAILTO" => \$mailto,
"MAILER" => \$mailer, "MAILER" => \$mailer,
"MAIL_PATH" => \$mail_path, "MAIL_PATH" => \$mail_path,
"MAIL_MAX_SIZE" => \$mail_max_size,
"MAIL_COMMAND" => \$mail_command, "MAIL_COMMAND" => \$mail_command,
"EMAIL_ON_ERROR" => \$email_on_error, "EMAIL_ON_ERROR" => \$email_on_error,
"EMAIL_WHEN_FINISHED" => \$email_when_finished, "EMAIL_WHEN_FINISHED" => \$email_when_finished,
...@@ -273,6 +279,7 @@ my %option_map = ( ...@@ -273,6 +279,7 @@ my %option_map = (
"PRE_KTEST" => \$pre_ktest, "PRE_KTEST" => \$pre_ktest,
"POST_KTEST" => \$post_ktest, "POST_KTEST" => \$post_ktest,
"PRE_TEST" => \$pre_test, "PRE_TEST" => \$pre_test,
"PRE_TEST_DIE" => \$pre_test_die,
"POST_TEST" => \$post_test, "POST_TEST" => \$post_test,
"BUILD_TYPE" => \$build_type, "BUILD_TYPE" => \$build_type,
"BUILD_OPTIONS" => \$build_options, "BUILD_OPTIONS" => \$build_options,
...@@ -507,9 +514,7 @@ EOF ...@@ -507,9 +514,7 @@ EOF
sub _logit { sub _logit {
if (defined($opt{"LOG_FILE"})) { if (defined($opt{"LOG_FILE"})) {
open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}"; print LOG @_;
print OUT @_;
close(OUT);
} }
} }
...@@ -909,6 +914,12 @@ sub process_expression { ...@@ -909,6 +914,12 @@ sub process_expression {
} }
} }
if ($val =~ s/^\s*NOT\s+(.*)//) {
my $express = $1;
my $ret = process_expression($name, $express);
return !$ret;
}
if ($val =~ /^\s*0\s*$/) { if ($val =~ /^\s*0\s*$/) {
return 0; return 0;
} elsif ($val =~ /^\s*\d+\s*$/) { } elsif ($val =~ /^\s*\d+\s*$/) {
...@@ -1485,8 +1496,32 @@ sub dodie { ...@@ -1485,8 +1496,32 @@ sub dodie {
if ($email_on_error) { if ($email_on_error) {
my $name = get_test_name; my $name = get_test_name;
my $log_file;
if (defined($opt{"LOG_FILE"})) {
my $whence = 0; # beginning of file
my $pos = $test_log_start;
if (defined($mail_max_size)) {
my $log_size = tell LOG;
$log_size -= $test_log_start;
if ($log_size > $mail_max_size) {
$whence = 2; # end of file
$pos = - $mail_max_size;
}
}
$log_file = "$tmpdir/log";
open (L, "$opt{LOG_FILE}") or die "Can't open $opt{LOG_FILE} to read)";
open (O, "> $tmpdir/log") or die "Can't open $tmpdir/log\n";
seek(L, $pos, $whence);
while (<L>) {
print O;
}
close O;
close L;
}
send_email("KTEST: critical failure for test $i [$name]", send_email("KTEST: critical failure for test $i [$name]",
"Your test started at $script_start_time has failed with:\n@_\n"); "Your test started at $script_start_time has failed with:\n@_\n", $log_file);
} }
if ($monitor_cnt) { if ($monitor_cnt) {
...@@ -1508,7 +1543,7 @@ sub create_pty { ...@@ -1508,7 +1543,7 @@ sub create_pty {
my $TIOCGPTN = 0x80045430; my $TIOCGPTN = 0x80045430;
sysopen($ptm, "/dev/ptmx", O_RDWR | O_NONBLOCK) or sysopen($ptm, "/dev/ptmx", O_RDWR | O_NONBLOCK) or
dodie "Cant open /dev/ptmx"; dodie "Can't open /dev/ptmx";
# unlockpt() # unlockpt()
$tmp = pack("i", 0); $tmp = pack("i", 0);
...@@ -1772,8 +1807,6 @@ sub run_command { ...@@ -1772,8 +1807,6 @@ sub run_command {
(fail "unable to exec $command" and return 0); (fail "unable to exec $command" and return 0);
if (defined($opt{"LOG_FILE"})) { if (defined($opt{"LOG_FILE"})) {
open(LOG, ">>$opt{LOG_FILE}") or
dodie "failed to write to log";
$dolog = 1; $dolog = 1;
} }
...@@ -1821,7 +1854,6 @@ sub run_command { ...@@ -1821,7 +1854,6 @@ sub run_command {
} }
close(CMD); close(CMD);
close(LOG) if ($dolog);
close(RD) if ($dord); close(RD) if ($dord);
$end_time = time; $end_time = time;
...@@ -3188,6 +3220,8 @@ sub config_bisect_end { ...@@ -3188,6 +3220,8 @@ sub config_bisect_end {
doprint "***************************************\n\n"; doprint "***************************************\n\n";
} }
my $pass = 1;
sub run_config_bisect { sub run_config_bisect {
my ($good, $bad, $last_result) = @_; my ($good, $bad, $last_result) = @_;
my $reset = ""; my $reset = "";
...@@ -3210,11 +3244,15 @@ sub run_config_bisect { ...@@ -3210,11 +3244,15 @@ sub run_config_bisect {
$ret = run_config_bisect_test $config_bisect_type; $ret = run_config_bisect_test $config_bisect_type;
if ($ret) { if ($ret) {
doprint "NEW GOOD CONFIG\n"; doprint "NEW GOOD CONFIG ($pass)\n";
system("cp $output_config $tmpdir/good_config.tmp.$pass");
$pass++;
# Return 3 for good config # Return 3 for good config
return 3; return 3;
} else { } else {
doprint "NEW BAD CONFIG\n"; doprint "NEW BAD CONFIG ($pass)\n";
system("cp $output_config $tmpdir/bad_config.tmp.$pass");
$pass++;
# Return 4 for bad config # Return 4 for bad config
return 4; return 4;
} }
...@@ -4077,8 +4115,12 @@ if ($#new_configs >= 0) { ...@@ -4077,8 +4115,12 @@ if ($#new_configs >= 0) {
} }
} }
if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) { if (defined($opt{"LOG_FILE"})) {
unlink $opt{"LOG_FILE"}; if ($opt{"CLEAR_LOG"}) {
unlink $opt{"LOG_FILE"};
}
open(LOG, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
LOG->autoflush(1);
} }
doprint "\n\nSTARTING AUTOMATED TESTS\n\n"; doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
...@@ -4171,7 +4213,7 @@ sub find_mailer { ...@@ -4171,7 +4213,7 @@ sub find_mailer {
} }
sub do_send_mail { sub do_send_mail {
my ($subject, $message) = @_; my ($subject, $message, $file) = @_;
if (!defined($mail_path)) { if (!defined($mail_path)) {
# find the mailer # find the mailer
...@@ -4181,16 +4223,30 @@ sub do_send_mail { ...@@ -4181,16 +4223,30 @@ sub do_send_mail {
} }
} }
my $header_file = "$tmpdir/header";
open (HEAD, ">$header_file") or die "Can not create $header_file\n";
print HEAD "To: $mailto\n";
print HEAD "Subject: $subject\n\n";
print HEAD "$message\n";
close HEAD;
if (!defined($mail_command)) { if (!defined($mail_command)) {
if ($mailer eq "mail" || $mailer eq "mailx") { if ($mailer eq "mail" || $mailer eq "mailx") {
$mail_command = "\$MAIL_PATH/\$MAILER -s \'\$SUBJECT\' \$MAILTO <<< \'\$MESSAGE\'"; $mail_command = "cat \$HEADER_FILE \$BODY_FILE | \$MAIL_PATH/\$MAILER -s \'\$SUBJECT\' \$MAILTO";
} elsif ($mailer eq "sendmail" ) { } elsif ($mailer eq "sendmail" ) {
$mail_command = "echo \'Subject: \$SUBJECT\n\n\$MESSAGE\' | \$MAIL_PATH/\$MAILER -t \$MAILTO"; $mail_command = "cat \$HEADER_FILE \$BODY_FILE | \$MAIL_PATH/\$MAILER -t \$MAILTO";
} else { } else {
die "\nYour mailer: $mailer is not supported.\n"; die "\nYour mailer: $mailer is not supported.\n";
} }
} }
if (defined($file)) {
$mail_command =~ s/\$BODY_FILE/$file/g;
} else {
$mail_command =~ s/\$BODY_FILE//g;
}
$mail_command =~ s/\$HEADER_FILE/$header_file/g;
$mail_command =~ s/\$MAILER/$mailer/g; $mail_command =~ s/\$MAILER/$mailer/g;
$mail_command =~ s/\$MAIL_PATH/$mail_path/g; $mail_command =~ s/\$MAIL_PATH/$mail_path/g;
$mail_command =~ s/\$MAILTO/$mailto/g; $mail_command =~ s/\$MAILTO/$mailto/g;
...@@ -4338,10 +4394,19 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { ...@@ -4338,10 +4394,19 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
} }
doprint "\n\n"; doprint "\n\n";
if (defined($opt{"LOG_FILE"})) {
$test_log_start = tell(LOG);
}
doprint "RUNNING TEST $i of $opt{NUM_TESTS}$name with option $test_type $run_type$installme\n\n"; doprint "RUNNING TEST $i of $opt{NUM_TESTS}$name with option $test_type $run_type$installme\n\n";
if (defined($pre_test)) { if (defined($pre_test)) {
run_command $pre_test; my $ret = run_command $pre_test;
if (!$ret && defined($pre_test_die) &&
$pre_test_die) {
dodie "failed to pre_test\n";
}
} }
unlink $dmesg; unlink $dmesg;
...@@ -4441,4 +4506,10 @@ if ($email_when_finished) { ...@@ -4441,4 +4506,10 @@ if ($email_when_finished) {
send_email("KTEST: Your test has finished!", send_email("KTEST: Your test has finished!",
"$successes of $opt{NUM_TESTS} tests started at $script_start_time were successful!"); "$successes of $opt{NUM_TESTS} tests started at $script_start_time were successful!");
} }
if (defined($opt{"LOG_FILE"})) {
print "\n See $opt{LOG_FILE} for the record of results.\n\n";
close LOG;
}
exit 0; exit 0;
...@@ -442,6 +442,19 @@ ...@@ -442,6 +442,19 @@
# Users can cancel the test by Ctrl^C # Users can cancel the test by Ctrl^C
# (default 0) # (default 0)
#EMAIL_WHEN_CANCELED = 1 #EMAIL_WHEN_CANCELED = 1
#
# If a test ends with an error and EMAIL_ON_ERROR is set as well
# as a LOG_FILE is defined, then the log of the failing test will
# be included in the email that is sent.
# It is possible that the log may be very large, in which case,
# only the last amount of the log should be sent. To limit how
# much of the log is sent, set MAIL_MAX_SIZE. This will be the
# size in bytes of the last portion of the log of the failed
# test file. That is, if this is set to 100000, then only the
# last 100 thousand bytes of the log file will be included in
# the email.
# (default undef)
#MAIL_MAX_SIZE = 1000000
# Start a test setup. If you leave this off, all options # Start a test setup. If you leave this off, all options
# will be default and the test will run once. # will be default and the test will run once.
...@@ -557,6 +570,11 @@ ...@@ -557,6 +570,11 @@
# default (undefined) # default (undefined)
#PRE_TEST = ${SSH} reboot_to_special_kernel #PRE_TEST = ${SSH} reboot_to_special_kernel
# To kill the entire test if PRE_TEST is defined but fails set this
# to 1.
# (default 0)
#PRE_TEST_DIE = 1
# If there is a command you want to run after the individual test case # If there is a command you want to run after the individual test case
# completes, then you can set this option. # completes, then you can set this option.
# #
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment