Received: by 10.213.65.68 with SMTP id h4csp48782imn; Fri, 6 Apr 2018 15:21:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+cn62fQajEdXjW4fG07jt/evyi4rPbogml1L1A1jie5pwlZoB0yQv2zy6AmOR00ahqqCZR X-Received: by 10.99.54.73 with SMTP id d70mr18365559pga.86.1523053282310; Fri, 06 Apr 2018 15:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523053282; cv=none; d=google.com; s=arc-20160816; b=QZ0CIFE4eFxiN7i28Yc5Sdv1iaXISYIWey73aMi2mHifuXNw5UiZcgza7kFYmpiV1T SoGytQvgHdQZQiJhWQDGdIYJSq/Uh9S1Xl+5n+aa30OKKhuD7J6eheN5t4cPWHQG9iNE KMPS053KA7C7E8eO4v6OC59kMR5GAzGsmc1XF0qkef1t1hmHa5NCS/15tndDX3xmtjnQ RntjKBd3zDCyGr8VHXO11N7OMYIVFSYqOGfne8QgADzy+gbrDsq9xzr4SPZFeWDzPHAi G3oysXkOOCUq+kp01ooqp9FaXfasL9BbJFSGiFDkjKlR2Jy5ODWoG3CB0sGohKew9wuq mnIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=UgmxYT4flDWTvZIjQTbqixWTrzGMLTTaV8OseMKb690=; b=iFQu51b2RmQkjvZrSf/zjETN45ZCWks/IaJ9QZCC/Psm3BaCErcexxFvys+i97tL7a syOj/DIaOiWzsocHG0tdgxRRODZ9AfA6Ys+E1U75fIS/+4WYzhlyob4BEY1bbGVk3mnb A3muFg6Nh4k3McCf84dpfExG9s/sko8PQUoAEFs5DQQZUtzzsphjXsBJ+i4JvnIq0Ik0 EEBPqO3BGEiArtoILuioe/rnv0neQipzpdMeqEHX6C/EuDoTS4PY2l9zO8W8Ec3GqjOt aqsnqp3HSPSzbbL/azRmgAOH9AAPm1m7bhtsoZQ3P1GgYiVjp2m1Lir0I+ovRdlch2A9 vHWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=AmqGSaiW; 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=pass (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 h4-v6si9202350pln.744.2018.04.06.15.20.45; Fri, 06 Apr 2018 15:21:22 -0700 (PDT) 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; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=AmqGSaiW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752521AbeDFWRa (ORCPT + 99 others); Fri, 6 Apr 2018 18:17:30 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:59494 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751679AbeDFWR2 (ORCPT ); Fri, 6 Apr 2018 18:17:28 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w36M4Geh023600; Fri, 6 Apr 2018 22:17:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=UgmxYT4flDWTvZIjQTbqixWTrzGMLTTaV8OseMKb690=; b=AmqGSaiW2sPGxWWScpsZhRFeHSaYRtZbO28nH/VutJILh0Kb3BRATe/S97RBg+8Od587 0vP2PY9pmPLCPVSUMV8kq8+WnW99I+U5RzoS9AXE2MXEAc/jxvHEJqF0lHLEXotOzk2n eeijdJPFcUhguobPWUxR6sfo1BJUv7Ix1ZaONJoDRzESzV4zPf17+b4bP5v/TcGxJ503 tr5k6uP8BD9HNxxcmOlVGput7M1u3KGwAtSmL9+Bu62q+9c9XQHSXs7SIffMdGjSR6i8 vEi2gSrJuX41v6c5kIV8u+IpfN9QeL/wSALWxzFFRsHDpb6gPXrgXGiDb/b3kgjIH2mQ sw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2h5k4bewua-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Apr 2018 22:17:25 +0000 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 w36MHOMe001917 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 6 Apr 2018 22:17:25 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w36MHNYG030168; Fri, 6 Apr 2018 22:17:24 GMT Received: from titichen-linux.us.oracle.com (/10.211.54.111) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 06 Apr 2018 15:17:23 -0700 From: Tim Tianyang Chen To: rostedt@goodmis.org Cc: linux-kernel@vger.kernel.org, dhaval.giani@oracle.com, tim.tianyang.chen@alumni.upenn.edu, Tim Tianyang Chen Subject: [PATCH v3 1/4] ktest: add email support Date: Fri, 6 Apr 2018 15:17:02 -0700 Message-Id: <1523053025-12424-2-git-send-email-tianyang.chen@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1523053025-12424-1-git-send-email-tianyang.chen@oracle.com> References: <1523053025-12424-1-git-send-email-tianyang.chen@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8855 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804060222 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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