bldsystemtools/commonbldutils/GenResult/smoketest.tmpl
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 31 Mar 2010 23:20:42 +0300
branchRCL_3
changeset 20 a9d4531388d0
permissions -rw-r--r--
Revision: 201013 Kit: 201013

[@--# Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
# All rights reserved.
# This component and the accompanying materials are made available
# under the terms of the License "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:
# Template processed by GenDiamondsXml.pm
# 
#--@]
<?xml version="1.0" encoding="utf-8"?>
<diamonds-build>
  <schema>[@--$ENV{DiamondsSchemaNum}--@]</schema>
[@--
  use myutils;  
  use GenAutoSmokeTestResult;
  our $Gtotal = 0;
  our $Gexecuted = 0 ;
  our $Gsuccessful =0;
  our $Gnot_tested = 0 ;
  our $Gfailed  = 0 ;
  our $Gtestcases;
  our $Gtitle = "";

  my $iDir = &myutils::getiDir();
  my $iSnapshot = &myutils::getiSnapshot();
  my $iProduct = &myutils::getiProduct();
  my $iLinkPath = &myutils::getiLinkPath();


 {
	#my $str = PlanTxtAutoSmokeTestResult('.\\', "MSF00290", "tb92sf", '.\\');
	my $str = PlanTxtAutoSmokeTestResult($iDir, $iSnapshot, $iProduct, $iLinkPath);
	
	if ($str ne undef) #not empty
	{
		$Gtestcases = resultTestCasesXMLbody($str);
		$Gtotal = $Gsuccessful+ $Gnot_tested+ $Gfailed;	# total number of testcases
	}	
}
$OUT = '';#return value

#  _html2text HTML formate convert to plan text string.
#  input a html string
#  ouput smiplified text
sub _html2text {
	my ($str) = shift(@_);

	$str =~ s/\n//sg;	# Remove all obsolete newlines.

	# Link:
	$str =~ s/<a[ ]+.*?>(.+)<\/a>/$1/ig;

	# Table:
	$str =~ s/<\/?table[ ]*.*?>/\n/ig;
	$str =~ s/<td[ ]*.*?>/\t/ig;
	$str =~ s/<tr[ ]*.*?>/\n/ig;
	$str =~ s/<th[ ]*.*?>/\t/ig;
	
	# Cleaning up:
	$str =~ s/<.*?>//sg;		# Remove all tags.
	$str =~ s/\n[ ]+\n/\n\n/sg;	# Remove all obsolete spaces.
	$str =~ s/\n[ ]+/\n/sg;
	$str =~ s/\n{2,}/\n\n/sg;	# Remove all obsolete newlines.
	$str =~ s/^[ ]*//g;		# Remove all leading spaces (again).
	$str =~ s/[ ]+/ /g;		# Remove all duplicate spaces (again).

	$str =~ s/[\t\t]+/\t/g;
	return $str;
}

sub PlanTxtAutoSmokeTestResult
{
	my ($iLogsPublishLocation, $iSnapshot, $iProduct, $iLinkPathLocation) = @_;
	my $str;
	$str =  GenAutoSmokeTestResult::generateSTHTMLSummary($iLogsPublishLocation."AutoSmokeTest", $iSnapshot, $iProduct, $iLinkPathLocation."AutoSmokeTest");
	$str =~ s/[\t]+//g; # Remove extra \t. the \t was gen by GenSmokeTestResult.pm

	$str = _html2text($str);

	$str =~ s/&nbsp//g; #remove &nbsp
	$str =~ s/\n\t/\n/g;#remove \t at head
	$str =~ s/\n\n/\n/g;
	$str=~ s/^\n//g;#remove first empy line
	return $str;
}

sub resultTestCasesXMLbody
{
	my ($str) = shift (@_);
	my @lines = split(/\n/,$str);
	#print Dumper(\@lines);
	$Gtitle =  $lines[0];#Auto Smoke Test
	@results = @lines[2..$#lines];
	#print Dumper(\@results);

	my $ret ="<testcases>\n";
	my @testTitle = split (/\t/, $lines[1]);
	foreach my $APlatform (@results)
	{
		my @result = split (/\t/, $APlatform);	
		$plat = $result[0];# platform name;
		$result[1];# Summary
		$result[2];# Time World
		$result[3];# Contacts
		$result[4];# Messaging
		$result[5];# Agenda
		$result[6];# Defects
		for (my $i =2;$i<6;++$i)
		{
			$ret .= "<testcase>\n<name>".$plat.$testTitle[$i]."</name>\n";
			$ret .= "<status>".$result[$i]."</status>\n";		
			$ret .= "</testcase>\n";
			if ($result[$i] =~/FAILURES/)
			{$Gexecuted++;
			$Gfailed++;}	#FAILURES
			elsif( $result[$i] =~/Unexecuted/) 
			{$Gnot_tested++;}#Unexecuted
			elsif ( $result[$i] =~/OK/)
			{$Gexecuted++;
			$Gsuccessful++;}#OK
			
		}
	}
	$ret .="</testcases>\n";
	return $ret;
}

--@]
	<tests>
		<test_results>
			<test type="[@--$Gtitle--@]">
			<total>[@--$Gtotal--@]</total>
			<executed>[@--$Gexecuted--@]</executed>
			<successful>[@--$Gsuccessful--@]</successful>
			<failed>[@--$Gfailed--@]</failed>
			<not_tested>[@--$Gnot_tested--@]</not_tested>			
			[@--$Gtestcases--@]
			</test>
		</test_results>
	</tests>
</diamonds-build>