diff options
-rwxr-xr-x | tools/testing/ktest/ktest.pl | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index d4b22b5c425b..bb43f8631c95 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl | |||
@@ -23,6 +23,11 @@ my %evals; | |||
23 | 23 | ||
24 | #default opts | 24 | #default opts |
25 | my %default = ( | 25 | my %default = ( |
26 | "MAILER" => "sendmail", # default mailer | ||
27 | "EMAIL_ON_ERROR" => 1, | ||
28 | "EMAIL_WHEN_FINISHED" => 1, | ||
29 | "EMAIL_WHEN_CANCELED" => 0, | ||
30 | "EMAIL_WHEN_STARTED" => 0, | ||
26 | "NUM_TESTS" => 1, | 31 | "NUM_TESTS" => 1, |
27 | "TEST_TYPE" => "build", | 32 | "TEST_TYPE" => "build", |
28 | "BUILD_TYPE" => "randconfig", | 33 | "BUILD_TYPE" => "randconfig", |
@@ -211,6 +216,15 @@ my $test_time; | |||
211 | my $pwd; | 216 | my $pwd; |
212 | my $dirname = $FindBin::Bin; | 217 | my $dirname = $FindBin::Bin; |
213 | 218 | ||
219 | my $mailto; | ||
220 | my $mailer; | ||
221 | my $email_on_error; | ||
222 | my $email_when_finished; | ||
223 | my $email_when_started; | ||
224 | my $email_when_canceled; | ||
225 | |||
226 | my $script_start_time = localtime(); | ||
227 | |||
214 | # set when a test is something other that just building or install | 228 | # set when a test is something other that just building or install |
215 | # which would require more options. | 229 | # which would require more options. |
216 | my $buildonly = 1; | 230 | my $buildonly = 1; |
@@ -236,6 +250,12 @@ my $no_reboot = 1; | |||
236 | my $reboot_success = 0; | 250 | my $reboot_success = 0; |
237 | 251 | ||
238 | my %option_map = ( | 252 | my %option_map = ( |
253 | "MAILTO" => \$mailto, | ||
254 | "MAILER" => \$mailer, | ||
255 | "EMAIL_ON_ERROR" => \$email_on_error, | ||
256 | "EMAIL_WHEN_FINISHED" => \$email_when_finished, | ||
257 | "EMAIL_WHEN_STARTED" => \$email_when_started, | ||
258 | "EMAIL_WHEN_CANCELED" => \$email_when_canceled, | ||
239 | "MACHINE" => \$machine, | 259 | "MACHINE" => \$machine, |
240 | "SSH_USER" => \$ssh_user, | 260 | "SSH_USER" => \$ssh_user, |
241 | "TMP_DIR" => \$tmpdir, | 261 | "TMP_DIR" => \$tmpdir, |
@@ -1430,6 +1450,11 @@ sub dodie { | |||
1430 | print " See $opt{LOG_FILE} for more info.\n"; | 1450 | print " See $opt{LOG_FILE} for more info.\n"; |
1431 | } | 1451 | } |
1432 | 1452 | ||
1453 | if ($email_on_error) { | ||
1454 | send_email("KTEST: critical failure for your [$test_type] test", | ||
1455 | "Your test started at $script_start_time has failed with:\n@_\n"); | ||
1456 | } | ||
1457 | |||
1433 | if ($monitor_cnt) { | 1458 | if ($monitor_cnt) { |
1434 | # restore terminal settings | 1459 | # restore terminal settings |
1435 | system("stty $stty_orig"); | 1460 | system("stty $stty_orig"); |
@@ -4099,6 +4124,26 @@ sub set_test_option { | |||
4099 | return eval_option($name, $option, $i); | 4124 | return eval_option($name, $option, $i); |
4100 | } | 4125 | } |
4101 | 4126 | ||
4127 | sub _mailx_send { | ||
4128 | my ($subject, $message) = @_; | ||
4129 | system("$mailer -s \'$subject\' $mailto <<< \'$message\'"); | ||
4130 | } | ||
4131 | |||
4132 | sub _sendmail_send { | ||
4133 | my ($subject, $message) = @_; | ||
4134 | system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto"); | ||
4135 | } | ||
4136 | |||
4137 | sub send_email { | ||
4138 | if (defined($mailto) && defined($mailer)) { | ||
4139 | if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);} | ||
4140 | elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);} | ||
4141 | else { doprint "\nYour mailer: $mailer is not supported.\n" } | ||
4142 | } else { | ||
4143 | print "No email sent: email or mailer not specified in config.\n" | ||
4144 | } | ||
4145 | } | ||
4146 | |||
4102 | # First we need to do is the builds | 4147 | # First we need to do is the builds |
4103 | for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { | 4148 | for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { |
4104 | 4149 | ||
@@ -4139,9 +4184,15 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { | |||
4139 | $start_minconfig_defined = 1; | 4184 | $start_minconfig_defined = 1; |
4140 | 4185 | ||
4141 | # The first test may override the PRE_KTEST option | 4186 | # The first test may override the PRE_KTEST option |
4142 | if (defined($pre_ktest) && $i == 1) { | 4187 | if ($i == 1) { |
4143 | doprint "\n"; | 4188 | if (defined($pre_ktest)) { |
4144 | run_command $pre_ktest; | 4189 | doprint "\n"; |
4190 | run_command $pre_ktest; | ||
4191 | } | ||
4192 | if ($email_when_started) { | ||
4193 | send_email("KTEST: Your [$test_type] test was started", | ||
4194 | "Your test was started on $script_start_time"); | ||
4195 | } | ||
4145 | } | 4196 | } |
4146 | 4197 | ||
4147 | # Any test can override the POST_KTEST option | 4198 | # Any test can override the POST_KTEST option |
@@ -4305,4 +4356,8 @@ if ($opt{"POWEROFF_ON_SUCCESS"}) { | |||
4305 | 4356 | ||
4306 | doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n"; | 4357 | doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n"; |
4307 | 4358 | ||
4359 | if ($email_when_finished) { | ||
4360 | send_email("KTEST: Your [$test_type] test has finished!", | ||
4361 | "$successes of $opt{NUM_TESTS} tests started at $script_start_time were successful!"); | ||
4362 | } | ||
4308 | exit 0; | 4363 | exit 0; |