From bf3b153fdf2435a8ed6a63fda4d9f8642c81741d Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 26 Oct 2015 10:24:42 -0700 Subject: [PATCH] Add OpenCover coverage for C# --- src/csharp/.gitignore | 1 + src/csharp/.nuget/packages.config | 2 ++ tools/run_tests/run_csharp.bat | 18 ++++++++++++++---- tools/run_tests/run_tests.py | 14 ++++++++++---- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/csharp/.gitignore b/src/csharp/.gitignore index deac55029ee..0f96a482219 100644 --- a/src/csharp/.gitignore +++ b/src/csharp/.gitignore @@ -7,6 +7,7 @@ Grpc.v12.suo Grpc.sdf TestResult.xml +coverage_results.xml /TestResults .vs/ *.nupkg diff --git a/src/csharp/.nuget/packages.config b/src/csharp/.nuget/packages.config index a7df95cf6bd..89a310ac569 100644 --- a/src/csharp/.nuget/packages.config +++ b/src/csharp/.nuget/packages.config @@ -1,4 +1,6 @@  + + \ No newline at end of file diff --git a/tools/run_tests/run_csharp.bat b/tools/run_tests/run_csharp.bat index 310cfe0d2fe..0e33e5295a4 100644 --- a/tools/run_tests/run_csharp.bat +++ b/tools/run_tests/run_csharp.bat @@ -2,13 +2,23 @@ setlocal -@rem enter this directory +@rem enter src/csharp directory cd /d %~dp0\..\..\src\csharp -@rem set UUID variable to a random GUID, we will use it to put TestResults.xml to a dedicated directory, so that parallel test runs don't collide -for /F %%i in ('powershell -Command "[guid]::NewGuid().ToString()"') do (set UUID=%%i) +if not "%CONFIG%" == "gcov" ( + @rem Run tests for assembly passed as 1st arg. -packages\NUnit.Runners.2.6.4\tools\nunit-console-x86.exe /domain:None -labels "%1/bin/Debug/%1.dll" -work test-results/%UUID% || goto :error + @rem set UUID variable to a random GUID, we will use it to put TestResults.xml to a dedicated directory, so that parallel test runs don't collide + for /F %%i in ('powershell -Command "[guid]::NewGuid().ToString()"') do (set UUID=%%i) + + packages\NUnit.Runners.2.6.4\tools\nunit-console-x86.exe /domain:None -labels "%1/bin/Debug/%1.dll" -work test-results/%UUID% || goto :error +) else ( + @rem Run all tests with code coverage + + packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -target:"packages\NUnit.Runners.2.6.4\tools\nunit-console-x86.exe" -targetdir:"." -targetargs:"/domain:None -labels Grpc.Core.Tests/bin/Debug/Grpc.Core.Tests.dll Grpc.IntegrationTesting/bin/Debug/Grpc.IntegrationTesting.dll Grpc.Examples.Tests/bin/Debug/Grpc.Examples.Tests.dll Grpc.HealthCheck.Tests/bin/Debug/Grpc.HealthCheck.Tests.dll" -filter:"+[Grpc.Core]*" -register:user -output:coverage_results.xml || goto :error + + packages\ReportGenerator.2.3.2.0\tools\ReportGenerator.exe -reports:"coverage_results.xml" -targetdir:"..\..\reports\csharp_coverage" -reporttypes:"Html;TextSummary" || goto :error +) endlocal diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 3859958a952..b1f886f319c 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -342,10 +342,16 @@ class CSharpLanguage(object): cmd = 'tools\\run_tests\\run_csharp.bat' else: cmd = 'tools/run_tests/run_csharp.sh' - return [config.job_spec([cmd, assembly], - None, shortname=assembly, - environ=_FORCE_ENVIRON_FOR_WRAPPERS) - for assembly in assemblies] + + if not config.build_config == 'gcov': + return [config.job_spec([cmd, assembly], + None, shortname=assembly, + environ=_FORCE_ENVIRON_FOR_WRAPPERS) + for assembly in assemblies] + else: + # For code coverage we need to run all tests in one suite. + return [config.job_spec([cmd], None, + environ=_FORCE_ENVIRON_FOR_WRAPPERS)] def pre_build_steps(self): if self.platform == 'windows':