symport/bldtest/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 Cwd;
       
    25 
       
    26 # The following are the tests to run
       
    27 BEGIN { plan tests => 96 }
       
    28 
       
    29 # Make sure we're in the correct folder
       
    30 chdir('../bldtest') or die "Failed to set folder: $!";
       
    31 
       
    32 # Version of the script - just use the date
       
    33 $main::VERSION = '09-Oct-08';
       
    34 
       
    35 # Get command line arguments
       
    36 print "\n";
       
    37 my ( $verbose, $ignore );
       
    38 GetOptions("verbose" => \$verbose, "ignore" => \$ignore) or pod2usage(2);
       
    39 
       
    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 # Test new build system
       
    45 my $flm = catfile($ENV{SBS_HOME}, 'lib', 'flm', 'x86tool.xml');
       
    46 my $tem = catfile($ENV{EPOCROOT}, 'epoc32', 'tools', 'makefile_templates', 'tools', 'x86tool.mk');
       
    47 
       
    48 warn "FLM $flm doesn't exist?" if !-e $flm;
       
    49 print "Testing SBSv2 with FLM\n";
       
    50 rename $tem, "$tem.disabled";
       
    51 $ENV{SBS_VERSION} = 2 if $win32;
       
    52 doCheck('deb');
       
    53 doCheck('rel');
       
    54 rename "$tem.disabled", $tem;
       
    55 
       
    56 # Disable the FLM if it exists and run test with the TEM
       
    57 print "Testing SBSv2 with TEM\n";
       
    58 rename $flm, "$flm.disabled";
       
    59 doCheck('deb');
       
    60 doCheck('rel');
       
    61 rename "$flm.disabled", $flm;
       
    62 
       
    63 # Test old build system
       
    64 print "Testing SBSv1 with TEM\n";
       
    65 if ($win32)
       
    66 	{
       
    67 	$ENV{SBS_VERSION} = 1;
       
    68 	doCheck('deb');
       
    69 	doCheck('rel');
       
    70 	}
       
    71 else
       
    72 	{
       
    73 	# No such thing on Linux - just keep Test happy
       
    74 	for(my $i = 1; $i <= 32; $i++)
       
    75 		{
       
    76 		ok(1);
       
    77 		}
       
    78 	}
       
    79 
       
    80 # ***
       
    81 # Check everything works
       
    82 #
       
    83 sub doCheck
       
    84 	{
       
    85 	my $variant = shift;
       
    86 
       
    87 	# Have to set library path for Linux
       
    88 	if (!$win32)
       
    89 		{
       
    90 		$ENV{LD_LIBRARY_PATH} =~ s[/epoc32[^:]+:/][];
       
    91 		$ENV{LD_LIBRARY_PATH} = "$ENV{EPOCROOT}epoc32/release/tools2/linux-i386/$variant:$ENV{LD_LIBRARY_PATH}";
       
    92 		}
       
    93 
       
    94 	# Build the code
       
    95 	my $sbs_ver = doBuild($variant);
       
    96 
       
    97 	# File extensions differ on Windows and Linux
       
    98 	my ( $ext_exe, $ext_dll ) = $win32 ? ( '.exe', '.dll' ) : ( '', '.so' );
       
    99 
       
   100 	# Generate string for the location of built file in epoc tree
       
   101 	my $release = catfile($ENV{EPOCROOT}, 'epoc32', 'release', 'tools2');
       
   102 	$release = catfile($release, 'linux-i386') if !$win32;
       
   103 	$release = catfile($release, '%s', '%s%s');
       
   104 
       
   105 	# The simple test should pass
       
   106 	doTest(sprintf($release, $variant, 'testexe', $ext_exe));
       
   107 	doTest(sprintf($release, $variant, 'testexe_main.test', ''));
       
   108 
       
   109 	# Check that the exe and lib have been built
       
   110 	checkExist(sprintf($release, $variant, 'testexe', $ext_exe));
       
   111 	checkExist(sprintf($release, $variant, 'testexe_main.test', ''));
       
   112 	checkExist(sprintf($release, $variant, 'libteststatic', '.a'));
       
   113 	checkExist(sprintf($release, $variant, 'libtestdll', $ext_dll));
       
   114 
       
   115 	# Check all the files exist
       
   116 	if ($sbs_ver == 1)
       
   117 		{
       
   118 		my $build = catfile($ENV{EPOCROOT}, 'epoc32', 'build', cwd(), 'wrappermakefiles', '%s', cwd(), '%s');
       
   119 		$build =~ s/\w:\\//g;
       
   120 
       
   121 		# Check the object files exist
       
   122 		checkExist(sprintf($build, $variant, 'testexe.cpp.o'));
       
   123 		checkExist(sprintf($build, $variant, 'teststatic.cpp.o'));
       
   124 		checkExist(sprintf($build, $variant, 'testdll.cpp.o'));
       
   125 
       
   126 		# Clean should delete everything
       
   127 		doClean($sbs_ver, $variant);
       
   128 	
       
   129 		# Object files should be gone now
       
   130 		checkMissing(sprintf($build, $variant, 'testexe.cpp.o'));
       
   131 		checkMissing(sprintf($build, $variant, 'teststatic.cpp.o'));
       
   132 		checkMissing(sprintf($build, $variant, 'testdll.cpp.o'));
       
   133 		}
       
   134 	else
       
   135 		{
       
   136 		my $build;
       
   137 
       
   138 		# Build location differs between the TEM and FLM
       
   139 		my $flm = catfile($ENV{SBS_HOME}, 'lib', 'flm', 'x86tool.xml');
       
   140 		if (-e $flm)
       
   141 			{
       
   142 			my $cwd = cwd();
       
   143 			$cwd =~ s/$ENV{HOME}// if $ENV{HOME};
       
   144 			$build = catfile($ENV{EPOCROOT}, 'epoc32', 'build', 'x86tools', '%s', '%s', $cwd, '%s');
       
   145 			$build =~ s/\w:\\//g;
       
   146 
       
   147 			# Check the object files exist
       
   148 			checkExist(sprintf($build, $variant, 'testexe', 'testexe.cpp.o'));
       
   149 			checkExist(sprintf($build, $variant, 'teststatic', 'teststatic.cpp.o'));
       
   150 			checkExist(sprintf($build, $variant, 'testdll', 'testdll.cpp.o'));
       
   151 	
       
   152 			# Clean should delete everything
       
   153 			doClean($sbs_ver, $variant);
       
   154 	
       
   155 			# Object files should be gone now
       
   156 			checkMissing(sprintf($build, $variant, 'testexe', 'testexe.cpp.o'));
       
   157 			checkMissing(sprintf($build, $variant, 'teststatic', 'teststatic.cpp.o'));
       
   158 			checkMissing(sprintf($build, $variant, 'testdll', 'testdll.cpp.o'));
       
   159 			}
       
   160 		else
       
   161 			{
       
   162 			$build = catfile($ENV{EPOCROOT}, 'epoc32', 'build', '%s', cwd(), '%s');
       
   163 			$build =~ s/\w:\\//g;
       
   164 
       
   165 			# Check the object files exist
       
   166 			checkExist(sprintf($build, $variant, 'testexe.cpp.o'));
       
   167 			checkExist(sprintf($build, $variant, 'teststatic.cpp.o'));
       
   168 			checkExist(sprintf($build, $variant, 'testdll.cpp.o'));
       
   169 	
       
   170 			# Clean should delete everything
       
   171 			doClean($sbs_ver, $variant);
       
   172 	
       
   173 			# Object files should be gone now
       
   174 			checkMissing(sprintf($build, $variant, 'testexe.cpp.o'));
       
   175 			checkMissing(sprintf($build, $variant, 'teststatic.cpp.o'));
       
   176 			checkMissing(sprintf($build, $variant, 'testdll.cpp.o'));
       
   177 			}
       
   178 		}
       
   179 
       
   180 	# Releaseables should be gone
       
   181 	checkMissing(sprintf($release, $variant, 'testexe', $ext_exe));
       
   182 	checkMissing(sprintf($release, $variant, 'testexe_main.test', ''));
       
   183 	checkMissing(sprintf($release, $variant, 'libteststatic', '.a'));
       
   184 	checkMissing(sprintf($release, $variant, 'libtestdll', $ext_dll));
       
   185 	}
       
   186 
       
   187 sub checkExist
       
   188 	{
       
   189 	my $file = shift;
       
   190 	print "Checking file exists: $file\n" if $verbose;
       
   191 	ok(-e $file);
       
   192 	}
       
   193 
       
   194 sub checkMissing
       
   195 	{
       
   196 	my $file = shift;
       
   197 	print "Checking file missing: $file\n" if $verbose;
       
   198 	ok(!-e $file);
       
   199 	}
       
   200 
       
   201 # ***
       
   202 # Runs test code
       
   203 #
       
   204 sub doTest
       
   205 	{
       
   206 	my $test = shift;
       
   207 	warn "Can't find test exe: $test" if (!-e $test);
       
   208 
       
   209 	my $pass;
       
   210 	if (-e $test)
       
   211 		{
       
   212 		print "Running test: $test\n" if $verbose;
       
   213 		open TEST, "$test|" or die "Failed to start test $test: $!";
       
   214 		while(<TEST>)
       
   215 			{
       
   216 			$pass = 1 if /^RTEST: SUCCESS/ or /TEST Successfully Completed/;
       
   217 			}
       
   218 		close TEST;
       
   219 		}
       
   220 	ok($pass);	
       
   221 	}
       
   222 
       
   223 # ***
       
   224 # Cleans the test code
       
   225 # *
       
   226 sub doClean
       
   227 	{
       
   228 	my $sbs_ver = shift;
       
   229 	my $variant = shift;
       
   230 
       
   231 	my $redir = $verbose?'':' >nul 2>&1';
       
   232 	print "Cleaning component for $variant\n" if $verbose;
       
   233 	if ($sbs_ver == 1)
       
   234 		{
       
   235 		# Use the old build system
       
   236 		system("bldmake bldfiles$redir");
       
   237 		system("abld test makefile tools2$redir");
       
   238 		system("abld test clean tools2 $variant$redir");
       
   239 		}
       
   240 	else
       
   241 		{
       
   242 		# Use the new build system
       
   243 		system("sbs -c tools2_$variant.test CLEAN$redir");
       
   244 		}
       
   245 	}
       
   246 
       
   247 # ***
       
   248 # Builds the test code
       
   249 # *
       
   250 sub doBuild
       
   251 	{
       
   252 	my $variant = shift;
       
   253 
       
   254 	# First of all see if SBSv2 is installed
       
   255 	my $sbs_ver = 1;
       
   256 	open SBS, 'sbs -v 2>&1|' or die "Failed to execute command: $!";
       
   257 	while(<SBS>)
       
   258 		{
       
   259 		if (/^sbs version/)
       
   260 			{
       
   261 			$sbs_ver = 2;
       
   262 			last;
       
   263 			}
       
   264 		}
       
   265 	close SBS;
       
   266 	die "This test requires SBSv2. Run with -ignore to run this test anyway" if $sbs_ver == 1 && !$ignore;
       
   267 
       
   268 	# Override the result using environment variable
       
   269 	$sbs_ver = 1 if $ENV{SBS_VERSION} && $ENV{SBS_VERSION} == 1;
       
   270 
       
   271 	# Now build the test code - assumes current working directory is correct!
       
   272 	my $redir = $verbose?'':' >nul 2>&1';
       
   273 	print "Building test code using SBSv$sbs_ver for $variant\n" if $verbose;
       
   274 	if ($sbs_ver == 1)
       
   275 		{
       
   276 		print "Building using sbsv1\n" if $verbose;
       
   277 
       
   278 		# Use the old build system
       
   279 		system("bldmake bldfiles$redir");
       
   280 		system("abld test makefile tools2$redir");
       
   281 		system("abld test clean tools2$redir");
       
   282 		system("abld test library tools2$redir");
       
   283 		system("abld test target tools2 $variant$redir");
       
   284 		}
       
   285 	else
       
   286 		{
       
   287 		print "Building using sbsv2\n" if $verbose;
       
   288 
       
   289 		# TEM can't handle parallel builds due to dependencies between extension makefiles
       
   290 		my $flm = catfile($ENV{SBS_HOME}, 'lib', 'flm', 'x86tool.xml');
       
   291 		my $jopt = (!-e $flm) ? '-j 1' : '';
       
   292 
       
   293 		# Use the new build system
       
   294 		system("sbs $jopt -c tools2_$variant.test CLEAN$redir");
       
   295 		system("sbs $jopt -c tools2_$variant.test$redir");
       
   296 		}
       
   297 
       
   298 	# Return the sbs version for later
       
   299 	return $sbs_ver;
       
   300 	}
       
   301 
       
   302 =head1 NAME
       
   303 
       
   304 test.pl - A script for running tests
       
   305 
       
   306 =head1 SYNOPSIS
       
   307 
       
   308 test.pl [-help] [-version] [-verbose] [-ignore]
       
   309 
       
   310  Options:
       
   311    -help      brief help message
       
   312    -version   version of the script
       
   313    -verbose   print what the scripts does
       
   314    -ignore    ignore lack of SBSv2 and run tests anyway
       
   315 =cut