diff -r 000000000000 -r 83f4b4db085c bldsystemtools/commonbldutils/GenResult/GenPostBuildResult.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bldsystemtools/commonbldutils/GenResult/GenPostBuildResult.pm Tue Feb 02 01:39:43 2010 +0200 @@ -0,0 +1,578 @@ +# Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# Script summarise and hotlink autosmoketest logs by reading +# testdriver generated files +# +# + +#!/usr/bin/perl -w +package GenPostBuildResult; +use GenResult; +use strict; +use Net::SMTP; + +########################################################################## +# +# Name : getAVResults() +# Synopsis : To parse a logfile, and ouput results into a common +# data format for processing. +# +# Inputs : $iLogsPublication +# Output : A single variable that is passed to the final results HTML +# table. +# +########################################################################## +sub getAVResults { + +my ($iLogsPublishLocation) = @_; + +my $iAVFileName = "anti-virus.log"; +my $iAVError = ""; +my $iAVLogFileLocation = $iLogsPublishLocation.$iAVFileName; +my $iAVResult = "WARNING: Potential virus found, check anti-virus.log"; +my $iAVWarning = ""; +my $oldIdeFile = 0; +my $errorFound = 0; + +# mcafee specifics +my $iTotal = 0; +my $iClean = 0; + + if(-e $iAVLogFileLocation) { + + # id header from antivirus.log + my $iAVName = getAVProductName($iAVLogFileLocation); + + open (AVLOGFILE, $iAVLogFileLocation) or die "ERROR: Can't open file: $!"; + + my @iAVLog = ; + + if ($iAVName eq "SOPHOS") { + + foreach (@iAVLog){ + if(m/No viruses were discovered/i){ + $iAVResult = "No viruses were discovered"; + $iAVError = ""; + } + elsif(m/(is older than \d+ days)+/i){ + $oldIdeFile = 1; + } + elsif(m/errors? (was|were) encountered/i) { + $errorFound = 1; + } + } + + } elsif ($iAVName eq "MCAFEE") { + + foreach (@iAVLog){ + if (m/Total files:\s{1}\.*\s*([0-9]+)/i) { + $iTotal += $1; + } + elsif (m/Clean:\s{1}\.*\s*([0-9]+)/i) { + $iClean += $1; + } + } + + if ($iTotal eq $iClean) { + $iAVResult = "No viruses were discovered"; + $iAVError = ""; + } + } elsif ($iAVName eq "UNKNOWN") { + $iAVResult = " WARNING: Cannot Identify Anti-Virus product"; + $iAVError = ""; + } + + # generate-html-output + if( $oldIdeFile) { + $iAVWarning = " Virus Definition file needs to be updated"; + } + if($oldIdeFile && $errorFound) { + $iAVWarning .= "
"; + } + if( $errorFound) { + $iAVWarning .= " Error(s) encountered. See anti-virus.log"; + } + } + else{ + $iAVResult = "WARNING: Anti-virus.log file not found "; + $iAVError = ""; + } + + close AVLOGFILE; + +return ($iAVResult,$iAVWarning,$iAVError); +} + +# +# Identify AV Product +# - Sophos +# - McAfee +# - UnKnown +sub getAVProductName($) { + + my $iAVLogFileLocation = shift; + + my $iMcAfee = 0; + my $iSophos = 0; + + open (AVLOGFILE, $iAVLogFileLocation) or die "ERROR: Can't open file: $!"; + + my @iAVLog = ; + + foreach (@iAVLog){ + + if(m/McAfee VirusScan for Win32/i) { + $iMcAfee = 1; + last; + } + + if(m/Sophos Anti-Virus/i) { + $iSophos = 1; + last; + } + } + + # does not recognise "both" + return ($iMcAfee ? "MCAFEE" : + ($iSophos ? "SOPHOS" : "UNKNOWN")); + +} + +########################################################################## +# --- REQ9019 --- +# Name : getSidVidResults() +# Synopsis : To check if the SID-VID report for ROM images has been created +# using tools_imgcheck module during the build. +# Inputs : $iLogsPublishLocation +# Output : A single variable that is passed to the final results HTML +# table. +# +########################################################################## +sub getSidVidResults { + +my ($iLogsPublishLocation) = @_; + +my $iSidVidReportFileName = "sidvid.xml"; +my $iSidVidReportFileLocation = $iLogsPublishLocation.$iSidVidReportFileName; +my $iSidVidReportResult; + if(-e $iSidVidReportFileLocation) { + + $iSidVidReportFileLocation =~ s/\\/\//g; # swap backslashes to fwd slashes + + # create browser link + $iSidVidReportFileLocation = "file:///".$iSidVidReportFileLocation; + $iSidVidReportResult ="$iSidVidReportFileName"; + } + else{ + $iSidVidReportResult = "WARNING: SID/VID report $iSidVidReportFileName not found"; + } + +return ($iSidVidReportResult); +} + +########################################################################## +# +# Name : CDBfiletest() +# Synopsis : To test if the CDB report was created successfully. Submit +# result to the postbuild results table. +# +# Inputs : $iBCPrevious +# Output : A single variable that is passed to the final results HTML +# table. +# +########################################################################## +sub CDBFileTest{ + +my ($iLinkPathLocation, $iProduct, $iSnapshot, $imail) = @_; + +my $iBCPreviousXML = $iLinkPathLocation; +$iBCPreviousXML = $iBCPreviousXML."cdb-info\\bc-prev.xml"; +my $iBCBaseXML = $iLinkPathLocation; +$iBCBaseXML = $iBCBaseXML."cdb-info\\bc-base.xml"; + +my $iPrevTotal = "XML file not found"; +my $iPrevPublish = "XML file not found"; +my $iBaseTotal = "XML file not found"; +my $iBasePublish = "XML file not found"; + +my $size = 0; +my $errorMessageBase = ""; +my $errorMessagePrev = ""; + +my $iBCPreviousHTML = $iLinkPathLocation; +$iBCPreviousHTML = $iBCPreviousHTML."cdb-info\\BC-prev.html"; +my $iBCBaseHTML = $iLinkPathLocation; +$iBCBaseHTML = $iBCBaseHTML."cdb-info\\BC-base.html"; + +if (-e $iBCPreviousXML){ + + $iPrevTotal = "Keyword 'TotalBreaks' not found"; + $iPrevPublish = "Keyword 'PublishedPartner' not found"; + + open (BCPREV, $iBCPreviousXML) or die "ERROR: Can't open file: $!"; + + my @iBCPrev = ; + + foreach (@iBCPrev){ + + if(m/(totalBreaks count=")(\d+)/i){ + $iPrevTotal = $2; + } + + if(m/(publishedPartner" count=")(\d+)/i){ + $iPrevPublish = $2; + } + } + close BCPREV; + + if((uc($iLinkPathLocation) !~ m/TEST_BUILD/) && defined($imail) && $iPrevTotal>50){ + &SendEmail($iProduct,$iSnapshot,"The BC_Prev breaks are $iPrevTotal for Symbian v$iProduct $iSnapshot" );} + + #--DEF067716-- + + $size = (stat($iBCPreviousHTML))[7]; + + if ( -e $iBCPreviousHTML){ + if ($size == 0) { + $errorMessagePrev = " [ BC-prev html link invalid ]"; + } else { + my $bool = 0; + open (BCPREVHTML, $iBCPreviousHTML) or die "ERROR: Can't open file: $!"; + while(){ + if(m//){ + $bool = 1; + } + } + close BCPREVHTML; + if ($bool == 1){ + $errorMessagePrev = ""; + }else{ + $errorMessagePrev = " [ BC-prev: Not a HTML file ]"; + } + } + } else { + $errorMessagePrev = " [ BC-prev.html does not exist ]"; + } + + #-------------- + + } + +if (-e $iBCBaseXML){ + + $iBaseTotal = "Keyword 'TotalBreaks' not found"; + $iBasePublish = "Keyword 'PublishedPartner' not found"; + + open (BCBASE, $iBCBaseXML) or die "ERROR: Can't open file: $!"; + + my @iBCBase = ; + + foreach (@iBCBase){ + + if(m/(totalBreaks count=")(\d+)/i){ + $iBaseTotal = $2; + } + + if(m/(publishedPartner" count=")(\d+)/i){ + $iBasePublish = $2; + } + } + close BCBASE; + + if((uc($iLinkPathLocation) !~ m/TEST_BUILD/) && defined($imail) && $iBaseTotal>400){ + &SendEmail($iProduct,$iSnapshot,"The BC_Base breaks are $iBaseTotal for Symbian v$iProduct $iSnapshot" );} + #--DEF067716-- + + $size = (stat($iBCBaseHTML))[7]; + + if ( -e $iBCBaseHTML){ + if ($size == 0) { + $errorMessageBase = " [ BC-base html link invalid ]"; + }else { + my $bool = 0; + open (BCBASEHTML, $iBCBaseHTML) or die "ERROR: Can't open file: $!"; + while(){ + if(m//){ + $bool = 1; + } + } + close BCBASEHTML; + if ($bool == 1){ + $errorMessageBase = ""; + }else{ + $errorMessageBase = " [ BC-base: Not a HTML file ]"; + } + } + } else { + $errorMessageBase = " [ BC-base.html does not exist ]"; + } + + #-------------- + + } + +return ($iPrevTotal, $iPrevPublish, $iBaseTotal, $iBasePublish, $errorMessagePrev, $errorMessageBase); +} + +sub SendEmail +{ + my (@body, @message, $sender_address, $notification_address,$iProduct,$iSnap); + ($iProduct,$iSnap,@body) = @_; + $sender_address = 'I_EXT_SysBuildSupport@nokia.com'; + $notification_address = 'I_EXT_SysBuildSupport@nokia.com'; + + push @message,"From: $sender_address\n"; + push @message,"To: $notification_address\n"; + push @message,"Subject: Break Threshold CDB Notification $iSnap Symbian v$iProduct\n"; + push @message,"\n"; + push @message,@body; + + my $smtp = Net::SMTP->new('smtp.nokia.com', Hello => $ENV{COMPUTERNAME}, Debug => 0); + $smtp->mail(); + $smtp->to($notification_address); + + $smtp->data(@message) or die "ERROR: Sending message"; + $smtp->quit; +} +########################################################################## +# +# Name : CBRTime() +# Synopsis : To obtain the time of export for both the gt_techview and +# gt_only files and to report the status of the exported +# CBR's. +# +# Inputs : Export_gt_only_baseline.log, +# Export_gt_techview_baseline.log +# Output : To display the times in the post built results table. +# +# +########################################################################## +sub CBRTime{ + + my ($iLogsPublishLocation, $iProduct, $iSnapshot) = @_; + + + my $iOnlyResult = " Export Unsuccessful"; + my $iTechViewResult = "Export Unsuccessful"; + my $iOnlyTimes = ""; + my $iTechViewTime = ""; + # Error + my $iOnlyResultError = ""; + my $iTechViewResultError = ""; + my $iExportError = ""; + + if (-e $iLogsPublishLocation."Export_CBR.log") + { + open (ILOG, $iLogsPublishLocation."Export_CBR.log") or die "ERROR: Can't open file: $!"; + my $iOnlyExportFound = 0; + my $iTechviewExportFound = 0; + + while (my $line = ) + { + if( $line =~ m/Environment gt_only_baseline.*?successfully exported/i) + { + $iOnlyResult = "Export Successful"; + $iOnlyExportFound = 1; + } + + if( $line =~ m/gt_only_baseline.*?exportenv finsihed at\s+(.*)/i) + { + $iOnlyTimes = "".$1.""; + } + + if($line =~ m/Environment gt_techview_baseline.*?successfully exported/i) + { + $iTechViewResult = "Export Successful"; + $iTechviewExportFound = 1; + } + + if( $line =~ m/gt_techview_baseline.*?exportenv finsihed at\s+(.*)/i) + { + $iTechViewTime = "".$1.""; + } + + if( $line =~ m/ERROR: Failed to record delivery using template/i) + { + $iExportError = " Record Delivery Failed "; + } + + + } + + if($iOnlyExportFound == 0) + { + $iOnlyResultError = " [ Export Unsuccessful ]"; + $iOnlyTimes = "--"; + } + if($iTechviewExportFound == 0) + { + $iTechViewResultError = " [ Export Unsuccessful ]"; + $iTechViewTime = "--"; + } + close ILOG; + + } else { + $iOnlyResult = "Cannot find file"; + $iOnlyTimes = "Cannot find file"; + $iOnlyResultError = " [ File not found ]"; + $iTechViewResult = "Cannot find file"; + $iTechViewTime = "Cannot find file"; + $iTechViewResultError = " [ File not found ]"; + } + + return ($iOnlyResult, $iOnlyTimes, $iTechViewResult, $iTechViewTime, $iOnlyResultError, $iTechViewResultError, $iExportError); +} + +########################################################################## +# +# Name : generatesPostBuildSummary() +# Synopsis: Creates Post Build Table in Build Results. +# Inputs : Function parameters returned from genResult.pm that are to be +# implemented in the Post Build Results table. +# +# Outputs : HTML code that will be part of the HTML report generated +# for the final build results table. +########################################################################## +sub generatesPostBuildSummary{ + +my ($iLogsPublishLocation, $iLinkPathLocation, $iProduct, $iSnapshot, $imail) = @_; +my @CDBResArr = &CDBFileTest($iLinkPathLocation, $iProduct, $iSnapshot, $imail); +my @CBRResTime = &CBRTime($iLogsPublishLocation, $iProduct, $iSnapshot); +my @AVResults = &getAVResults($iLogsPublishLocation); +my $SidVidReportURL = &getSidVidResults($iLogsPublishLocation); + +my $SidVidReportResult = "SID/VID report generated."; + +if( $SidVidReportURL =~ /WARNING/){ + $SidVidReportResult = $SidVidReportURL; + $SidVidReportURL = " "; +} + +my $postbuild_html = "\n +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + "; + + # If it is a test build then do not evaluate the CBR Export time component, else implement the export table. + + if(GenResult::isTestBuild() eq "0"){ + + $postbuild_html=$postbuild_html." + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Post Build Results
   Defects
AntiVirus " . $AVResults[0] . "  " . $AVResults[1] . "  " . $AVResults[2] . "
SID VID Reports".$SidVidReportResult."".$SidVidReportURL." 
[CDB PREVIOUS]Total Number of Breaks: " . $CDBResArr[0] . " Breaks at Published Partner and Above: " . $CDBResArr[1] . "  " . "" . $CDBResArr[4] . "
[CDB BASE]Total Number of Breaks: " . $CDBResArr[2] . " Breaks at Published Partner and Above: " .$CDBResArr[3] . "  " . "" . $CDBResArr[5] . "
[CBR Export] GT_OnlyStatus: " . $CBRResTime[0] . " Time of Export: " . $CBRResTime[1] . "   " . $CBRResTime[4] . "
[CBR Export] TechViewStatus: " . $CBRResTime[2] . " Time of Export: " . $CBRResTime[3] . "   " . $CBRResTime[5] . "
Record Delivery Errors  " . $CBRResTime[6] . "   
+
+ "; + } + else{ + $postbuild_html=$postbuild_html." + +
"; + } +return $postbuild_html; +} + +1;