Received: by 10.223.164.202 with SMTP id h10csp5514246wrb; Tue, 21 Nov 2017 10:54:35 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ4Od6nWc8sdw9dOscmGksHeFrbbcA+NdLEkLyGAnfxdChyVi/iXwEg0Ip+UNR3SgIT/BnM X-Received: by 10.99.135.199 with SMTP id i190mr17635674pge.356.1511290475273; Tue, 21 Nov 2017 10:54:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511290475; cv=none; d=google.com; s=arc-20160816; b=pxo3LVsTh9Lk7NxCMFLwuWrvh2CqkIkn0uw6QT+Pu231ZVs47CvHbW6YQkXMKdq5EQ RD4XeoLAltJM8PeQM5eoUepqDDQP7m+3tRB4FhRdZp7kVBaFIjAVNalhAHZhbHsDjt5x ogGNj1PcansZGGBFyPsY2tQhq8ZTAo+HrTLZcQ125Ned5ON/kziVX2d5yjCz3aXZHSNG K15+yKTRGOSR1VfoviXaaG7OvOoKP2rzk/IfiGIaUExNzgA6ODJWhh5evi2HxMC3h9tf SjpwZvcBIxjD+hVChtdqMRCUmlzmecgz+CPQKfxi5lncRpG7sR7F5v6S0CL42+z5MwrV +D1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:cc:to:references:subject:arc-authentication-results; bh=rwwjUzYmaIdRGqTdkp7NtXLVoUG0OpwL/XVhmdAppvY=; b=uHjeK24tGhBmGfmvvXgo3HOab0h1ul7keY+FFq1kWALQwKxfHx9wuHOFL3sNHZM2BE Hc0PvnHWA3bgk8UKHyVv7k+2v3K02pEX/wwPCbcJHru0nOilznfZxu2+uqw5tPMmj9Gj aoj6rNKN/96cRZz06S08tZcdJRADRykBH6C8+y+jw2YslU4qIlkhtxoRSAHxz79G6n7S 3qRk6yvyaKh4tN1SKyfHmUKgCXNK0fZAzlU2pAnANnjhvCtFEn/v22Gdr+bCf8/q2Ofe nPtcLmMrHkEC628v01gPNb/lJSjB67gzmn9O6y+fAOwWu7vsZY+eWG3ux7ji0C/8fy8P aZ9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 6si5787355pfs.283.2017.11.21.10.54.24; Tue, 21 Nov 2017 10:54:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751371AbdKUSxl (ORCPT + 76 others); Tue, 21 Nov 2017 13:53:41 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:42318 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751145AbdKUSxj (ORCPT ); Tue, 21 Nov 2017 13:53:39 -0500 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id vALIrZKH003255 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Nov 2017 18:53:35 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vALIrYZt028093 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Nov 2017 18:53:34 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id vALIrXoJ023457; Tue, 21 Nov 2017 18:53:33 GMT Received: from [10.1.10.119] (/173.161.222.85) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 21 Nov 2017 10:53:33 -0800 Subject: [PATCH 1/2][RFC]Ktest: Add email support References: <20171120173738.34823-2-tianyang.chen@oracle.com> To: rostedt@goodmis.org, linux-kernel@vger.kernel.org Cc: dhaval.giani@oracle.com From: Tim Tianyang Chen X-Forwarded-Message-Id: <20171120173738.34823-2-tianyang.chen@oracle.com> Message-ID: Date: Tue, 21 Nov 2017 10:53:32 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <20171120173738.34823-2-tianyang.chen@oracle.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Tim Tianyang Chen --- 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 From 1583891788950018506@xxx Sun Nov 12 20:01:59 +0000 2017 X-GM-THRID: 1583605276196187345 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread