symport/symuser/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 use File::Copy;
       
    25 
       
    26 # The following are the tests to run
       
    27 BEGIN { plan tests => 60 }
       
    28 my @tests = qw/t_bflat t_bseg t_buf t_rbuf t_char t_circ t_collate t_des t_farray t_func t_graph t_key t_lex t_match t_parray t_que t_readar t_regn t_sque t_varray t_versio t_hashtab t_huff t_float t_i64 t_i64_2 t_math t_math2 t_trap t_ctrap/;
       
    29 
       
    30 # Make sure we're in the correct folder
       
    31 chdir('../symuser') or die "Failed to set folder: $!";
       
    32 
       
    33 # Version of the script - just use the date
       
    34 $main::VERSION = '13-Oct-08';
       
    35 
       
    36 # Get command line arguments
       
    37 print "\n";
       
    38 my ( $verbose, $skip );
       
    39 GetOptions("verbose" => \$verbose, "skip" => \$skip) or pod2usage(2);
       
    40 
       
    41 my $win32 = 1 if $^O =~ /MSWin32/;
       
    42 print "Running on Win32\n" if $win32 && $verbose;
       
    43 print "Running on Linux\n" if !$win32 && $verbose;
       
    44 
       
    45 # Some files have to be copied to an accessible location
       
    46 unlink 'UnicodeData.txt';
       
    47 copy(catfile('..', 'e32test', 'buffer', 'UnicodeData.txt'), 'unicodedata.txt') or die "Failed to copy file: $!";
       
    48 
       
    49 # Build the code and run the tests
       
    50 doBuild() if (!$skip);
       
    51 foreach my $test ( @tests )
       
    52 	{
       
    53 	doTest('deb', $test);
       
    54 	doTest('rel', $test);
       
    55 	}
       
    56 
       
    57 # ***
       
    58 # Runs test code
       
    59 #
       
    60 sub doTest
       
    61 	{
       
    62 	my ( $variant, $name ) = @_;
       
    63 
       
    64 	my $test;
       
    65 	if ($win32)
       
    66 		{
       
    67 		$test = catfile($ENV{EPOCROOT}, 'epoc32', 'release', 'tools2', $variant, "$name.exe");
       
    68 		}
       
    69 	else
       
    70 		{
       
    71 		# Have to set library path for Linux
       
    72 		$ENV{LD_LIBRARY_PATH} =~ s[/epoc32[^:]+:/][];
       
    73 		$ENV{LD_LIBRARY_PATH} = "$ENV{EPOCROOT}epoc32/release/tools2/linux-i386/$variant:$ENV{LD_LIBRARY_PATH}";
       
    74 		$test = catfile($ENV{EPOCROOT}, 'epoc32', 'release', 'tools2', 'linux-i386', $variant, $name);
       
    75 		}
       
    76 
       
    77 	die "Can't find test exe: $test" if !-e $test;
       
    78 	print "Running test: $test\n" if $verbose;
       
    79 
       
    80 	my $pass;
       
    81 	open TEST, "$test|" or die "Failed to start test $test: $!";
       
    82 	while(<TEST>)
       
    83 		{
       
    84 		print "\t$_" if $verbose;
       
    85 		$pass = 1 if /^RTEST: SUCCESS/ or /TEST Successfully Completed/;
       
    86 		}
       
    87 
       
    88 	print "FAIL: $test\n" if (!$pass);
       
    89 	ok($pass);	
       
    90 	close TEST;
       
    91 	}
       
    92 
       
    93 # ***
       
    94 # Builds the test code
       
    95 # *
       
    96 sub doBuild
       
    97 	{
       
    98 	# First of all see if SBSv2 is installed
       
    99 	my $sbs_ver = 1;
       
   100 	open SBS, 'sbs -v 2>&1|' or die "Failed to execute command: $!";
       
   101 	while(<SBS>)
       
   102 		{
       
   103 		if (/^sbs version/)
       
   104 			{
       
   105 			$sbs_ver = 2;
       
   106 			last;
       
   107 			}
       
   108 		}
       
   109 	close SBS;
       
   110 	
       
   111 	# Override the result using environment variable
       
   112 	$sbs_ver = 1 if $ENV{SBS_VERSION} && $ENV{SBS_VERSION} == 1;
       
   113 	my $nul = $win32 ? 'nul' : '/dev/null';
       
   114 	my $redir = $verbose? '' : " >$nul 2>&1";
       
   115 
       
   116 	# Now build the test code - assumes current working directory is correct!
       
   117 	print "Building test code using SBSv$sbs_ver\n" if $verbose;
       
   118 	if ($sbs_ver == 1)
       
   119 		{
       
   120 		print "Building test code using SBSv1\n";
       
   121 
       
   122 		# Use the old build system
       
   123 		system("bldmake bldfiles$redir");
       
   124 		system("abld test makefile$redir");
       
   125 		system("abld test clean$redir");
       
   126 		system("abld test build$redir");
       
   127 		}
       
   128 	else
       
   129 		{
       
   130 		print "Building test code using SBSv2\n";
       
   131 
       
   132 		# Use the new build system
       
   133 		system("sbs -c tools2.test CLEAN$redir");
       
   134 		system("sbs -c tools2.test$redir");
       
   135 		}
       
   136 	}
       
   137 
       
   138 =head1 NAME
       
   139 
       
   140 test.pl - A script for running tests
       
   141 
       
   142 =head1 SYNOPSIS
       
   143 
       
   144 test.pl [-help] [-version] [-verbose] [-skip]
       
   145 
       
   146  Options:
       
   147    -help      brief help message
       
   148    -version   version of the script
       
   149    -verbose   print what the scripts does
       
   150    -skip      skip building the code
       
   151 
       
   152 =cut