ktest.pl: Add MAIL_MAX_SIZE to limit the amount of log emailed
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Wed, 1 Jul 2020 22:34:10 +0000 (18:34 -0400)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Thu, 2 Jul 2020 13:55:04 +0000 (09:55 -0400)
Add the ktest config option MAIL_MAX_SIZE that will limit the size of the
log file that is placed into the email on failure.

Link: https://lore.kernel.org/r/20200701231756.790637968@goodmis.org
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
tools/testing/ktest/ktest.pl
tools/testing/ktest/sample.conf

index 8a4a33492952b83cb18a158cb763ce3f41d33cb7..36db5b0b36475b972e21559572eefb0d4fdc0432 100755 (executable)
@@ -227,6 +227,7 @@ 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;
@@ -263,6 +264,7 @@ 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,
@@ -1497,10 +1499,18 @@ sub dodie {
        my $log_file;
 
        if (defined($opt{"LOG_FILE"})) {
+           my $size = 0;
+           if (defined($mail_max_size)) {
+               my $log_size = tell LOG;
+               $log_size -= $test_log_start;
+               if ($log_size > $mail_max_size) {
+                   $size = $log_size - $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, $test_log_start, 0);
+           seek(L, $test_log_start + $size, 0);
            while (<L>) {
                print O;
            }
index cb8227fbd01ed48d4ae7a160caa15ef133d9bd0a..5e7d1d7297529be4ca1b684af3bd5b3e87b1fcfc 100644 (file)
 # Users can cancel the test by Ctrl^C
 # (default 0)
 #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
 # will be default and the test will run once.