From: Tim Tianyang Chen <tianyang.chen@oracle.com>
To: rostedt@goodmis.org, linux-kernel@vger.kernel.org
Cc: dhaval.giani@oracle.com
Subject: [PATCH 1/2][RFC]Ktest: Add email support
Date: Tue, 21 Nov 2017 10:53:32 -0800 [thread overview]
Message-ID: <d265a564-5241-5a90-d712-149b92319285@oracle.com> (raw)
In-Reply-To: <20171120173738.34823-2-tianyang.chen@oracle.com>
Users can define optional "MAILER" "USR_EMAIL" variables to get email notifications.
Ktest will send emails when the script:
* was started
* was cancelled by Ctrl-C
* failed with fatal errors and called dodie()
* completed all testing
Users have to setup the mailer provided in config prior to using this script.
Supported mailers: mailx, mail, sendmail
mailer specific routines are _sendmail_send(), _mailx_send()
Suggested-by: Dhaval Giani <dhaval.giani@oracle.com>
Signed-off-by: Tim Tianyang Chen <tianyang.chen@oracle.com>
---
ktest.pl | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/ktest.pl b/ktest.pl
index 0c8b61f..2e38647 100755
--- a/ktest.pl
+++ b/ktest.pl
@@ -22,6 +22,8 @@ my %evals;
#default opts
my %default = (
+ "USR_EMAIL" => "",
+ "MAILER" => "mailx", # default mailer
"NUM_TESTS" => 1,
"TEST_TYPE" => "build",
"BUILD_TYPE" => "randconfig",
@@ -204,6 +206,8 @@ my $install_time;
my $reboot_time;
my $test_time;
+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;
@@ -1426,6 +1430,9 @@ sub dodie {
print " See $opt{LOG_FILE} for more info.\n";
}
+ send_email("KTEST: critical failure for your [$opt{TEST_TYPE}] test",
+ "Your test started at $script_start_time has failed with:\n@_\n");
+
if ($monitor_cnt) {
# restore terminal settings
system("stty $stty_orig");
@@ -4224,6 +4231,38 @@ sub set_test_option {
return eval_option($name, $option, $i);
}
+sub _mailx_send {
+ my ($subject, $message) = @_;
+ system("$opt{MAILER} -s \'$subject\' $opt{USR_EMAIL} <<< \'$message\'");
+}
+
+sub _sendmail_send {
+ my ($subject, $message) = @_;
+ system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $opt{USR_EMAIL}");
+}
+
+sub send_email {
+ if ($opt{USR_EMAIL} ne "" && $opt{MAILER} ne "")
+ {
+ if ($opt{MAILER} eq "mail" || $opt{MAILER} eq "mailx"){ _mailx_send(@_);}
+ elsif ($opt{MAILER} eq "sendmail" ) { _sendmail_send(@_);}
+ else { doprint "\nYour mailer: $opt{MAILER} is not supported.\n" }
+ }
+ else
+ {
+ print "No email sent: email or mailer not specified in config.\n"
+ }
+}
+
+$SIG{INT} = sub {
+ send_email("KTEST: Your [$opt{TEST_TYPE}] test was cancelled",
+ "Your test started at $script_start_time was cancelled: sig int");
+ die "\nCaught Sig Int, test interrupted: $!\n"
+};
+
+send_email("KTEST: Your [$opt{TEST_TYPE}] test was started",
+ "Your test was started on $script_start_time");
+
# First we need to do is the builds
for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
@@ -4429,5 +4468,7 @@ if ($opt{"POWEROFF_ON_SUCCESS"}) {
doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
+send_email("KTEST: Your [$opt{TEST_TYPE}] test has finished!",
+ "$successes of $opt{NUM_TESTS} tests started at $script_start_time were successful!");
exit 0;
--
1.8.3.1
next parent reply other threads:[~2017-11-21 18:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20171120173738.34823-2-tianyang.chen@oracle.com>
2017-11-21 18:53 ` Tim Tianyang Chen [this message]
2017-12-14 23:39 ` Steven Rostedt
2017-12-15 0:11 ` Tim Tianyang Chen
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=d265a564-5241-5a90-d712-149b92319285@oracle.com \
--to=tianyang.chen@oracle.com \
--cc=dhaval.giani@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.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®