mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, John Warthog9 Hawley <warthog9@kernel.org>
Subject: Re: [for-next][PATCH 7/8] ktest.pl: Add the log of last test in email on failure
Date: Thu, 2 Jul 2020 09:42:35 +0200	[thread overview]
Message-ID: <20200702074235.GB1076415@kroah.com> (raw)
In-Reply-To: <20200701231756.619246244@goodmis.org>

On Wed, Jul 01, 2020 at 07:17:24PM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> 
> If a failure happens and an email is sent, show the contents of the log of
> the last test that failed in the email.
> 
> Cc: Greg KH <gregkh@linuxfoundation.org>
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
>  tools/testing/ktest/ktest.pl | 44 ++++++++++++++++++++++++++++++++----
>  1 file changed, 40 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
> index e90e2e7cb72c..945a7d8c178c 100755
> --- a/tools/testing/ktest/ktest.pl
> +++ b/tools/testing/ktest/ktest.pl
> @@ -82,6 +82,8 @@ my %default = (
>      "IGNORE_UNUSED"		=> 0,
>  );
>  
> +my $test_log_start = 0;
> +
>  my $ktest_config = "ktest.conf";
>  my $version;
>  my $have_version = 0;
> @@ -1492,8 +1494,21 @@ sub dodie {
>  
>      if ($email_on_error) {
>  	my $name = get_test_name;
> +	my $log_file;
> +
> +	if (defined($opt{"LOG_FILE"})) {
> +	    $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);
> +	    while (<L>) {
> +		print O;
> +	    }
> +	    close O;
> +	    close L;
> +	}
>          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) {
> @@ -4185,7 +4200,7 @@ sub find_mailer {
>  }
>  
>  sub do_send_mail {
> -    my ($subject, $message) = @_;
> +    my ($subject, $message, $file) = @_;
>  
>      if (!defined($mail_path)) {
>  	# find the mailer
> @@ -4195,22 +4210,37 @@ 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 ($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" ) {
> -	    $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 {
>  	    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/\$MAIL_PATH/$mail_path/g;
>      $mail_command =~ s/\$MAILTO/$mailto/g;
>      $mail_command =~ s/\$SUBJECT/$subject/g;
>      $mail_command =~ s/\$MESSAGE/$message/g;
>  
> +	    print ">$mail_command<\n";
>      run_command $mail_command;
>  }
>  
> @@ -4352,6 +4382,11 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
>      }
>  
>      doprint "\n\n";
> +
> +    if (defined($opt{"LOG_FILE"})) {
> +	$test_log_start = tell(LOG);
> +    }

Nit, the mix of spaces and tabs in this file is always annoying to me,
but it's your code...

> +
>      doprint "RUNNING TEST $i of $opt{NUM_TESTS}$name with option $test_type $run_type$installme\n\n";
>  
>      if (defined($pre_test)) {
> @@ -4461,6 +4496,7 @@ if ($email_when_finished) {
>  }
>  
>  if (defined($opt{"LOG_FILE"})) {
> +
>      print "\n See $opt{LOG_FILE} for the record of results.\n\n";
>      close LOG;
>  }

Extra blank line?

Anyway, looks sane to me

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

  parent reply	other threads:[~2020-07-02  7:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-01 23:17 [for-next][PATCH 0/8] ktest.pl: Various updates and including more content in email on failures Steven Rostedt
2020-07-01 23:17 ` [for-next][PATCH 1/8] ktest.pl: Have config-bisect save each config used in the bisect Steven Rostedt
2020-07-01 23:17 ` [for-next][PATCH 2/8] ktest.pl: Always show log file location if defined even on success Steven Rostedt
2020-07-01 23:17 ` [for-next][PATCH 3/8] ktest.pl: Define PRE_TEST_DIE to kill the test if the PRE_TEST fails Steven Rostedt
2020-07-01 23:17 ` [for-next][PATCH 4/8] ktest.pl: Add a NOT operator Steven Rostedt
2020-07-01 23:17 ` [for-next][PATCH 5/8] ktest.pl: Just open up the log file once Steven Rostedt
2020-07-01 23:17 ` [for-next][PATCH 6/8] ktest.pl: Turn off buffering to the log file Steven Rostedt
2020-07-01 23:17 ` [for-next][PATCH 7/8] ktest.pl: Add the log of last test in email on failure Steven Rostedt
2020-07-01 23:44   ` Steven Rostedt
2020-07-02  7:42   ` Greg KH [this message]
2020-07-02 12:21     ` Steven Rostedt
2020-07-01 23:17 ` [for-next][PATCH 8/8] ktest.pl: Add MAIL_MAX_SIZE to limit the amount of log emailed Steven Rostedt
2020-07-02  7:41   ` Greg KH
2020-07-02 12:19     ` Steven Rostedt
2020-07-02 12:34       ` Greg KH
2020-07-02 12:58         ` Steven Rostedt
2020-07-02 16:52           ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200702074235.GB1076415@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=warthog9@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®