Re: [PATCH v3 1/4] Ktest: add email support

2018-04-07 Thread Steven Rostedt
On Fri, 6 Apr 2018 16:09:28 -0700
Tim Tianyang Chen  wrote:


> >   sub _sendmail_send {
> >   my ($subject, $message) = @_;
> > -system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t 
> > $mailto");
> > +
> > +if (!defined($mail_exec)) {
> > +   $mail_exec = "/usr/sbin/sendmail";
> > +}
> > +run_command "echo \'Subject: $subject\n\n$message\' | $mail_exec -t 
> > $mailto";
> >   }
> >   
> Not sure if I understand why $mail_exec is necessary. Doesn't $mailer 
> already have a default? Wouldn't people just use $mailer to define the 
> executable they want to use? What if the $mailx_exec specified doesn't 
> use '-t' option?

sendmail isn't in my path, I had to specify the path name to find it.
Hmm, we could have "MAILER_PATH" to find it. I can change that.

Actually, what we should also add is the format to print it out.

MAIL_COMMAND = echo \'Subject: $SUBJECT\n\n$MESSAGE\' | sendmail -t ${MAILTO}

Note the difference between $SUBJECT, $MESSAGE and ${MAILTO}. When we
have ${FOO} that is a variable the user controls. But $FOO is a
variable that is hard coded for certain commands.

That may be better to have.

Here's my latest total diff:

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 30a4c053f98b..a14fc309d140 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -23,7 +23,7 @@ my %evals;
 
 #default opts
 my %default = (
-"MAILER"   => "sendmail",  # default mailer
+"MAILER"   => "sendmail",  # default mailer
 "EMAIL_ON_ERROR"   => 1,
 "EMAIL_WHEN_FINISHED"  => 1,
 "EMAIL_WHEN_CANCELED"  => 0,
@@ -218,6 +218,8 @@ my $dirname = $FindBin::Bin;
 
 my $mailto;
 my $mailer;
+my $mail_path;
+my $mail_command;
 my $email_on_error;
 my $email_when_finished;
 my $email_when_started;
@@ -250,8 +252,10 @@ my $no_reboot = 1;
 my $reboot_success = 0;
 
 my %option_map = (
-"MAILTO"   => \$mailto,
-"MAILER"   => \$mailer,
+"MAILTO"   => \$mailto,
+"MAILER"   => \$mailer,
+"MAIL_PATH"=> \$mail_path,
+"MAIL_COMMAND" => \$mail_command,
 "EMAIL_ON_ERROR"   => \$email_on_error,
 "EMAIL_WHEN_FINISHED"  => \$email_when_finished,
 "EMAIL_WHEN_STARTED"   => \$email_when_started,
@@ -1431,7 +1435,14 @@ sub do_not_reboot {
($test_type eq "config_bisect" && $opt{"CONFIG_BISECT_TYPE[$i]"} eq 
"build");
 }
 
+my $in_die = 0;
+
 sub dodie {
+
+# avoid recusion
+return if ($in_die);
+$in_die = 1;
+
 doprint "CRITICAL FAILURE... ", @_, "\n";
 
 my $i = $iteration;
@@ -4124,23 +4135,61 @@ sub set_test_option {
 return eval_option($name, $option, $i);
 }
 
-sub _mailx_send {
-my ($subject, $message) = @_;
-system("$mailer -s \'$subject\' $mailto <<< \'$message\'");
+sub find_mailer {
+my ($mailer) = @_;
+
+my @paths = split /:/, $ENV{PATH};
+
+# sendmail is usually in /usr/sbin
+$paths[$#paths + 1] = "/usr/sbin";
+
+foreach my $path (@paths) {
+   if (-x "$path/$mailer") {
+   return $path;
+   }
+}
+
+return undef;
 }
 
-sub _sendmail_send {
+sub do_send_mail {
 my ($subject, $message) = @_;
-system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto");
+
+if (!defined($mail_path)) {
+   # find the mailer
+   $mail_path = find_mailer $mailer;
+   if (!defined($mail_path)) {
+   die "\nCan not find $mailer in PATH\n";
+   }
+}
+
+if (!defined($mail_command)) {
+   if ($mailer eq "mail" || $mailer eq "mailx") {
+   $mail_command = "\$MAIL_PATH/\$MAILER -s \'\$SUBJECT\' \$MAILTO <<< 
\'\$MESSAGE\'";
+   } elsif ($mailer eq "sendmail" ) {
+   $mail_command =  "echo \'Subject: \$SUBJECT\n\n\$MESSAGE\' | 
\$MAIL_PATH/\$MAILER -t \$MAILTO";
+   } else {
+   die "\nYour mailer: $mailer is not supported.\n";
+   }
+}
+
+$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;
+
+run_command $mail_command;
 }
 
 sub send_email {
-if (defined($mailto) && defined($mailer)) {
-if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);}
-elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);}
-else { doprint "\nYour mailer: $mailer is not supported.\n" }
-} else {
-print "No email sent: email or mailer not specified in config.\n"
+
+if (defined($mailto)) {
+   if (!defined($mailer)) {
+   doprint "No email sent: email or mailer not specified in config.\n";
+   return;
+   }
+   do_send_mail @_;
 }
 }
 
diff --git a/tools/testing/ktest/sample.conf 

Re: [PATCH v3 1/4] Ktest: add email support

2018-04-07 Thread Steven Rostedt
On Fri, 6 Apr 2018 16:09:28 -0700
Tim Tianyang Chen  wrote:


> >   sub _sendmail_send {
> >   my ($subject, $message) = @_;
> > -system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t 
> > $mailto");
> > +
> > +if (!defined($mail_exec)) {
> > +   $mail_exec = "/usr/sbin/sendmail";
> > +}
> > +run_command "echo \'Subject: $subject\n\n$message\' | $mail_exec -t 
> > $mailto";
> >   }
> >   
> Not sure if I understand why $mail_exec is necessary. Doesn't $mailer 
> already have a default? Wouldn't people just use $mailer to define the 
> executable they want to use? What if the $mailx_exec specified doesn't 
> use '-t' option?

sendmail isn't in my path, I had to specify the path name to find it.
Hmm, we could have "MAILER_PATH" to find it. I can change that.

Actually, what we should also add is the format to print it out.

MAIL_COMMAND = echo \'Subject: $SUBJECT\n\n$MESSAGE\' | sendmail -t ${MAILTO}

Note the difference between $SUBJECT, $MESSAGE and ${MAILTO}. When we
have ${FOO} that is a variable the user controls. But $FOO is a
variable that is hard coded for certain commands.

That may be better to have.

Here's my latest total diff:

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 30a4c053f98b..a14fc309d140 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -23,7 +23,7 @@ my %evals;
 
 #default opts
 my %default = (
-"MAILER"   => "sendmail",  # default mailer
+"MAILER"   => "sendmail",  # default mailer
 "EMAIL_ON_ERROR"   => 1,
 "EMAIL_WHEN_FINISHED"  => 1,
 "EMAIL_WHEN_CANCELED"  => 0,
@@ -218,6 +218,8 @@ my $dirname = $FindBin::Bin;
 
 my $mailto;
 my $mailer;
+my $mail_path;
+my $mail_command;
 my $email_on_error;
 my $email_when_finished;
 my $email_when_started;
@@ -250,8 +252,10 @@ my $no_reboot = 1;
 my $reboot_success = 0;
 
 my %option_map = (
-"MAILTO"   => \$mailto,
-"MAILER"   => \$mailer,
+"MAILTO"   => \$mailto,
+"MAILER"   => \$mailer,
+"MAIL_PATH"=> \$mail_path,
+"MAIL_COMMAND" => \$mail_command,
 "EMAIL_ON_ERROR"   => \$email_on_error,
 "EMAIL_WHEN_FINISHED"  => \$email_when_finished,
 "EMAIL_WHEN_STARTED"   => \$email_when_started,
@@ -1431,7 +1435,14 @@ sub do_not_reboot {
($test_type eq "config_bisect" && $opt{"CONFIG_BISECT_TYPE[$i]"} eq 
"build");
 }
 
+my $in_die = 0;
+
 sub dodie {
+
+# avoid recusion
+return if ($in_die);
+$in_die = 1;
+
 doprint "CRITICAL FAILURE... ", @_, "\n";
 
 my $i = $iteration;
@@ -4124,23 +4135,61 @@ sub set_test_option {
 return eval_option($name, $option, $i);
 }
 
-sub _mailx_send {
-my ($subject, $message) = @_;
-system("$mailer -s \'$subject\' $mailto <<< \'$message\'");
+sub find_mailer {
+my ($mailer) = @_;
+
+my @paths = split /:/, $ENV{PATH};
+
+# sendmail is usually in /usr/sbin
+$paths[$#paths + 1] = "/usr/sbin";
+
+foreach my $path (@paths) {
+   if (-x "$path/$mailer") {
+   return $path;
+   }
+}
+
+return undef;
 }
 
-sub _sendmail_send {
+sub do_send_mail {
 my ($subject, $message) = @_;
-system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto");
+
+if (!defined($mail_path)) {
+   # find the mailer
+   $mail_path = find_mailer $mailer;
+   if (!defined($mail_path)) {
+   die "\nCan not find $mailer in PATH\n";
+   }
+}
+
+if (!defined($mail_command)) {
+   if ($mailer eq "mail" || $mailer eq "mailx") {
+   $mail_command = "\$MAIL_PATH/\$MAILER -s \'\$SUBJECT\' \$MAILTO <<< 
\'\$MESSAGE\'";
+   } elsif ($mailer eq "sendmail" ) {
+   $mail_command =  "echo \'Subject: \$SUBJECT\n\n\$MESSAGE\' | 
\$MAIL_PATH/\$MAILER -t \$MAILTO";
+   } else {
+   die "\nYour mailer: $mailer is not supported.\n";
+   }
+}
+
+$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;
+
+run_command $mail_command;
 }
 
 sub send_email {
-if (defined($mailto) && defined($mailer)) {
-if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);}
-elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);}
-else { doprint "\nYour mailer: $mailer is not supported.\n" }
-} else {
-print "No email sent: email or mailer not specified in config.\n"
+
+if (defined($mailto)) {
+   if (!defined($mailer)) {
+   doprint "No email sent: email or mailer not specified in config.\n";
+   return;
+   }
+   do_send_mail @_;
 }
 }
 
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf
index 

Re: [PATCH v3 1/4] Ktest: add email support

2018-04-06 Thread Tim Tianyang Chen

I just fixed them up and pulled them in myself. ;-)

I also added the following on top of them (and testing this, live while
testing ftrace patches and other builds).

Thanks Steve!

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 30a4c053f98b..837fa75cbb47 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -23,7 +23,7 @@ my %evals;
  
  #default opts

  my %default = (
-"MAILER" => "sendmail",  # default mailer
+"MAILER" => "sendmail",  # default mailer

Noticed this when I sent the new version.


  "EMAIL_ON_ERROR"=> 1,
  "EMAIL_WHEN_FINISHED"   => 1,
  "EMAIL_WHEN_CANCELED"   => 0,
@@ -218,6 +218,7 @@ my $dirname = $FindBin::Bin;
  
  my $mailto;

  my $mailer;
+my $mail_exec;
  my $email_on_error;
  my $email_when_finished;
  my $email_when_started;
@@ -1431,7 +1433,14 @@ sub do_not_reboot {
($test_type eq "config_bisect" && $opt{"CONFIG_BISECT_TYPE[$i]"} eq 
"build");
  }
  
+my $in_die = 0;

+
  sub dodie {
+
+# avoid recusion
+return if ($in_die);
+$in_die = 1;
+
  doprint "CRITICAL FAILURE... ", @_, "\n";

Good idea.
  
  my $i = $iteration;

@@ -4126,21 +4135,31 @@ sub set_test_option {
  
  sub _mailx_send {

  my ($subject, $message) = @_;
-system("$mailer -s \'$subject\' $mailto <<< \'$message\'");
+
+if (!defined($mail_exec)) {
+   $mail_exec = $mailer;
+}
+run_command "$mail_exec -s \'$subject\' $mailto <<< \'$message\'";
  }
  
  sub _sendmail_send {

  my ($subject, $message) = @_;
-system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto");
+
+if (!defined($mail_exec)) {
+   $mail_exec = "/usr/sbin/sendmail";
+}
+run_command "echo \'Subject: $subject\n\n$message\' | $mail_exec -t 
$mailto";
  }
  
Not sure if I understand why $mail_exec is necessary. Doesn't $mailer 
already have a default? Wouldn't people just use $mailer to define the 
executable they want to use? What if the $mailx_exec specified doesn't 
use '-t' option?


Thanks,
Tim


Re: [PATCH v3 1/4] Ktest: add email support

2018-04-06 Thread Tim Tianyang Chen

I just fixed them up and pulled them in myself. ;-)

I also added the following on top of them (and testing this, live while
testing ftrace patches and other builds).

Thanks Steve!

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 30a4c053f98b..837fa75cbb47 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -23,7 +23,7 @@ my %evals;
  
  #default opts

  my %default = (
-"MAILER" => "sendmail",  # default mailer
+"MAILER" => "sendmail",  # default mailer

Noticed this when I sent the new version.


  "EMAIL_ON_ERROR"=> 1,
  "EMAIL_WHEN_FINISHED"   => 1,
  "EMAIL_WHEN_CANCELED"   => 0,
@@ -218,6 +218,7 @@ my $dirname = $FindBin::Bin;
  
  my $mailto;

  my $mailer;
+my $mail_exec;
  my $email_on_error;
  my $email_when_finished;
  my $email_when_started;
@@ -1431,7 +1433,14 @@ sub do_not_reboot {
($test_type eq "config_bisect" && $opt{"CONFIG_BISECT_TYPE[$i]"} eq 
"build");
  }
  
+my $in_die = 0;

+
  sub dodie {
+
+# avoid recusion
+return if ($in_die);
+$in_die = 1;
+
  doprint "CRITICAL FAILURE... ", @_, "\n";

Good idea.
  
  my $i = $iteration;

@@ -4126,21 +4135,31 @@ sub set_test_option {
  
  sub _mailx_send {

  my ($subject, $message) = @_;
-system("$mailer -s \'$subject\' $mailto <<< \'$message\'");
+
+if (!defined($mail_exec)) {
+   $mail_exec = $mailer;
+}
+run_command "$mail_exec -s \'$subject\' $mailto <<< \'$message\'";
  }
  
  sub _sendmail_send {

  my ($subject, $message) = @_;
-system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto");
+
+if (!defined($mail_exec)) {
+   $mail_exec = "/usr/sbin/sendmail";
+}
+run_command "echo \'Subject: $subject\n\n$message\' | $mail_exec -t 
$mailto";
  }
  
Not sure if I understand why $mail_exec is necessary. Doesn't $mailer 
already have a default? Wouldn't people just use $mailer to define the 
executable they want to use? What if the $mailx_exec specified doesn't 
use '-t' option?


Thanks,
Tim


Re: [PATCH v3 1/4] Ktest: add email support

2018-04-06 Thread Steven Rostedt
On Fri, 6 Apr 2018 15:19:48 -0700
Tim Tianyang Chen  wrote:


> > The full path name needs to be here.
> >
> >   tools/testing/ktest/ktest.pl
> >  
> Sorry I was working on my private folder, version tracked with other 
> stuff. Just re-sent them.

I just fixed them up and pulled them in myself. ;-)

I also added the following on top of them (and testing this, live while
testing ftrace patches and other builds).

-- Steve

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 30a4c053f98b..837fa75cbb47 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -23,7 +23,7 @@ my %evals;
 
 #default opts
 my %default = (
-"MAILER"   => "sendmail",  # default mailer
+"MAILER"   => "sendmail",  # default mailer
 "EMAIL_ON_ERROR"   => 1,
 "EMAIL_WHEN_FINISHED"  => 1,
 "EMAIL_WHEN_CANCELED"  => 0,
@@ -218,6 +218,7 @@ my $dirname = $FindBin::Bin;
 
 my $mailto;
 my $mailer;
+my $mail_exec;
 my $email_on_error;
 my $email_when_finished;
 my $email_when_started;
@@ -250,8 +251,9 @@ my $no_reboot = 1;
 my $reboot_success = 0;
 
 my %option_map = (
-"MAILTO"   => \$mailto,
-"MAILER"   => \$mailer,
+"MAILTO"   => \$mailto,
+"MAILER"   => \$mailer,
+"MAIL_EXEC"=> \$mail_exec,
 "EMAIL_ON_ERROR"   => \$email_on_error,
 "EMAIL_WHEN_FINISHED"  => \$email_when_finished,
 "EMAIL_WHEN_STARTED"   => \$email_when_started,
@@ -1431,7 +1433,14 @@ sub do_not_reboot {
($test_type eq "config_bisect" && $opt{"CONFIG_BISECT_TYPE[$i]"} eq 
"build");
 }
 
+my $in_die = 0;
+
 sub dodie {
+
+# avoid recusion
+return if ($in_die);
+$in_die = 1;
+
 doprint "CRITICAL FAILURE... ", @_, "\n";
 
 my $i = $iteration;
@@ -4126,21 +4135,31 @@ sub set_test_option {
 
 sub _mailx_send {
 my ($subject, $message) = @_;
-system("$mailer -s \'$subject\' $mailto <<< \'$message\'");
+
+if (!defined($mail_exec)) {
+   $mail_exec = $mailer;
+}
+run_command "$mail_exec -s \'$subject\' $mailto <<< \'$message\'";
 }
 
 sub _sendmail_send {
 my ($subject, $message) = @_;
-system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto");
+
+if (!defined($mail_exec)) {
+   $mail_exec = "/usr/sbin/sendmail";
+}
+run_command "echo \'Subject: $subject\n\n$message\' | $mail_exec -t 
$mailto";
 }
 
 sub send_email {
-if (defined($mailto) && defined($mailer)) {
+if (defined($mailto)) {
+   if (!defined($mailer)) {
+   doprint "No email sent: email or mailer not specified in config.\n";
+   return;
+   }
 if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);}
 elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);}
-else { doprint "\nYour mailer: $mailer is not supported.\n" }
-} else {
-print "No email sent: email or mailer not specified in config.\n"
+else { die "\nYour mailer: $mailer is not supported.\n" }
 }
 }
 
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf
index d1a2626aaa0a..86e7cffc45c0 100644
--- a/tools/testing/ktest/sample.conf
+++ b/tools/testing/ktest/sample.conf
@@ -411,6 +411,10 @@
 # (default sendmail)
 #MAILER = sendmail
 #
+# The executable to run
+# (default: for sendmail "/usr/sbin/sendmail", otherwise equals ${MAILER})
+#MAIL_EXEC = /usr/sbin/sendmail
+#
 # Errors are defined as those would terminate the script
 # (default 1)
 #EMAIL_ON_ERROR = 1


Re: [PATCH v3 1/4] Ktest: add email support

2018-04-06 Thread Steven Rostedt
On Fri, 6 Apr 2018 15:19:48 -0700
Tim Tianyang Chen  wrote:


> > The full path name needs to be here.
> >
> >   tools/testing/ktest/ktest.pl
> >  
> Sorry I was working on my private folder, version tracked with other 
> stuff. Just re-sent them.

I just fixed them up and pulled them in myself. ;-)

I also added the following on top of them (and testing this, live while
testing ftrace patches and other builds).

-- Steve

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 30a4c053f98b..837fa75cbb47 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -23,7 +23,7 @@ my %evals;
 
 #default opts
 my %default = (
-"MAILER"   => "sendmail",  # default mailer
+"MAILER"   => "sendmail",  # default mailer
 "EMAIL_ON_ERROR"   => 1,
 "EMAIL_WHEN_FINISHED"  => 1,
 "EMAIL_WHEN_CANCELED"  => 0,
@@ -218,6 +218,7 @@ my $dirname = $FindBin::Bin;
 
 my $mailto;
 my $mailer;
+my $mail_exec;
 my $email_on_error;
 my $email_when_finished;
 my $email_when_started;
@@ -250,8 +251,9 @@ my $no_reboot = 1;
 my $reboot_success = 0;
 
 my %option_map = (
-"MAILTO"   => \$mailto,
-"MAILER"   => \$mailer,
+"MAILTO"   => \$mailto,
+"MAILER"   => \$mailer,
+"MAIL_EXEC"=> \$mail_exec,
 "EMAIL_ON_ERROR"   => \$email_on_error,
 "EMAIL_WHEN_FINISHED"  => \$email_when_finished,
 "EMAIL_WHEN_STARTED"   => \$email_when_started,
@@ -1431,7 +1433,14 @@ sub do_not_reboot {
($test_type eq "config_bisect" && $opt{"CONFIG_BISECT_TYPE[$i]"} eq 
"build");
 }
 
+my $in_die = 0;
+
 sub dodie {
+
+# avoid recusion
+return if ($in_die);
+$in_die = 1;
+
 doprint "CRITICAL FAILURE... ", @_, "\n";
 
 my $i = $iteration;
@@ -4126,21 +4135,31 @@ sub set_test_option {
 
 sub _mailx_send {
 my ($subject, $message) = @_;
-system("$mailer -s \'$subject\' $mailto <<< \'$message\'");
+
+if (!defined($mail_exec)) {
+   $mail_exec = $mailer;
+}
+run_command "$mail_exec -s \'$subject\' $mailto <<< \'$message\'";
 }
 
 sub _sendmail_send {
 my ($subject, $message) = @_;
-system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto");
+
+if (!defined($mail_exec)) {
+   $mail_exec = "/usr/sbin/sendmail";
+}
+run_command "echo \'Subject: $subject\n\n$message\' | $mail_exec -t 
$mailto";
 }
 
 sub send_email {
-if (defined($mailto) && defined($mailer)) {
+if (defined($mailto)) {
+   if (!defined($mailer)) {
+   doprint "No email sent: email or mailer not specified in config.\n";
+   return;
+   }
 if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);}
 elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);}
-else { doprint "\nYour mailer: $mailer is not supported.\n" }
-} else {
-print "No email sent: email or mailer not specified in config.\n"
+else { die "\nYour mailer: $mailer is not supported.\n" }
 }
 }
 
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf
index d1a2626aaa0a..86e7cffc45c0 100644
--- a/tools/testing/ktest/sample.conf
+++ b/tools/testing/ktest/sample.conf
@@ -411,6 +411,10 @@
 # (default sendmail)
 #MAILER = sendmail
 #
+# The executable to run
+# (default: for sendmail "/usr/sbin/sendmail", otherwise equals ${MAILER})
+#MAIL_EXEC = /usr/sbin/sendmail
+#
 # Errors are defined as those would terminate the script
 # (default 1)
 #EMAIL_ON_ERROR = 1


Re: [PATCH v3 1/4] Ktest: add email support

2018-04-06 Thread Tim Tianyang Chen



On 04/06/2018 11:24 AM, Steven Rostedt wrote:

On Mon, 26 Mar 2018 13:08:01 -0700
Tim Tianyang Chen  wrote:


Users can define optional variables to get email notifications.
Ktest can send emails when the script:
  * was started
  * 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 
Signed-off-by: Tim Tianyang Chen 

---
 changes since v2:
 coding style fix for option maps and if statements
moved sig int handeling to another patch
 changes since v1:
 added options for when to send emails to option_map
---
  ktest.pl | 61 ++---
  1 file changed, 58 insertions(+), 3 deletions(-)

diff --git a/ktest.pl b/ktest.pl
index 0c8b61f8398e..9469783bc6c1 100755
--- a/ktest.pl
+++ b/ktest.pl

If you can, please use git to make your diffs.

The full path name needs to be here.

  tools/testing/ktest/ktest.pl

Sorry I was working on my private folder, version tracked with other 
stuff. Just re-sent them.


Tim


Re: [PATCH v3 1/4] Ktest: add email support

2018-04-06 Thread Tim Tianyang Chen



On 04/06/2018 11:24 AM, Steven Rostedt wrote:

On Mon, 26 Mar 2018 13:08:01 -0700
Tim Tianyang Chen  wrote:


Users can define optional variables to get email notifications.
Ktest can send emails when the script:
  * was started
  * 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 
Signed-off-by: Tim Tianyang Chen 

---
 changes since v2:
 coding style fix for option maps and if statements
moved sig int handeling to another patch
 changes since v1:
 added options for when to send emails to option_map
---
  ktest.pl | 61 ++---
  1 file changed, 58 insertions(+), 3 deletions(-)

diff --git a/ktest.pl b/ktest.pl
index 0c8b61f8398e..9469783bc6c1 100755
--- a/ktest.pl
+++ b/ktest.pl

If you can, please use git to make your diffs.

The full path name needs to be here.

  tools/testing/ktest/ktest.pl

Sorry I was working on my private folder, version tracked with other 
stuff. Just re-sent them.


Tim


[PATCH v3 1/4] ktest: add email support

2018-04-06 Thread Tim Tianyang Chen
Users can define optional variables to get email notifications.
Ktest can send emails when the script:
 * was started
 * 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 
Signed-off-by: Tim Tianyang Chen 
---
 tools/testing/ktest/ktest.pl | 61 +---
 1 file changed, 58 insertions(+), 3 deletions(-)

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 8809f244bb7c..a9a6318b1395 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -22,6 +22,11 @@ my %evals;
 
 #default opts
 my %default = (
+"MAILER"   => "sendmail",  # default mailer
+"EMAIL_ON_ERROR"   => 1,
+"EMAIL_WHEN_FINISHED"  => 1,
+"EMAIL_WHEN_CANCELED"  => 0,
+"EMAIL_WHEN_STARTED"   => 0,
 "NUM_TESTS"=> 1,
 "TEST_TYPE"=> "build",
 "BUILD_TYPE"   => "randconfig",
@@ -204,6 +209,15 @@ my $install_time;
 my $reboot_time;
 my $test_time;
 
+my $mailto;
+my $mailer;
+my $email_on_error;
+my $email_when_finished;
+my $email_when_started;
+my $email_when_canceled;
+
+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;
@@ -229,6 +243,12 @@ my $no_reboot = 1;
 my $reboot_success = 0;
 
 my %option_map = (
+"MAILTO"   => \$mailto,
+"MAILER"   => \$mailer,
+"EMAIL_ON_ERROR"   => \$email_on_error,
+"EMAIL_WHEN_FINISHED"  => \$email_when_finished,
+"EMAIL_WHEN_STARTED"   => \$email_when_started,
+"EMAIL_WHEN_CANCELED"  => \$email_when_canceled,
 "MACHINE"  => \$machine,
 "SSH_USER" => \$ssh_user,
 "TMP_DIR"  => \$tmpdir,
@@ -1426,6 +1446,11 @@ sub dodie {
print " See $opt{LOG_FILE} for more info.\n";
 }
 
+if ($email_on_error) {
+send_email("KTEST: critical failure for your [$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");
@@ -4222,6 +4247,26 @@ sub set_test_option {
 return eval_option($name, $option, $i);
 }
 
+sub _mailx_send {
+my ($subject, $message) = @_;
+system("$mailer -s \'$subject\' $mailto <<< \'$message\'");
+}
+
+sub _sendmail_send {
+my ($subject, $message) = @_;
+system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto");
+}
+
+sub send_email {
+if (defined($mailto) && defined($mailer)) {
+if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);}
+elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);}
+else { doprint "\nYour mailer: $mailer is not supported.\n" }
+} else {
+print "No email sent: email or mailer not specified in config.\n"
+}
+}
+
 # First we need to do is the builds
 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
 
@@ -4262,9 +4307,15 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
 $start_minconfig_defined = 1;
 
 # The first test may override the PRE_KTEST option
-if (defined($pre_ktest) && $i == 1) {
-   doprint "\n";
-   run_command $pre_ktest;
+if ($i == 1) {
+if (defined($pre_ktest)) {
+doprint "\n";
+run_command $pre_ktest;
+}
+if ($email_when_started) {
+send_email("KTEST: Your [$test_type] test was started",
+"Your test was started on $script_start_time");
+}
 }
 
 # Any test can override the POST_KTEST option
@@ -4428,4 +4479,8 @@ if ($opt{"POWEROFF_ON_SUCCESS"}) {
 
 doprint "\n$successes of $opt{NUM_TESTS} tests were successful\n\n";
 
+if ($email_when_finished) {
+send_email("KTEST: Your [$test_type] test has finished!",
+"$successes of $opt{NUM_TESTS} tests started at $script_start_time 
were successful!");
+}
 exit 0;
-- 
1.8.3.1



[PATCH v3 1/4] ktest: add email support

2018-04-06 Thread Tim Tianyang Chen
Users can define optional variables to get email notifications.
Ktest can send emails when the script:
 * was started
 * 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 
Signed-off-by: Tim Tianyang Chen 
---
 tools/testing/ktest/ktest.pl | 61 +---
 1 file changed, 58 insertions(+), 3 deletions(-)

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 8809f244bb7c..a9a6318b1395 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -22,6 +22,11 @@ my %evals;
 
 #default opts
 my %default = (
+"MAILER"   => "sendmail",  # default mailer
+"EMAIL_ON_ERROR"   => 1,
+"EMAIL_WHEN_FINISHED"  => 1,
+"EMAIL_WHEN_CANCELED"  => 0,
+"EMAIL_WHEN_STARTED"   => 0,
 "NUM_TESTS"=> 1,
 "TEST_TYPE"=> "build",
 "BUILD_TYPE"   => "randconfig",
@@ -204,6 +209,15 @@ my $install_time;
 my $reboot_time;
 my $test_time;
 
+my $mailto;
+my $mailer;
+my $email_on_error;
+my $email_when_finished;
+my $email_when_started;
+my $email_when_canceled;
+
+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;
@@ -229,6 +243,12 @@ my $no_reboot = 1;
 my $reboot_success = 0;
 
 my %option_map = (
+"MAILTO"   => \$mailto,
+"MAILER"   => \$mailer,
+"EMAIL_ON_ERROR"   => \$email_on_error,
+"EMAIL_WHEN_FINISHED"  => \$email_when_finished,
+"EMAIL_WHEN_STARTED"   => \$email_when_started,
+"EMAIL_WHEN_CANCELED"  => \$email_when_canceled,
 "MACHINE"  => \$machine,
 "SSH_USER" => \$ssh_user,
 "TMP_DIR"  => \$tmpdir,
@@ -1426,6 +1446,11 @@ sub dodie {
print " See $opt{LOG_FILE} for more info.\n";
 }
 
+if ($email_on_error) {
+send_email("KTEST: critical failure for your [$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");
@@ -4222,6 +4247,26 @@ sub set_test_option {
 return eval_option($name, $option, $i);
 }
 
+sub _mailx_send {
+my ($subject, $message) = @_;
+system("$mailer -s \'$subject\' $mailto <<< \'$message\'");
+}
+
+sub _sendmail_send {
+my ($subject, $message) = @_;
+system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto");
+}
+
+sub send_email {
+if (defined($mailto) && defined($mailer)) {
+if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);}
+elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);}
+else { doprint "\nYour mailer: $mailer is not supported.\n" }
+} else {
+print "No email sent: email or mailer not specified in config.\n"
+}
+}
+
 # First we need to do is the builds
 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
 
@@ -4262,9 +4307,15 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
 $start_minconfig_defined = 1;
 
 # The first test may override the PRE_KTEST option
-if (defined($pre_ktest) && $i == 1) {
-   doprint "\n";
-   run_command $pre_ktest;
+if ($i == 1) {
+if (defined($pre_ktest)) {
+doprint "\n";
+run_command $pre_ktest;
+}
+if ($email_when_started) {
+send_email("KTEST: Your [$test_type] test was started",
+"Your test was started on $script_start_time");
+}
 }
 
 # Any test can override the POST_KTEST option
@@ -4428,4 +4479,8 @@ if ($opt{"POWEROFF_ON_SUCCESS"}) {
 
 doprint "\n$successes of $opt{NUM_TESTS} tests were successful\n\n";
 
+if ($email_when_finished) {
+send_email("KTEST: Your [$test_type] test has finished!",
+"$successes of $opt{NUM_TESTS} tests started at $script_start_time 
were successful!");
+}
 exit 0;
-- 
1.8.3.1



Re: [PATCH v3 1/4] Ktest: add email support

2018-04-06 Thread Steven Rostedt
On Mon, 26 Mar 2018 13:08:01 -0700
Tim Tianyang Chen  wrote:

> Users can define optional variables to get email notifications.
> Ktest can send emails when the script:
>  * was started
>  * 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 
> Signed-off-by: Tim Tianyang Chen 
> 
> ---
> changes since v2:
> coding style fix for option maps and if statements
>   moved sig int handeling to another patch
> changes since v1:
> added options for when to send emails to option_map
> ---
>  ktest.pl | 61 ++---
>  1 file changed, 58 insertions(+), 3 deletions(-)
> 
> diff --git a/ktest.pl b/ktest.pl
> index 0c8b61f8398e..9469783bc6c1 100755
> --- a/ktest.pl
> +++ b/ktest.pl

If you can, please use git to make your diffs.

The full path name needs to be here.

 tools/testing/ktest/ktest.pl

-- Steve

> @@ -22,6 +22,11 @@ my %evals;
>  
> 


Re: [PATCH v3 1/4] Ktest: add email support

2018-04-06 Thread Steven Rostedt
On Mon, 26 Mar 2018 13:08:01 -0700
Tim Tianyang Chen  wrote:

> Users can define optional variables to get email notifications.
> Ktest can send emails when the script:
>  * was started
>  * 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 
> Signed-off-by: Tim Tianyang Chen 
> 
> ---
> changes since v2:
> coding style fix for option maps and if statements
>   moved sig int handeling to another patch
> changes since v1:
> added options for when to send emails to option_map
> ---
>  ktest.pl | 61 ++---
>  1 file changed, 58 insertions(+), 3 deletions(-)
> 
> diff --git a/ktest.pl b/ktest.pl
> index 0c8b61f8398e..9469783bc6c1 100755
> --- a/ktest.pl
> +++ b/ktest.pl

If you can, please use git to make your diffs.

The full path name needs to be here.

 tools/testing/ktest/ktest.pl

-- Steve

> @@ -22,6 +22,11 @@ my %evals;
>  
> 


[PATCH v3 1/4] Ktest: add email support

2018-03-26 Thread Tim Tianyang Chen
Users can define optional variables to get email notifications.
Ktest can send emails when the script:
 * was started
 * 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 
Signed-off-by: Tim Tianyang Chen 

---
changes since v2:
coding style fix for option maps and if statements
moved sig int handeling to another patch
changes since v1:
added options for when to send emails to option_map
---
 ktest.pl | 61 ++---
 1 file changed, 58 insertions(+), 3 deletions(-)

diff --git a/ktest.pl b/ktest.pl
index 0c8b61f8398e..9469783bc6c1 100755
--- a/ktest.pl
+++ b/ktest.pl
@@ -22,6 +22,11 @@ my %evals;
 
 #default opts
 my %default = (
+"MAILER"   => "sendmail",  # default mailer
+"EMAIL_ON_ERROR"   => 1,
+"EMAIL_WHEN_FINISHED"  => 1,
+"EMAIL_WHEN_CANCELED"  => 0,
+"EMAIL_WHEN_STARTED"   => 0,
 "NUM_TESTS"=> 1,
 "TEST_TYPE"=> "build",
 "BUILD_TYPE"   => "randconfig",
@@ -204,6 +209,15 @@ my $install_time;
 my $reboot_time;
 my $test_time;
 
+my $mailto;
+my $mailer;
+my $email_on_error;
+my $email_when_finished;
+my $email_when_started;
+my $email_when_canceled;
+
+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;
@@ -229,6 +243,12 @@ my $no_reboot = 1;
 my $reboot_success = 0;
 
 my %option_map = (
+"MAILTO"   => \$mailto,
+"MAILER"   => \$mailer,
+"EMAIL_ON_ERROR"   => \$email_on_error,
+"EMAIL_WHEN_FINISHED"  => \$email_when_finished,
+"EMAIL_WHEN_STARTED"   => \$email_when_started,
+"EMAIL_WHEN_CANCELED"  => \$email_when_canceled,
 "MACHINE"  => \$machine,
 "SSH_USER" => \$ssh_user,
 "TMP_DIR"  => \$tmpdir,
@@ -1426,6 +1446,11 @@ sub dodie {
print " See $opt{LOG_FILE} for more info.\n";
 }
 
+if ($email_on_error) {
+send_email("KTEST: critical failure for your [$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 +4249,26 @@ sub set_test_option {
 return eval_option($name, $option, $i);
 }
 
+sub _mailx_send {
+my ($subject, $message) = @_;
+system("$mailer -s \'$subject\' $mailto <<< \'$message\'");
+}
+
+sub _sendmail_send {
+my ($subject, $message) = @_;
+system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto");
+}
+
+sub send_email {
+if (defined($mailto) && defined($mailer)) {
+if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);}
+elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);}
+else { doprint "\nYour mailer: $mailer is not supported.\n" }
+} else {
+print "No email sent: email or mailer not specified in config.\n"
+}
+}
+
 # First we need to do is the builds
 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
 
@@ -4264,9 +4309,15 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
 $start_minconfig_defined = 1;
 
 # The first test may override the PRE_KTEST option
-if (defined($pre_ktest) && $i == 1) {
-   doprint "\n";
-   run_command $pre_ktest;
+if ($i == 1) {
+if (defined($pre_ktest)) {
+doprint "\n";
+run_command $pre_ktest;
+}
+if ($email_when_started) {
+send_email("KTEST: Your [$test_type] test was started",
+"Your test was started on $script_start_time");
+}
 }
 
 # Any test can override the POST_KTEST option
@@ -4430,4 +4481,8 @@ if ($opt{"POWEROFF_ON_SUCCESS"}) {
 
 doprint "\n$successes of $opt{NUM_TESTS} tests were successful\n\n";
 
+if ($email_when_finished) {
+send_email("KTEST: Your [$test_type] test has finished!",
+"$successes of $opt{NUM_TESTS} tests started at $script_start_time 
were successful!");
+}
 exit 0;
-- 
2.15.1



[PATCH v3 1/4] Ktest: add email support

2018-03-26 Thread Tim Tianyang Chen
Users can define optional variables to get email notifications.
Ktest can send emails when the script:
 * was started
 * 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 
Signed-off-by: Tim Tianyang Chen 

---
changes since v2:
coding style fix for option maps and if statements
moved sig int handeling to another patch
changes since v1:
added options for when to send emails to option_map
---
 ktest.pl | 61 ++---
 1 file changed, 58 insertions(+), 3 deletions(-)

diff --git a/ktest.pl b/ktest.pl
index 0c8b61f8398e..9469783bc6c1 100755
--- a/ktest.pl
+++ b/ktest.pl
@@ -22,6 +22,11 @@ my %evals;
 
 #default opts
 my %default = (
+"MAILER"   => "sendmail",  # default mailer
+"EMAIL_ON_ERROR"   => 1,
+"EMAIL_WHEN_FINISHED"  => 1,
+"EMAIL_WHEN_CANCELED"  => 0,
+"EMAIL_WHEN_STARTED"   => 0,
 "NUM_TESTS"=> 1,
 "TEST_TYPE"=> "build",
 "BUILD_TYPE"   => "randconfig",
@@ -204,6 +209,15 @@ my $install_time;
 my $reboot_time;
 my $test_time;
 
+my $mailto;
+my $mailer;
+my $email_on_error;
+my $email_when_finished;
+my $email_when_started;
+my $email_when_canceled;
+
+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;
@@ -229,6 +243,12 @@ my $no_reboot = 1;
 my $reboot_success = 0;
 
 my %option_map = (
+"MAILTO"   => \$mailto,
+"MAILER"   => \$mailer,
+"EMAIL_ON_ERROR"   => \$email_on_error,
+"EMAIL_WHEN_FINISHED"  => \$email_when_finished,
+"EMAIL_WHEN_STARTED"   => \$email_when_started,
+"EMAIL_WHEN_CANCELED"  => \$email_when_canceled,
 "MACHINE"  => \$machine,
 "SSH_USER" => \$ssh_user,
 "TMP_DIR"  => \$tmpdir,
@@ -1426,6 +1446,11 @@ sub dodie {
print " See $opt{LOG_FILE} for more info.\n";
 }
 
+if ($email_on_error) {
+send_email("KTEST: critical failure for your [$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 +4249,26 @@ sub set_test_option {
 return eval_option($name, $option, $i);
 }
 
+sub _mailx_send {
+my ($subject, $message) = @_;
+system("$mailer -s \'$subject\' $mailto <<< \'$message\'");
+}
+
+sub _sendmail_send {
+my ($subject, $message) = @_;
+system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto");
+}
+
+sub send_email {
+if (defined($mailto) && defined($mailer)) {
+if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);}
+elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);}
+else { doprint "\nYour mailer: $mailer is not supported.\n" }
+} else {
+print "No email sent: email or mailer not specified in config.\n"
+}
+}
+
 # First we need to do is the builds
 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
 
@@ -4264,9 +4309,15 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
 $start_minconfig_defined = 1;
 
 # The first test may override the PRE_KTEST option
-if (defined($pre_ktest) && $i == 1) {
-   doprint "\n";
-   run_command $pre_ktest;
+if ($i == 1) {
+if (defined($pre_ktest)) {
+doprint "\n";
+run_command $pre_ktest;
+}
+if ($email_when_started) {
+send_email("KTEST: Your [$test_type] test was started",
+"Your test was started on $script_start_time");
+}
 }
 
 # Any test can override the POST_KTEST option
@@ -4430,4 +4481,8 @@ if ($opt{"POWEROFF_ON_SUCCESS"}) {
 
 doprint "\n$successes of $opt{NUM_TESTS} tests were successful\n\n";
 
+if ($email_when_finished) {
+send_email("KTEST: Your [$test_type] test has finished!",
+"$successes of $opt{NUM_TESTS} tests started at $script_start_time 
were successful!");
+}
 exit 0;
-- 
2.15.1