From 420ba4f8ef35db46b6ca1a7b12ef81f1ec160218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Tue, 25 Feb 2020 21:46:15 +0100 Subject: [PATCH] added coverage measurement --- .gitignore | 3 ++ .../DeserializationTests.cs | 1 + .../DynamicSerializerStateTests.cs | 1 + Capnp.Net.Runtime.Tests/FramePumpTests.cs | 1 + Capnp.Net.Runtime.Tests/Interception.cs | 1 + .../MessageBuilderTests.cs | 1 + Capnp.Net.Runtime.Tests/RpcSchemaTests.cs | 1 + .../SegmentAllocatorTests.cs | 1 + Capnp.Net.Runtime.Tests/TcpRpc.cs | 1 + .../TcpRpcAdvancedStuff.cs | 1 + Capnp.Net.Runtime.Tests/TcpRpcPorted.cs | 1 + Capnp.Net.Runtime.Tests/WirePointerTests.cs | 1 + appveyor.yml | 13 +++++ scripts/choco-install-coverage-tools.ps1 | 4 ++ scripts/measure-coverage.ps1 | 48 +++++++++++++++++++ scripts/vsdevcmdprompt-measure-coverage.bat | 4 ++ 16 files changed, 83 insertions(+) create mode 100644 scripts/choco-install-coverage-tools.ps1 create mode 100644 scripts/measure-coverage.ps1 create mode 100644 scripts/vsdevcmdprompt-measure-coverage.bat diff --git a/.gitignore b/.gitignore index 64fa334..752be25 100644 --- a/.gitignore +++ b/.gitignore @@ -336,3 +336,6 @@ ASALocalRun/ # Capnp code behind *.capnp.cs /globalPackages + +# Coverage results folder +coverage/ diff --git a/Capnp.Net.Runtime.Tests/DeserializationTests.cs b/Capnp.Net.Runtime.Tests/DeserializationTests.cs index 882d4d7..647799b 100644 --- a/Capnp.Net.Runtime.Tests/DeserializationTests.cs +++ b/Capnp.Net.Runtime.Tests/DeserializationTests.cs @@ -3,6 +3,7 @@ namespace Capnp.Net.Runtime.Tests { [TestClass] + [TestCategory("Coverage")] public class DeserializationTests { [TestMethod] diff --git a/Capnp.Net.Runtime.Tests/DynamicSerializerStateTests.cs b/Capnp.Net.Runtime.Tests/DynamicSerializerStateTests.cs index 0797860..a65c71f 100644 --- a/Capnp.Net.Runtime.Tests/DynamicSerializerStateTests.cs +++ b/Capnp.Net.Runtime.Tests/DynamicSerializerStateTests.cs @@ -7,6 +7,7 @@ using System.IO; namespace Capnp.Net.Runtime.Tests { [TestClass] + [TestCategory("Coverage")] public class DynamicSerializerStateTests { [TestMethod] diff --git a/Capnp.Net.Runtime.Tests/FramePumpTests.cs b/Capnp.Net.Runtime.Tests/FramePumpTests.cs index 2ebef32..8c964a6 100644 --- a/Capnp.Net.Runtime.Tests/FramePumpTests.cs +++ b/Capnp.Net.Runtime.Tests/FramePumpTests.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; namespace Capnp.Net.Runtime.Tests { [TestClass] + [TestCategory("Coverage")] public class FramePumpTests { class MyStruct : SerializerState diff --git a/Capnp.Net.Runtime.Tests/Interception.cs b/Capnp.Net.Runtime.Tests/Interception.cs index ea7c1f5..ac0ea63 100644 --- a/Capnp.Net.Runtime.Tests/Interception.cs +++ b/Capnp.Net.Runtime.Tests/Interception.cs @@ -14,6 +14,7 @@ using System.Threading.Tasks.Dataflow; namespace Capnp.Net.Runtime.Tests { [TestClass] + [TestCategory("Coverage")] public class Interception: TestBase { class MyPolicy : IInterceptionPolicy diff --git a/Capnp.Net.Runtime.Tests/MessageBuilderTests.cs b/Capnp.Net.Runtime.Tests/MessageBuilderTests.cs index 32196a6..5b3d6b1 100644 --- a/Capnp.Net.Runtime.Tests/MessageBuilderTests.cs +++ b/Capnp.Net.Runtime.Tests/MessageBuilderTests.cs @@ -3,6 +3,7 @@ namespace Capnp.Net.Runtime.Tests { [TestClass] + [TestCategory("Coverage")] public class MessageBuilderTests { class Struct2D0P : SerializerState diff --git a/Capnp.Net.Runtime.Tests/RpcSchemaTests.cs b/Capnp.Net.Runtime.Tests/RpcSchemaTests.cs index 8032cc3..f8841ec 100644 --- a/Capnp.Net.Runtime.Tests/RpcSchemaTests.cs +++ b/Capnp.Net.Runtime.Tests/RpcSchemaTests.cs @@ -4,6 +4,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Capnp.Net.Runtime.Tests { [TestClass] + [TestCategory("Coverage")] public class RpcSchemaTests { [TestMethod] diff --git a/Capnp.Net.Runtime.Tests/SegmentAllocatorTests.cs b/Capnp.Net.Runtime.Tests/SegmentAllocatorTests.cs index 7506f08..7ff67b5 100644 --- a/Capnp.Net.Runtime.Tests/SegmentAllocatorTests.cs +++ b/Capnp.Net.Runtime.Tests/SegmentAllocatorTests.cs @@ -3,6 +3,7 @@ namespace Capnp.Net.Runtime.Tests { [TestClass] + [TestCategory("Coverage")] public class SegmentAllocatorTests { [TestMethod] diff --git a/Capnp.Net.Runtime.Tests/TcpRpc.cs b/Capnp.Net.Runtime.Tests/TcpRpc.cs index b5482e4..56d8229 100644 --- a/Capnp.Net.Runtime.Tests/TcpRpc.cs +++ b/Capnp.Net.Runtime.Tests/TcpRpc.cs @@ -12,6 +12,7 @@ namespace Capnp.Net.Runtime.Tests { [TestClass] + [TestCategory("Coverage")] public class TcpRpc { public static int TcpPort = 49153; diff --git a/Capnp.Net.Runtime.Tests/TcpRpcAdvancedStuff.cs b/Capnp.Net.Runtime.Tests/TcpRpcAdvancedStuff.cs index b708d77..e029d0a 100644 --- a/Capnp.Net.Runtime.Tests/TcpRpcAdvancedStuff.cs +++ b/Capnp.Net.Runtime.Tests/TcpRpcAdvancedStuff.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; namespace Capnp.Net.Runtime.Tests { [TestClass] + [TestCategory("Coverage")] public class TcpRpcAdvancedStuff : TestBase { [TestMethod, Timeout(10000)] diff --git a/Capnp.Net.Runtime.Tests/TcpRpcPorted.cs b/Capnp.Net.Runtime.Tests/TcpRpcPorted.cs index db6a450..5bf3b17 100644 --- a/Capnp.Net.Runtime.Tests/TcpRpcPorted.cs +++ b/Capnp.Net.Runtime.Tests/TcpRpcPorted.cs @@ -13,6 +13,7 @@ using Microsoft.Extensions.Logging; namespace Capnp.Net.Runtime.Tests { [TestClass] + [TestCategory("Coverage")] public class TcpRpcPorted: TestBase { [TestMethod] diff --git a/Capnp.Net.Runtime.Tests/WirePointerTests.cs b/Capnp.Net.Runtime.Tests/WirePointerTests.cs index ba7cd91..18ec167 100644 --- a/Capnp.Net.Runtime.Tests/WirePointerTests.cs +++ b/Capnp.Net.Runtime.Tests/WirePointerTests.cs @@ -4,6 +4,7 @@ using System; namespace Capnp.Net.Runtime.Tests { [TestClass] + [TestCategory("Coverage")] public class WirePointerTests { [TestMethod] diff --git a/appveyor.yml b/appveyor.yml index b8c4883..da2ecb5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -11,9 +11,15 @@ install: - vcpkg install capnproto - cd %APPVEYOR_BUILD_FOLDER% - dotnet tool install -g nbgv + - choco install opencover --version=4.7.922 --force -y + - choco install reportgenerator.portable --version=2.5.0.0 --force -y + - dotnet tool install -g coveralls.net --version 1.0.0 init: # Good practise, because Windows line endings are different from Unix/Linux ones - cmd: git config --global core.autocrlf true +environment: + COVERALLS_REPO_TOKEN: + secure: mwxwOymoS7vB56iQN5Obbt8+oMqbRpK8Ei2GZUI7Mm46C8asDR/Wu0RAXYlhp85Q before_build: - cmd: nbgv cloud - cmd: dotnet --version @@ -51,6 +57,9 @@ artifacts: - path: capnpc-csharp\nupkg\*.nupkg name: capnpc-csharp type: NuGetPackage + - path: coverage\report\* + name: Coverage report + type: zip test_script: - cmd: | nbgv get-version -v NuGetPackageVersion >> version.txt @@ -80,6 +89,10 @@ test_script: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Release\net471\Capnp.Net.Runtime.Tests.Std20.dll vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests.Core21\bin\Debug\netcoreapp2.1\Capnp.Net.Runtime.Tests.Core21.dll vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests.Core21\bin\Release\netcoreapp2.1\Capnp.Net.Runtime.Tests.Core21.dll + - ps: | + .\scipts\measure-coverage.ps1 + $coveralls = ".\tools\csmacnz.coveralls.exe" + & $coveralls --reportgenerator -i coverage/report --repoToken $env:COVERALLS_REPO_TOKEN --commitId $env:APPVEYOR_REPO_COMMIT --commitBranch $env:APPVEYOR_REPO_BRANCH --commitAuthor $env:APPVEYOR_REPO_COMMIT_AUTHOR --commitEmail $env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL --commitMessage $env:APPVEYOR_REPO_COMMIT_MESSAGE --jobId $env:APPVEYOR_JOB_ID on_finish : # any cleanup in here deploy: diff --git a/scripts/choco-install-coverage-tools.ps1 b/scripts/choco-install-coverage-tools.ps1 new file mode 100644 index 0000000..82e6e98 --- /dev/null +++ b/scripts/choco-install-coverage-tools.ps1 @@ -0,0 +1,4 @@ +if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit } + +choco install opencover --version=4.7.922 +choco install reportgenerator.portable --version=2.5.0.0 diff --git a/scripts/measure-coverage.ps1 b/scripts/measure-coverage.ps1 new file mode 100644 index 0000000..8b9f809 --- /dev/null +++ b/scripts/measure-coverage.ps1 @@ -0,0 +1,48 @@ +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$rootDir = "$scriptDir\.." +$coverageDir = "$rootDir\coverage" +$coverageReportDir = "$rootDir\coverage\report" +$openCover = "$env:LOCALAPPDATA\Apps\OpenCover\OpenCover.Console.exe" +$vsTestConsole = where.exe vstest.console + +$runtimeTestsDnc21 = "$rootDir\Capnp.Net.Runtime.Tests.Core21\bin\Release\netcoreapp2.1\Capnp.Net.Runtime.Tests.Core21.dll" +$coverageOutputRuntimeDnc21 = "$coverageDir\cov-Capnp.Net.Runtime-dnc21.xml" + +$runtimeTestsNet471 = "$rootDir\Capnp.Net.Runtime.Tests\bin\Release\net471\Capnp.Net.Runtime.Tests.Std20.dll" +$coverageOutputRuntimeNet471 = "$coverageDir\cov-Capnp.Net.Runtime-net471.xml" + +$generatorTests = "$rootDir\CapnpC.CSharp.Generator.Tests\bin\Release\netcoreapp3.0\CapnpC.CSharp.Generator.Tests.dll" +$coverageOutputGenerator = "$coverageDir\cov-CapnpC.CSharp.Generator.xml" + +If(!(test-path $coverageDir)) +{ + New-Item -ItemType Directory -Force -Path $coverageDir +} + +If(!(test-path $coverageReportDir)) +{ + New-Item -ItemType Directory -Force -Path $coverageReportDir +} + +& $openCover -target:"$vsTestConsole" ` + -targetArgs:"/inIsolation $runtimeTestsDnc21 /TestCaseFilter:`"TestCategory=Coverage`"" ` + -filter:"+[Capnp.Net.Runtime]Capnp.*" ` + -excludebyattribute:"System.CodeDom.Compiler.GeneratedCodeAttribute" ` + -output:"$coverageOutputRuntimeDnc21" ` + -mergebyhash -register:user -oldStyle + +& $openCover -target:"$vsTestConsole" ` + -targetArgs:"/inIsolation $runtimeTestsNet471 /TestCaseFilter:`"TestCategory=Coverage`"" ` + -filter:"+[Capnp.Net.Runtime]Capnp.*" ` + -excludebyattribute:"System.CodeDom.Compiler.GeneratedCodeAttribute" ` + -output:"$coverageOutputRuntimeNet471" ` + -mergebyhash -register:user -oldStyle + +& $openCover -target:"$vsTestConsole" ` + -targetArgs:"/inIsolation $generatorTests" ` + -filter:"+[CapnpC.CSharp.Generator]*" ` + -excludebyattribute:"System.CodeDom.Compiler.GeneratedCodeAttribute" ` + -output:"$coverageOutputGenerator" ` + -mergebyhash -register:user -oldStyle + +ReportGenerator.exe -reports:"$coverageOutputRuntimeDnc21;$coverageOutputRuntimeNet471;$coverageOutputGenerator" -targetdir:"$coverageReportDir" -reportTypes:"Html;Xml" diff --git a/scripts/vsdevcmdprompt-measure-coverage.bat b/scripts/vsdevcmdprompt-measure-coverage.bat new file mode 100644 index 0000000..be2bf74 --- /dev/null +++ b/scripts/vsdevcmdprompt-measure-coverage.bat @@ -0,0 +1,4 @@ +rem This batch file assumes to be run from a Visual Studio developer command prompt +rem This is necessary because we need to locate vstest.console.exe + +powershell -File measure-coverage.ps1