Skip to content

Commit f986900

Browse files
committed
ktest.pl: Add MAIL_MAX_SIZE to limit the amount of log emailed
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/[email protected] Reviewed-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 34148b1 commit f986900

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

tools/testing/ktest/ktest.pl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@
227227
my $mailto;
228228
my $mailer;
229229
my $mail_path;
230+
my $mail_max_size;
230231
my $mail_command;
231232
my $email_on_error;
232233
my $email_when_finished;
@@ -263,6 +264,7 @@
263264
"MAILTO" => \$mailto,
264265
"MAILER" => \$mailer,
265266
"MAIL_PATH" => \$mail_path,
267+
"MAIL_MAX_SIZE" => \$mail_max_size,
266268
"MAIL_COMMAND" => \$mail_command,
267269
"EMAIL_ON_ERROR" => \$email_on_error,
268270
"EMAIL_WHEN_FINISHED" => \$email_when_finished,
@@ -1497,10 +1499,18 @@ sub dodie {
14971499
my $log_file;
14981500

14991501
if (defined($opt{"LOG_FILE"})) {
1502+
my $size = 0;
1503+
if (defined($mail_max_size)) {
1504+
my $log_size = tell LOG;
1505+
$log_size -= $test_log_start;
1506+
if ($log_size > $mail_max_size) {
1507+
$size = $log_size - $mail_max_size;
1508+
}
1509+
}
15001510
$log_file = "$tmpdir/log";
15011511
open (L, "$opt{LOG_FILE}") or die "Can't open $opt{LOG_FILE} to read)";
15021512
open (O, "> $tmpdir/log") or die "Can't open $tmpdir/log\n";
1503-
seek(L, $test_log_start, 0);
1513+
seek(L, $test_log_start + $size, 0);
15041514
while (<L>) {
15051515
print O;
15061516
}

tools/testing/ktest/sample.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,19 @@
442442
# Users can cancel the test by Ctrl^C
443443
# (default 0)
444444
#EMAIL_WHEN_CANCELED = 1
445+
#
446+
# If a test ends with an error and EMAIL_ON_ERROR is set as well
447+
# as a LOG_FILE is defined, then the log of the failing test will
448+
# be included in the email that is sent.
449+
# It is possible that the log may be very large, in which case,
450+
# only the last amount of the log should be sent. To limit how
451+
# much of the log is sent, set MAIL_MAX_SIZE. This will be the
452+
# size in bytes of the last portion of the log of the failed
453+
# test file. That is, if this is set to 100000, then only the
454+
# last 100 thousand bytes of the log file will be included in
455+
# the email.
456+
# (default undef)
457+
#MAIL_MAX_SIZE = 1000000
445458

446459
# Start a test setup. If you leave this off, all options
447460
# will be default and the test will run once.

0 commit comments

Comments
 (0)