Skip to content
Snippets Groups Projects
Commit 05e9e270 authored by Nicolas Noble's avatar Nicolas Noble
Browse files

Merge pull request #3987 from jtattermusch/csharp_opencover

Add OpenCover coverage for C#
parents 1bf6f68a a09edad0
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ Grpc.v12.suo
Grpc.sdf
TestResult.xml
coverage_results.xml
/TestResults
.vs/
*.nupkg
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit.Runners" version="2.6.4" />
<package id="OpenCover" version="4.6.166" />
<package id="ReportGenerator" version="2.3.2.0" />
</packages>
\ No newline at end of file
......@@ -30,7 +30,7 @@
set -ex
if [ "$CONFIG" = "dbg" ]
if [ "$CONFIG" = "dbg" ] || [ "$CONFIG" = "gcov" ]
then
MSBUILD_CONFIG="Debug"
else
......
......@@ -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
......
......@@ -34,7 +34,7 @@ CONFIG=${CONFIG:-opt}
NUNIT_CONSOLE="mono packages/NUnit.Runners.2.6.4/tools/nunit-console.exe"
if [ "$CONFIG" = "dbg" ]
if [ "$CONFIG" = "dbg" ] || [ "$CONFIG" = "gcov" ]
then
MSBUILD_CONFIG="Debug"
else
......@@ -45,10 +45,24 @@ fi
cd $(dirname $0)/../..
root=`pwd`
cd src/csharp
export LD_LIBRARY_PATH=$root/libs/$CONFIG
$NUNIT_CONSOLE -labels "$1/bin/$MSBUILD_CONFIG/$1.dll"
if [ "$CONFIG" = "gcov" ]
then
(cd src/csharp; $NUNIT_CONSOLE -labels \
"Grpc.Core.Tests/bin/$MSBUILD_CONFIG/Grpc.Core.Tests.dll" \
"Grpc.Examples.Tests/bin/$MSBUILD_CONFIG/Grpc.Examples.Tests.dll" \
"Grpc.HealthCheck.Tests/bin/$MSBUILD_CONFIG/Grpc.HealthCheck.Tests.dll" \
"Grpc.IntegrationTesting/bin/$MSBUILD_CONFIG/Grpc.IntegrationTesting.dll")
gcov objs/gcov/src/csharp/ext/*.o
lcov --base-directory . --directory . -c -o coverage.info
lcov -e coverage.info '**/src/csharp/ext/*' -o coverage.info
genhtml -o reports/csharp_ext_coverage --num-spaces 2 \
-t 'gRPC C# native extension test coverage' coverage.info \
--rc genhtml_hi_limit=95 --rc genhtml_med_limit=80 --no-prefix
else
(cd src/csharp; $NUNIT_CONSOLE -labels "$1/bin/$MSBUILD_CONFIG/$1.dll")
fi
......@@ -342,10 +342,18 @@ 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 config.build_config == 'gcov':
# On Windows, we only collect C# code coverage.
# On Linux, we only collect coverage for native extension.
# For code coverage all tests need to run as one suite.
return [config.job_spec([cmd], None,
environ=_FORCE_ENVIRON_FOR_WRAPPERS)]
else:
return [config.job_spec([cmd, assembly],
None, shortname=assembly,
environ=_FORCE_ENVIRON_FOR_WRAPPERS)
for assembly in assemblies]
def pre_build_steps(self):
if self.platform == 'windows':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment