From 6c20c44e7c2b3982d42277f067e129df66b4b23a Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 12 Dec 2015 22:48:56 +0000 Subject: Add wrapper for running tests easily on MSVC/CMake --- runtest.pl.in | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 84 insertions(+), 5 deletions(-) (limited to 'runtest.pl.in') diff --git a/runtest.pl.in b/runtest.pl.in index f01f2936..7d197d4c 100755 --- a/runtest.pl.in +++ b/runtest.pl.in @@ -3,7 +3,10 @@ use strict; use warnings; -use lib 'infrastructure'; +use File::Basename; +chdir(dirname($0)); +use lib dirname($0).'/infrastructure'; + use BoxPlatform; my ($test_name,$test_mode) = @ARGV; @@ -97,9 +100,65 @@ sub runtest { my ($t) = @_; - # attempt to make this test + # Attempt to make this test. my $flag = ($test_mode eq 'release')?(BoxPlatform::make_flag('RELEASE')):''; - my $make_res = system("cd test/$t && $make_command $flag"); + my ($make_res, $test_project_exe); + + if($target_msvc) + { + $test_project_exe = "test_$t"; + # Assume that MSVC projects are built with CMake, so we can use + # MSBuild to run the tests. + my $test_src_dir = "test\\$t"; + my $test_dst_dir = "$test_mode\\test\\$t"; + + my @commands = ( + "msbuild /nologo /consoleloggerparameters:ErrorsOnly ". + "infrastructure\\cmake\\$test_project_exe.vcxproj", + "xcopy /s /i /y /q $test_src_dir $test_dst_dir", + "copy infrastructure\\cmake\\$test_mode\\$test_project_exe.exe $test_dst_dir" + ); + + if(-d $test_dst_dir) + { + unshift @commands, "rmdir /s /q $test_dst_dir"; + } + + foreach my $command (@commands) + { + $make_res = system($command); + if ($make_res != 0) + { + push @results, "$t: make failed: $command"; + last; + } + } + + # Windows doesn't support testextra files either, so fake it. + if ($make_res == 0 and -r "$test_src_dir/testextra") + { + open EXTRA, "$test_src_dir/testextra" + or die "$test_src_dir/testextra: $!"; + foreach my $line () + { + if ($line =~ m/^mkdir (.*)/) + { + mkdir("$test_dst_dir/$1") + or die "$test_dst_dir/$1: $!"; + } + else + { + die "Unsupported command in ". + "$test_src_dir/testextra: $!"; + } + } + } + } + else + { + $make_res = system("cd test/$t && $make_command $flag"); + } + if($make_res != 0) { push @results,"$t: make failed"; @@ -108,10 +167,30 @@ sub runtest } my $logfile = "test-$t.log"; + my $test_res; # run it - my $test_res = system("cd $test_mode/test/$t ; ./t 2>&1 " . - "| tee ../../../$logfile"); + if($target_msvc) + { + # no tee.exe, so let's do it ourselves. + open LOG, ">$logfile" or die "$logfile: $!"; + chdir("$test_mode/test/$t"); + open TEE, "$test_project_exe.exe |" + or die "$test_project_exe.exe: $!"; + while (my $line = ) + { + print $line; + print LOG $line; + } + close LOG; + close TEE; + chdir("../../.."); + } + else + { + $test_res = system("cd $test_mode/test/$t ; ./t 2>&1 " . + "| tee ../../../$logfile"); + } # open test results if(open RESULTS, $logfile) -- cgit v1.2.3