symport/symfile/test.pl
changeset 1 0a7b44b10206
child 2 806186ab5e14
equal deleted inserted replaced
0:c55016431358 1:0a7b44b10206
       
     1 #!/usr/bin/perl
       
     2 
       
     3 # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 # All rights reserved.
       
     5 # This component and the accompanying materials are made available
       
     6 # under the terms of the License "Symbian Foundation License v1.0"
       
     7 # which accompanies this distribution, and is available
       
     8 # at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     9 #
       
    10 # Initial Contributors:
       
    11 # Nokia Corporation - initial contribution.
       
    12 #
       
    13 # Contributors:
       
    14 #
       
    15 # Description:
       
    16 #
       
    17 
       
    18 use strict;
       
    19 use warnings;
       
    20 use Test;
       
    21 use Getopt::Long qw(:config auto_version auto_help);
       
    22 use File::Spec::Functions;
       
    23 use File::Basename;
       
    24 
       
    25 # The following are the tests to run
       
    26 BEGIN { plan tests => 6 }
       
    27 
       
    28 # Make sure we're in the correct folder
       
    29 chdir('../symfile') or die "Failed to set folder: $!";
       
    30 
       
    31 # Version of the script - just use the date
       
    32 $main::VERSION = '02-Oct-08';
       
    33 
       
    34 # Get command line arguments
       
    35 print "\n";
       
    36 my ( $verbose, $skip );
       
    37 GetOptions("verbose" => \$verbose, "skip" => \$skip) or pod2usage(2);
       
    38 
       
    39 # Get OS version
       
    40 my $win32 = 1 if $^O =~ /MSWin32/;
       
    41 print "Running on Win32\n" if $win32 && $verbose;
       
    42 print "Running on Linux\n" if !$win32 && $verbose;
       
    43 
       
    44 # Build the code
       
    45 doBuild() if (!$skip);
       
    46 
       
    47 # Run the tests
       
    48 doTest('deb', 't_symfile');
       
    49 doTest('rel', 't_symfile');
       
    50 doTest('deb', 't_symfile_dll');
       
    51 doTest('rel', 't_symfile_dll');
       
    52 
       
    53 # Run tests in emulator to check compatibility
       
    54 if ($win32)
       
    55 	{
       
    56 	doEmuTest(catfile($ENV{EPOCROOT}, 'epoc32', 'release', 'winscw', 'udeb', 't_symfile.exe'));
       
    57 	doEmuTest(catfile($ENV{EPOCROOT}, 'epoc32', 'release', 'winscw', 'urel', 't_symfile.exe'));
       
    58 	}
       
    59 else
       
    60 	{
       
    61 	# No emulator on Linux
       
    62 	ok(1);
       
    63 	ok(1);
       
    64 	}
       
    65 
       
    66 # ***
       
    67 # Runs test code
       
    68 #
       
    69 sub doTest
       
    70 	{
       
    71 	my ( $variant, $name ) = @_;
       
    72 
       
    73 	my $test;
       
    74 	if ($win32)
       
    75 		{
       
    76 		$test = catfile($ENV{EPOCROOT}, 'epoc32', 'release', 'tools2', $variant, "$name.exe");
       
    77 		}
       
    78 	else
       
    79 		{
       
    80 		# Have to set library path for Linux
       
    81 		$ENV{LD_LIBRARY_PATH} =~ s[/epoc32[^:]+:/][];
       
    82 		$ENV{LD_LIBRARY_PATH} = "$ENV{EPOCROOT}epoc32/release/tools2/linux-i386/$variant:$ENV{LD_LIBRARY_PATH}";
       
    83 		$test = catfile($ENV{EPOCROOT}, 'epoc32', 'release', 'tools2', 'linux-i386', $variant, $name);
       
    84 		}
       
    85 
       
    86 	die "Can't find test exe: $test" if !-e $test;
       
    87 	print "Running test: $test\n" if $verbose;
       
    88 
       
    89 	my $pass;
       
    90 	open TEST, "$test|" or die "Failed to start test $test: $!";
       
    91 	while(my $line = <TEST>)
       
    92 		{
       
    93 		next unless $line =~ /RTEST: /;
       
    94 		print "\t$line" if $verbose;
       
    95 		$pass = 1 if $line =~ /^RTEST: SUCCESS/ or $line =~ /TEST Successfully Completed/;
       
    96 		}
       
    97 
       
    98 	close TEST;
       
    99 	print "FAIL: $test\n" if (!$pass);
       
   100 	ok($pass);
       
   101 	}
       
   102 
       
   103 # ***
       
   104 # Runs emulator test code
       
   105 #
       
   106 sub doEmuTest
       
   107 	{
       
   108 	my $test = shift;
       
   109 	die "Can't find test exe: $test" if !-e $test;
       
   110 	print "Running emulator test: $test\n" if $verbose;
       
   111 	my $vis = $verbose ? 'textshell' : 'NoGui';
       
   112 
       
   113 	# Make sure the log file doesn't exist
       
   114 	my $logfile = catfile($ENV{TEMP}, 'epocwind.out');
       
   115 	unlink $logfile;
       
   116 
       
   117 	# Start the emulator	
       
   118 	die "Failed to Launch emulator for $test: $!" if system("$test -D$vis --") != 0;
       
   119 
       
   120 	# Check the log file
       
   121 	my $pass;
       
   122 	open LOG, $logfile, or die "Failed open log file $logfile: $!";
       
   123 	while(my $line = <LOG>)
       
   124 		{
       
   125 		next unless $line =~ /RTEST: /;
       
   126 
       
   127 		$line =~ s/^.*\t//;
       
   128 		chomp $line;
       
   129 
       
   130 		# Next line contains the test description
       
   131 		my $nextline = <LOG>;
       
   132 		$nextline =~ s/^.*\t//;
       
   133 		$line .= $nextline;
       
   134 
       
   135 		print "\t$line" if $verbose;
       
   136 		$pass = 1 if $line =~ /^RTEST: SUCCESS/ or $line =~ /TEST Successfully Completed/;
       
   137 		}
       
   138 	close LOG;
       
   139 	print "FAIL: $test\n" if (!$pass);
       
   140 	ok($pass);
       
   141 	}
       
   142 
       
   143 # ***
       
   144 # Builds the test code
       
   145 # *
       
   146 sub doBuild
       
   147 	{
       
   148 	# First of all see if SBSv2 is installed
       
   149 	my $sbs_ver = 1;
       
   150 	open SBS, 'sbs -v 2>&1|' or die "Failed to execute command: $!";
       
   151 	while(<SBS>)
       
   152 		{
       
   153 		if (/^sbs version/)
       
   154 			{
       
   155 			$sbs_ver = 2;
       
   156 			last;
       
   157 			}
       
   158 		}
       
   159 	close SBS;
       
   160 	
       
   161 	# Override the result using environment variable
       
   162 	$sbs_ver = 1 if $ENV{SBS_VERSION} && $ENV{SBS_VERSION} == 1;
       
   163 	my $redir = $verbose?'':' >nul 2>&1';
       
   164 
       
   165 	# Now build the test code - assumes current working directory is correct!
       
   166 	print "Building test code using SBSv$sbs_ver\n";
       
   167 	if ($sbs_ver == 1)
       
   168 		{
       
   169 		# Use the old build system
       
   170 		system("bldmake bldfiles$redir");
       
   171 		system("abld test makefile$redir");
       
   172 		system("abld test clean$redir");
       
   173 		system("abld test build$redir");
       
   174 		}
       
   175 	else
       
   176 		{
       
   177 		# Use the new build system
       
   178 		system("sbs -c tools2.test CLEAN$redir");
       
   179 		system("sbs -c tools2.test$redir");
       
   180 		system("sbs -c winscw.test CLEAN$redir");
       
   181 		system("sbs -c winscw.test$redir");
       
   182 		}
       
   183 	}
       
   184 
       
   185 =head1 NAME
       
   186 
       
   187 test.pl - A script for running tests
       
   188 
       
   189 =head1 SYNOPSIS
       
   190 
       
   191 test.pl [-help] [-version] [-verbose] [-skip]
       
   192 
       
   193  Options:
       
   194    -help      brief help message
       
   195    -version   version of the script
       
   196    -verbose   print what the scripts does
       
   197    -skip      skip building the code
       
   198 
       
   199 =cut