linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Ktest: add email support
@ 2017-12-15 23:20 Tim Tianyang Chen
  2017-12-15 23:20 ` [PATCH 1/3] " Tim Tianyang Chen
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Tim Tianyang Chen @ 2017-12-15 23:20 UTC (permalink / raw)
  To: rostedt, linux-kernel; +Cc: dhaval.giani, Tim Tianyang Chen

This patch set will let users define a mailer, an email address and when to receive
notifications during automated testings. Users need to setup the specified mailer
prior to using this feature.

Tim Tianyang Chen (3):
  Ktest: add email support
  Ktest: use dodie for critical falures
  Ktest: add email options to sample.config

 ktest.pl    | 131 +++++++++++++++++++++++++++++++++++++++++++++---------------
 sample.conf |  10 +++++
 2 files changed, 109 insertions(+), 32 deletions(-)

-- 
2.15.1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/3] Ktest: add email support
  2017-12-15 23:20 [PATCH 0/3] Ktest: add email support Tim Tianyang Chen
@ 2017-12-15 23:20 ` Tim Tianyang Chen
  2018-03-21 15:09   ` Steven Rostedt
  2017-12-15 23:20 ` [PATCH 2/3] Ktest: use dodie for critical falures Tim Tianyang Chen
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Tim Tianyang Chen @ 2017-12-15 23:20 UTC (permalink / raw)
  To: rostedt, linux-kernel; +Cc: dhaval.giani, Tim Tianyang Chen

Users can define optional variables to get email notifications.
Ktest can 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>

---
changes since v1:
    added options for when to sendemails in the option_map
---
 ktest.pl | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 70 insertions(+), 3 deletions(-)

diff --git a/ktest.pl b/ktest.pl
index 0c8b61f8398e..91cae4470fe7 100755
--- a/ktest.pl
+++ b/ktest.pl
@@ -22,6 +22,12 @@ my %evals;
 
 #default opts
 my %default = (
+    "MAILTO"                => "",
+    "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 +210,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 +244,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 +1447,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 +4250,37 @@ 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 ($mailto ne "" && $mailer ne "")
+    {
+        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"
+    }
+}
+
+$SIG{INT} = sub {
+    if ($email_when_canceled) {
+        send_email("KTEST: Your [$test_type] test was cancelled",
+                "Your test started at $script_start_time was cancelled: sig int");
+        die "\nCaught Sig Int, test interrupted: $!\n"
+    }
+};
+
 # First we need to do is the builds
 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
 
@@ -4264,9 +4321,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 +4493,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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/3] Ktest: use dodie for critical falures
  2017-12-15 23:20 [PATCH 0/3] Ktest: add email support Tim Tianyang Chen
  2017-12-15 23:20 ` [PATCH 1/3] " Tim Tianyang Chen
@ 2017-12-15 23:20 ` Tim Tianyang Chen
  2018-03-21 15:16   ` Steven Rostedt
  2017-12-15 23:20 ` [PATCH 3/3] Ktest: add email options to sample.config Tim Tianyang Chen
  2018-01-02 19:08 ` [PATCH 0/3] Ktest: add email support Tim Tianyang Chen
  3 siblings, 1 reply; 10+ messages in thread
From: Tim Tianyang Chen @ 2017-12-15 23:20 UTC (permalink / raw)
  To: rostedt, linux-kernel; +Cc: dhaval.giani, Tim Tianyang Chen

Users should get emails when the script dies because of a critical failure. Critical
failures are defined as any errors that could abnormally terminate the script.

In order to add email support, this patch converts all die() to dodie() except:
 * when '-v' is used as an option to get the version of the script.
 * in Sig-Int handeler because it's not a fatal error to cancel the script.
 * errors happen during parsing config

Suggested-by: Dhaval Giani <dhaval.giani@oracle.com>
Signed-off-by: Tim Tianyang Chen <tianyang.chen@oracle.com>

---
changes since v1:
    removed changes when errors happen during config parsing
---
 ktest.pl | 58 +++++++++++++++++++++++++++++-----------------------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/ktest.pl b/ktest.pl
index 91cae4470fe7..38e6d39bdcd2 100755
--- a/ktest.pl
+++ b/ktest.pl
@@ -1503,7 +1503,7 @@ sub exec_console {
     close($pts);
 
     exec $console or
-	die "Can't open console $console";
+	dodie "Can't open console $console";
 }
 
 sub open_console {
@@ -1651,7 +1651,7 @@ sub save_logs {
 
 	if (!-d $dir) {
 	    mkpath($dir) or
-		die "can't create $dir";
+		dodie "can't create $dir";
 	}
 
 	my %files = (
@@ -1664,7 +1664,7 @@ sub save_logs {
 	while (my ($name, $source) = each(%files)) {
 		if (-f "$source") {
 			cp "$source", "$dir/$name" or
-				die "failed to copy $source";
+				dodie "failed to copy $source";
 		}
 	}
 
@@ -1838,7 +1838,7 @@ sub get_grub2_index {
     $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
 
     open(IN, "$ssh_grub |")
-	or die "unable to get $grub_file";
+	or dodie "unable to get $grub_file";
 
     my $found = 0;
 
@@ -1853,7 +1853,7 @@ sub get_grub2_index {
     }
     close(IN);
 
-    die "Could not find '$grub_menu' in $grub_file on $machine"
+    dodie "Could not find '$grub_menu' in $grub_file on $machine"
 	if (!$found);
     doprint "$grub_number\n";
     $last_grub_menu = $grub_menu;
@@ -1881,7 +1881,7 @@ sub get_grub_index {
     $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
 
     open(IN, "$ssh_grub |")
-	or die "unable to get menu.lst";
+	or dodie "unable to get menu.lst";
 
     my $found = 0;
 
@@ -1896,7 +1896,7 @@ sub get_grub_index {
     }
     close(IN);
 
-    die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
+    dodie "Could not find '$grub_menu' in /boot/grub/menu on $machine"
 	if (!$found);
     doprint "$grub_number\n";
     $last_grub_menu = $grub_menu;
@@ -2009,7 +2009,7 @@ sub monitor {
     my $full_line = "";
 
     open(DMESG, "> $dmesg") or
-	die "unable to write to $dmesg";
+	dodie "unable to write to $dmesg";
 
     reboot_to;
 
@@ -2888,7 +2888,7 @@ sub run_bisect {
 sub update_bisect_replay {
     my $tmp_log = "$tmpdir/ktest_bisect_log";
     run_command "git bisect log > $tmp_log" or
-	die "can't create bisect log";
+	dodie "can't create bisect log";
     return $tmp_log;
 }
 
@@ -2897,9 +2897,9 @@ sub bisect {
 
     my $result;
 
-    die "BISECT_GOOD[$i] not defined\n"	if (!defined($bisect_good));
-    die "BISECT_BAD[$i] not defined\n"	if (!defined($bisect_bad));
-    die "BISECT_TYPE[$i] not defined\n"	if (!defined($bisect_type));
+    dodie "BISECT_GOOD[$i] not defined\n"	if (!defined($bisect_good));
+    dodie "BISECT_BAD[$i] not defined\n"	if (!defined($bisect_bad));
+    dodie "BISECT_TYPE[$i] not defined\n"	if (!defined($bisect_type));
 
     my $good = $bisect_good;
     my $bad = $bisect_bad;
@@ -2962,7 +2962,7 @@ sub bisect {
 	if ($check ne "good") {
 	    doprint "TESTING BISECT BAD [$bad]\n";
 	    run_command "git checkout $bad" or
-		die "Failed to checkout $bad";
+		dodie "Failed to checkout $bad";
 
 	    $result = run_bisect $type;
 
@@ -2974,7 +2974,7 @@ sub bisect {
 	if ($check ne "bad") {
 	    doprint "TESTING BISECT GOOD [$good]\n";
 	    run_command "git checkout $good" or
-		die "Failed to checkout $good";
+		dodie "Failed to checkout $good";
 
 	    $result = run_bisect $type;
 
@@ -2985,7 +2985,7 @@ sub bisect {
 
 	# checkout where we started
 	run_command "git checkout $head" or
-	    die "Failed to checkout $head";
+	    dodie "Failed to checkout $head";
     }
 
     run_command "git bisect start$start_files" or
@@ -3442,9 +3442,9 @@ sub patchcheck_reboot {
 sub patchcheck {
     my ($i) = @_;
 
-    die "PATCHCHECK_START[$i] not defined\n"
+    dodie "PATCHCHECK_START[$i] not defined\n"
 	if (!defined($patchcheck_start));
-    die "PATCHCHECK_TYPE[$i] not defined\n"
+    dodie "PATCHCHECK_TYPE[$i] not defined\n"
 	if (!defined($patchcheck_type));
 
     my $start = $patchcheck_start;
@@ -3458,7 +3458,7 @@ sub patchcheck {
     if (defined($patchcheck_end)) {
 	$end = $patchcheck_end;
     } elsif ($cherry) {
-	die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
+	dodie "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
     }
 
     # Get the true sha1's since we can use things like HEAD~3
@@ -3522,7 +3522,7 @@ sub patchcheck {
 	doprint "\nProcessing commit \"$item\"\n\n";
 
 	run_command "git checkout $sha1" or
-	    die "Failed to checkout $sha1";
+	    dodie "Failed to checkout $sha1";
 
 	# only clean on the first and last patch
 	if ($item eq $list[0] ||
@@ -3613,7 +3613,7 @@ sub read_kconfig {
     }
 
     open(KIN, "$kconfig")
-	or die "Can't open $kconfig";
+	or dodie "Can't open $kconfig";
     while (<KIN>) {
 	chomp;
 
@@ -3774,7 +3774,7 @@ sub get_depends {
 
 	    $dep =~ s/^[^$valid]*[$valid]+//;
 	} else {
-	    die "this should never happen";
+	    dodie "this should never happen";
 	}
     }
 
@@ -4035,7 +4035,7 @@ sub make_min_config {
 	    # update new ignore configs
 	    if (defined($ignore_config)) {
 		open (OUT, ">$temp_config")
-		    or die "Can't write to $temp_config";
+		    or dodie "Can't write to $temp_config";
 		foreach my $config (keys %save_configs) {
 		    print OUT "$save_configs{$config}\n";
 		}
@@ -4063,7 +4063,7 @@ sub make_min_config {
 
 	    # Save off all the current mandatory configs
 	    open (OUT, ">$temp_config")
-		or die "Can't write to $temp_config";
+		or dodie "Can't write to $temp_config";
 	    foreach my $config (keys %keep_configs) {
 		print OUT "$keep_configs{$config}\n";
 	    }
@@ -4132,7 +4132,7 @@ if ($#ARGV == 0) {
 if (! -f $ktest_config) {
     $newconfig = 1;
     get_test_case;
-    open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
+    open(OUT, ">$ktest_config") or dodie "Can not create $ktest_config";
     print OUT << "EOF"
 # Generated by ktest.pl
 #
@@ -4167,7 +4167,7 @@ if (defined($opt{"LOG_FILE"})) {
 my @new_configs = keys %entered_configs;
 if ($#new_configs >= 0) {
     print "\nAppending entered in configs to $ktest_config\n";
-    open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
+    open(OUT, ">>$ktest_config") or dodie "Can not append to $ktest_config";
     foreach my $config (@new_configs) {
 	print OUT "$config = $entered_configs{$config}\n";
 	$opt{$config} = process_variables($entered_configs{$config});
@@ -4304,11 +4304,11 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
     $outputdir = set_test_option("OUTPUT_DIR", $i);
     $builddir = set_test_option("BUILD_DIR", $i);
 
-    chdir $builddir || die "can't change directory to $builddir";
+    chdir $builddir || dodie "can't change directory to $builddir";
 
     if (!-d $outputdir) {
 	mkpath($outputdir) or
-	    die "can't create $outputdir";
+	    dodie "can't create $outputdir";
     }
 
     $make = "$makecmd O=$outputdir";
@@ -4345,7 +4345,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
 
     if (!-d $tmpdir) {
 	mkpath($tmpdir) or
-	    die "can't create $tmpdir";
+	    dodie "can't create $tmpdir";
     }
 
     $ENV{"SSH_USER"} = $ssh_user;
@@ -4418,7 +4418,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
 
     if (defined($checkout)) {
 	run_command "git checkout $checkout" or
-	    die "failed to checkout $checkout";
+	    dodie "failed to checkout $checkout";
     }
 
     $no_reboot = 0;
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/3] Ktest: add email options to sample.config
  2017-12-15 23:20 [PATCH 0/3] Ktest: add email support Tim Tianyang Chen
  2017-12-15 23:20 ` [PATCH 1/3] " Tim Tianyang Chen
  2017-12-15 23:20 ` [PATCH 2/3] Ktest: use dodie for critical falures Tim Tianyang Chen
@ 2017-12-15 23:20 ` Tim Tianyang Chen
  2018-03-21 15:17   ` Steven Rostedt
  2018-01-02 19:08 ` [PATCH 0/3] Ktest: add email support Tim Tianyang Chen
  3 siblings, 1 reply; 10+ messages in thread
From: Tim Tianyang Chen @ 2017-12-15 23:20 UTC (permalink / raw)
  To: rostedt, linux-kernel; +Cc: dhaval.giani, Tim Tianyang Chen

A block of email options is added under the optional config section.

Suggested-by: Dhaval Giani <dhaval.giani@oracle.com>
Signed-off-by: Tim Tianyang Chen <tianyang.chen@oracle.com>
---
 sample.conf | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/sample.conf b/sample.conf
index 6c58cd8bbbae..0571acf2179b 100644
--- a/sample.conf
+++ b/sample.conf
@@ -396,6 +396,16 @@
 
 #### Optional Config Options (all have defaults) ####
 
+# Email options for receiving notifications. Users must setup
+# the specified mailer prior to using this feature.
+#
+#MAILTO = ""
+#MAILER = sendmail
+#EMAIL_ON_ERROR = 1
+#EMAIL_WHEN_FINISHED = 1
+#EMAIL_WHEN_STARTED = 0
+#EMAIL_WHEN_CANCELED = 0
+
 # Start a test setup. If you leave this off, all options
 # will be default and the test will run once.
 # This is a label and not really an option (it takes no value).
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] Ktest: add email support
  2017-12-15 23:20 [PATCH 0/3] Ktest: add email support Tim Tianyang Chen
                   ` (2 preceding siblings ...)
  2017-12-15 23:20 ` [PATCH 3/3] Ktest: add email options to sample.config Tim Tianyang Chen
@ 2018-01-02 19:08 ` Tim Tianyang Chen
  2018-01-02 19:29   ` Steven Rostedt
  3 siblings, 1 reply; 10+ messages in thread
From: Tim Tianyang Chen @ 2018-01-02 19:08 UTC (permalink / raw)
  To: rostedt, linux-kernel; +Cc: dhaval.giani, John 'Warthog9' Hawley

Hi Steve, did your mailer find all the patches? I made sure they all 
reply to the same mail ID this time.

Thanks,
Tim

On 12/15/2017 03:20 PM, Tim Tianyang Chen wrote:
> This patch set will let users define a mailer, an email address and when to receive
> notifications during automated testings. Users need to setup the specified mailer
> prior to using this feature.
>
> Tim Tianyang Chen (3):
>    Ktest: add email support
>    Ktest: use dodie for critical falures
>    Ktest: add email options to sample.config
>
>   ktest.pl    | 131 +++++++++++++++++++++++++++++++++++++++++++++---------------
>   sample.conf |  10 +++++
>   2 files changed, 109 insertions(+), 32 deletions(-)
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] Ktest: add email support
  2018-01-02 19:08 ` [PATCH 0/3] Ktest: add email support Tim Tianyang Chen
@ 2018-01-02 19:29   ` Steven Rostedt
  0 siblings, 0 replies; 10+ messages in thread
From: Steven Rostedt @ 2018-01-02 19:29 UTC (permalink / raw)
  To: Tim Tianyang Chen
  Cc: linux-kernel, dhaval.giani, John 'Warthog9' Hawley

On Tue, 2 Jan 2018 11:08:00 -0800
Tim Tianyang Chen <tianyang.chen@oracle.com> wrote:

> Hi Steve, did your mailer find all the patches? I made sure they all 
> reply to the same mail ID this time.
> 

Yes, sorry due to end of year work, these were put on the back burner.

I'll see if I can get to them sometime this week.

-- Steve

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] Ktest: add email support
  2017-12-15 23:20 ` [PATCH 1/3] " Tim Tianyang Chen
@ 2018-03-21 15:09   ` Steven Rostedt
  0 siblings, 0 replies; 10+ messages in thread
From: Steven Rostedt @ 2018-03-21 15:09 UTC (permalink / raw)
  To: Tim Tianyang Chen; +Cc: linux-kernel, dhaval.giani

I'm really sorry for the late reply here. I finally took out time to
look at your patches. I've had my own set of ktest patches that I need
to push upstream that I haven't done so for over a year :-p


On Fri, 15 Dec 2017 15:20:09 -0800
Tim Tianyang Chen <tianyang.chen@oracle.com> wrote:

> Users can define optional variables to get email notifications.
> Ktest can 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>
> 
> ---
> changes since v1:
>     added options for when to sendemails in the option_map
> ---
>  ktest.pl | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 70 insertions(+), 3 deletions(-)
> 
> diff --git a/ktest.pl b/ktest.pl
> index 0c8b61f8398e..91cae4470fe7 100755
> --- a/ktest.pl
> +++ b/ktest.pl
> @@ -22,6 +22,12 @@ my %evals;
>  
>  #default opts
>  my %default = (
> +    "MAILTO"                => "",

We don't need to add MAILTO here. We want it undefined.

> +    "MAILER"                => "sendmail",  # default mailer
> +    "EMAIL_ON_ERROR"        => 1,
> +    "EMAIL_WHEN_FINISHED"   => 1,
> +    "EMAIL_WHEN_CANCELED"   => 0,
> +    "EMAIL_WHEN_STARTED"    => 0,

Note, the above has whitespace issues. There should be tabs between the
option and its value.

>      "NUM_TESTS"			=> 1,
>      "TEST_TYPE"			=> "build",
>      "BUILD_TYPE"		=> "randconfig",
> @@ -204,6 +210,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 +244,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,

Same whitespace issues.

>      "MACHINE"			=> \$machine,
>      "SSH_USER"			=> \$ssh_user,
>      "TMP_DIR"			=> \$tmpdir,
> @@ -1426,6 +1447,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 +4250,37 @@ 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 ($mailto ne "" && $mailer ne "")

This shoudl be:
	if (defined($mailto) && defined($mailer)) {

Also, note that we use Linux C style. (if statements end with '{').

> +    {
> +        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
> +    {

Linux C style is:

	} else {

> +        print "No email sent: email or mailer not specified in config.\n"
> +    }
> +}
> +
> +$SIG{INT} = sub {
> +    if ($email_when_canceled) {
> +        send_email("KTEST: Your [$test_type] test was cancelled",
> +                "Your test started at $script_start_time was cancelled: sig int");

Shouldn't the die be outside the if statement?

> +        die "\nCaught Sig Int, test interrupted: $!\n"
> +    }
> +};

This should be a separate patch, as it adds different functionality to
the email support. Also, when you do add it, please make it a separate
function:

ie.

sub cancel_test {
    dodie "Caught SIGINT, test interrupted: $!\n"
}

$SIG{INT} = qw(cancel_test);

Other than that. Looks good.

-- Steve

> +
>  # First we need to do is the builds
>  for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
>  
> @@ -4264,9 +4321,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 +4493,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;

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] Ktest: use dodie for critical falures
  2017-12-15 23:20 ` [PATCH 2/3] Ktest: use dodie for critical falures Tim Tianyang Chen
@ 2018-03-21 15:16   ` Steven Rostedt
  2018-03-26 18:48     ` Tim Tianyang Chen
  0 siblings, 1 reply; 10+ messages in thread
From: Steven Rostedt @ 2018-03-21 15:16 UTC (permalink / raw)
  To: Tim Tianyang Chen; +Cc: linux-kernel, dhaval.giani

On Fri, 15 Dec 2017 15:20:10 -0800
Tim Tianyang Chen <tianyang.chen@oracle.com> wrote:

> Users should get emails when the script dies because of a critical failure. Critical
> failures are defined as any errors that could abnormally terminate the script.
> 
> In order to add email support, this patch converts all die() to dodie() except:
>  * when '-v' is used as an option to get the version of the script.
>  * in Sig-Int handeler because it's not a fatal error to cancel the script.
>  * errors happen during parsing config

I would say you don't need it for parsing the config either. It doesn't
make sense, as you wouldn't have the mailto defined yet.


> @@ -4132,7 +4132,7 @@ if ($#ARGV == 0) {
>  if (! -f $ktest_config) {
>      $newconfig = 1;
>      get_test_case;
> -    open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
> +    open(OUT, ">$ktest_config") or dodie "Can not create $ktest_config";

Here, no config was specified, and so no configs either.


>      print OUT << "EOF"
>  # Generated by ktest.pl
>  #
> @@ -4167,7 +4167,7 @@ if (defined($opt{"LOG_FILE"})) {
>  my @new_configs = keys %entered_configs;
>  if ($#new_configs >= 0) {
>      print "\nAppending entered in configs to $ktest_config\n";
> -    open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
> +    open(OUT, ">>$ktest_config") or dodie "Can not append to $ktest_config";

Here too.


-- Steve


>      foreach my $config (@new_configs) {
>  	print OUT "$config = $entered_configs{$config}\n";
>  	$opt{$config} = process_variables($entered_configs{$config});

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] Ktest: add email options to sample.config
  2017-12-15 23:20 ` [PATCH 3/3] Ktest: add email options to sample.config Tim Tianyang Chen
@ 2018-03-21 15:17   ` Steven Rostedt
  0 siblings, 0 replies; 10+ messages in thread
From: Steven Rostedt @ 2018-03-21 15:17 UTC (permalink / raw)
  To: Tim Tianyang Chen; +Cc: linux-kernel, dhaval.giani

On Fri, 15 Dec 2017 15:20:11 -0800
Tim Tianyang Chen <tianyang.chen@oracle.com> wrote:

> A block of email options is added under the optional config section.
> 
> Suggested-by: Dhaval Giani <dhaval.giani@oracle.com>
> Signed-off-by: Tim Tianyang Chen <tianyang.chen@oracle.com>
> ---
>  sample.conf | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/sample.conf b/sample.conf
> index 6c58cd8bbbae..0571acf2179b 100644
> --- a/sample.conf
> +++ b/sample.conf
> @@ -396,6 +396,16 @@
>  
>  #### Optional Config Options (all have defaults) ####
>  
> +# Email options for receiving notifications. Users must setup
> +# the specified mailer prior to using this feature.

Each one should have a separate comment.

> +#
> +#MAILTO = ""

as this one:

# (default undefined)
#MAILTO =

-- Steve

> +#MAILER = sendmail
> +#EMAIL_ON_ERROR = 1
> +#EMAIL_WHEN_FINISHED = 1
> +#EMAIL_WHEN_STARTED = 0
> +#EMAIL_WHEN_CANCELED = 0
> +
>  # Start a test setup. If you leave this off, all options
>  # will be default and the test will run once.
>  # This is a label and not really an option (it takes no value).

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] Ktest: use dodie for critical falures
  2018-03-21 15:16   ` Steven Rostedt
@ 2018-03-26 18:48     ` Tim Tianyang Chen
  0 siblings, 0 replies; 10+ messages in thread
From: Tim Tianyang Chen @ 2018-03-26 18:48 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: linux-kernel, dhaval.giani

Thanks for the review Steve! One quick comment inline:

On 03/21/2018 08:16 AM, Steven Rostedt wrote:
> On Fri, 15 Dec 2017 15:20:10 -0800
> Tim Tianyang Chen <tianyang.chen@oracle.com> wrote:
>
>> Users should get emails when the script dies because of a critical failure. Critical
>> failures are defined as any errors that could abnormally terminate the script.
>>
>> In order to add email support, this patch converts all die() to dodie() except:
>>   * when '-v' is used as an option to get the version of the script.
>>   * in Sig-Int handeler because it's not a fatal error to cancel the script.
>>   * errors happen during parsing config
> I would say you don't need it for parsing the config either. It doesn't
> make sense, as you wouldn't have the mailto defined yet.
>
Maybe it's the way I worded it. This patch coverts all die() to dodie() 
_except_ these situations. So it doesn't send emails on config errors, 
which is what you said here.
>> @@ -4132,7 +4132,7 @@ if ($#ARGV == 0) {
>>   if (! -f $ktest_config) {
>>       $newconfig = 1;
>>       get_test_case;
>> -    open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
>> +    open(OUT, ">$ktest_config") or dodie "Can not create $ktest_config";
> Here, no config was specified, and so no configs either.
>
>
>>       print OUT << "EOF"
>>   # Generated by ktest.pl
>>   #
>> @@ -4167,7 +4167,7 @@ if (defined($opt{"LOG_FILE"})) {
>>   my @new_configs = keys %entered_configs;
>>   if ($#new_configs >= 0) {
>>       print "\nAppending entered in configs to $ktest_config\n";
>> -    open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
>> +    open(OUT, ">>$ktest_config") or dodie "Can not append to $ktest_config";
> Here too.
Right, I missed these two. I will send out v3 shortly.

Tim

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-03-26 18:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-15 23:20 [PATCH 0/3] Ktest: add email support Tim Tianyang Chen
2017-12-15 23:20 ` [PATCH 1/3] " Tim Tianyang Chen
2018-03-21 15:09   ` Steven Rostedt
2017-12-15 23:20 ` [PATCH 2/3] Ktest: use dodie for critical falures Tim Tianyang Chen
2018-03-21 15:16   ` Steven Rostedt
2018-03-26 18:48     ` Tim Tianyang Chen
2017-12-15 23:20 ` [PATCH 3/3] Ktest: add email options to sample.config Tim Tianyang Chen
2018-03-21 15:17   ` Steven Rostedt
2018-01-02 19:08 ` [PATCH 0/3] Ktest: add email support Tim Tianyang Chen
2018-01-02 19:29   ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).