secureswitools/swisistools/test/tinterpretsisinteg/testlistreader.pm
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 #
       
     2 # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 # Package contains routines to handle the parsing of the test list
       
    16 #
       
    17 
       
    18 package testlistreader;
       
    19 use strict;
       
    20 use File::Copy;
       
    21 my $Path = "\\epoc32\\winscw\\c\\tswi\\tinterpretsisinteg\\";
       
    22 my $domPath =  $Path."xml";
       
    23 my $runType = 0;
       
    24 mkdir($domPath);
       
    25 copy("/epoc32/tools/migrationtool/xml/dom.pm" , "$domPath");
       
    26 
       
    27 sub new {
       
    28     my $proto = shift;
       
    29     my $controller = shift;
       
    30 	$runType = shift;
       
    31     my $class = ref($proto) || $proto;
       
    32     my $self  = {};
       
    33     $self->{'verbose'} = 0;
       
    34     $self->{'currentTag'} = "";
       
    35     $self->{'controller'} = $controller;
       
    36 	$self->{'runType'} = $runType;
       
    37     bless ($self, $class);
       
    38     return $self;
       
    39 }
       
    40 
       
    41 # utility function to extract text associated with an XML tag
       
    42 sub getText {
       
    43     my ($self, $node, $tag) = @_;
       
    44 
       
    45     $self->{'currentTag'} = $tag;
       
    46     if ($node->getElementsByTagName($tag)->getLength > 0)
       
    47     {
       
    48 	my $text = $node->getElementsByTagName($tag)->item(0)->getFirstChild->getNodeValue;
       
    49 	return $text;
       
    50     }
       
    51     else
       
    52     {
       
    53 	return undef;
       
    54     }
       
    55 }
       
    56 
       
    57 sub parseFiles {
       
    58     my ($self, $specialFile, @normalFiles) = @_;
       
    59     my $controller = $self->{'controller'};
       
    60     my $firstDone = 0;
       
    61     foreach my $file (@normalFiles)
       
    62     {
       
    63 	my $base = 0;
       
    64 	if ($firstDone)
       
    65 	{
       
    66 	    $base = 0;
       
    67 	}
       
    68 	else
       
    69 	{
       
    70 	    $base = 1;
       
    71 	}
       
    72 	$firstDone = 0;
       
    73 	my $baseDir = $self->parseFile($file, $base);
       
    74 	$controller->setBaseDir($baseDir);
       
    75     }
       
    76     if (length($specialFile) > 0)
       
    77     {
       
    78 	my @order = $self->parseOnlyTests($specialFile);
       
    79 	$controller->setOrder(\@order);
       
    80     }
       
    81 }
       
    82 
       
    83 
       
    84 sub parseFile {
       
    85     my ($self, $filename) = @_;
       
    86     my $parser= XML::DOM::Parser->new();
       
    87     my $doc = $parser->parsefile($filename);
       
    88     my $controller = $self->{'controller'};
       
    89     my $baseDir="";
       
    90 
       
    91     my $getBase = 0;
       
    92 
       
    93     #the xml file must have a <testlist> tag
       
    94     my $root = $self->getText($doc, 'testlist');
       
    95     die "Missing tag <".$self->{'currentTag'}."> in $filename\n" if (!(defined $root));
       
    96 
       
    97     my $testCount = 0;
       
    98     foreach my $test ($doc->getElementsByTagName('test')) {
       
    99 	my %testEntry;
       
   100 	$testCount++;
       
   101 
       
   102 	# the test element must have an id attribute
       
   103 	my $testid = $test->getAttribute('id');
       
   104 	die "Must have the id attribute for test $testCount in file\n" if (length($testid) ==0);
       
   105 	
       
   106 	my $testtype = $test->getAttribute('type');
       
   107 	$testEntry{'id'} = $testid;
       
   108 
       
   109 	#add all the other elements in the test element to the current test entry
       
   110 	foreach my $elem ($test->getChildNodes)
       
   111 	{
       
   112 	    if ($elem->getNodeType == 1)
       
   113 	    {
       
   114 		#an element
       
   115 		my $key = $elem->getNodeName;
       
   116 		my $value = undef;
       
   117 		if (length($elem->getFirstChild) > 0)
       
   118 		{
       
   119 			$value = $elem->getFirstChild->getNodeValue;
       
   120 		}
       
   121 		$testEntry{$key} = $value;
       
   122 		#some of the elements have attributes. These also need to be 
       
   123 		#added to the current test entry
       
   124 
       
   125 		if ($key eq "command")
       
   126 		{
       
   127 		    $testEntry{'command_dir'} = $elem->getAttribute('dir');
       
   128 		    my $log = $elem->getAttribute('log');
       
   129 		    if (length($log))
       
   130 		    {
       
   131 			if (lc($log) =~/yes/)
       
   132 			{
       
   133 			    $testEntry{'log'} = 1;
       
   134 			}
       
   135 			else
       
   136 			{
       
   137 			    $testEntry{'log'} = 0;
       
   138 			}
       
   139 		    }
       
   140 		    else
       
   141 		    {
       
   142 			$testEntry{'log'} = 1;
       
   143 		    }
       
   144 		}
       
   145 		elsif ($key eq "check")
       
   146 		{
       
   147 
       
   148 		    my $c_type = $elem->getAttribute('type');
       
   149 		    $testEntry{'check_type'} = $c_type if (length($c_type));
       
   150 		  
       
   151 		    my $c_prog = $elem->getAttribute('name');
       
   152 		    $testEntry{'check_prog'} = $c_prog if (length($c_prog));
       
   153 		    # check if base results directory is required for checking
       
   154 		    # the results
       
   155 		    if (exists($testEntry{'check_type'}))
       
   156 		    {
       
   157 			$getBase = 1 if ($testEntry{'check_type'} eq "diff" );
       
   158 		    }
       
   159 		}
       
   160 	    }
       
   161 	}
       
   162 
       
   163 	#now check that all the mandatory elements and attribute exist
       
   164 	if ($getBase)
       
   165 	{
       
   166 	    $baseDir = $self->getText($doc, 'baseResultDir');
       
   167 	    die "Missing tag <".$self->{'currentTag'}."> in $filename\n" if (!(defined $baseDir));
       
   168 	}
       
   169 	die "Empty or missing 'title' tag for test " . $testEntry{'id'} . "\n" if (length($testEntry{'title'}) == 0);
       
   170 	die "Empty or missing 'command' tag for test " . $testEntry{'id'} . "\n" if (length($testEntry{'command'}) == 0);
       
   171 	die "Empty or missing 'check' tag with 'type' attribute for test " . $testEntry{'id'} . "\n" if (length($testEntry{'check_type'}) == 0);
       
   172 
       
   173 	die "Invalid 'type' attribute value (" . $testEntry{'check_type'} . ") for 'check' tag test " . $testEntry{'id'} . "\n" if ($testEntry{'check_type'} ne "diff" && $testEntry{'check_type'} ne "program" && $testEntry{'check_type'} ne "result") ;
       
   174 	if (length($testtype))
       
   175 	{
       
   176 	    $testEntry{'type'} = $testtype;
       
   177 	}
       
   178 	else
       
   179 	{
       
   180 	    $testEntry{'type'} = 'basic';
       
   181 	}
       
   182 	# if the test is for 9.6 & future release and the type is nativeonly
       
   183 	# do not include it in the entry
       
   184 	if(nativeOnly($self->{'runType'},$testtype))
       
   185 		{
       
   186 		$controller->addTest(\%testEntry);
       
   187 		}
       
   188     }
       
   189     return $baseDir;
       
   190     $doc->dispose;
       
   191 }
       
   192 
       
   193 sub nativeOnly()
       
   194 	{
       
   195 	my ($runType,$type) = @_;
       
   196 	if( ($runType eq "usifnative") && ($type eq "nativeonly") )
       
   197 		{
       
   198 		return 0;
       
   199 		}
       
   200 	return 1;
       
   201 	}
       
   202 
       
   203 # parse a XML file with test references only
       
   204 sub parseOnlyTests {
       
   205     my ($self, $filename) = @_;
       
   206     my $controller = $self->{'controller'};
       
   207     my $parser= XML::DOM::Parser->new();
       
   208     my $doc = $parser->parsefile($filename);
       
   209     my @newOrder;
       
   210 
       
   211     # file only contains list of tests to be executed
       
   212     foreach my $test ($doc->getElementsByTagName('test')) {
       
   213 	my $testid = $test->getAttribute('id');
       
   214 	push @newOrder, $testid;
       
   215     }
       
   216     $doc->dispose;
       
   217     return @newOrder;
       
   218 }
       
   219 
       
   220 1;