Add instructions for running code coverage with locally built mscorlib
authorHugh Bellamy <hughbellars@gmail.com>
Tue, 17 May 2016 19:40:43 +0000 (20:40 +0100)
committerHugh Bellamy <hughbellars@gmail.com>
Tue, 28 Jun 2016 16:31:34 +0000 (17:31 +0100)
Fixes dotnet/corefx#8381

Commit migrated from https://github.com/dotnet/corefx/commit/097f48becf8b4c645ede2c65ff2b8face98a4ee5

docs/libraries/building/code-coverage.md
docs/libraries/building/facade-code-coverage.bat [new file with mode: 0644]

index 4d94672..34dc06b 100644 (file)
@@ -60,3 +60,22 @@ The results for this one library will then also show up in the aforementioned in
 And then once the run completes:
     
     ..\..\..\bin\tests\coverage\index.htm
+
+## Code coverage with mscorlib code
+
+Some of the libraries for which contracts and tests live in the corefx repo are actually implemented in the core runtime library in another repo, e.g. the implementation that backs the System.Runtime contract is in System.Private.Corlib.dll in either the coreclr or corert repo. To run coverage reports for these projects, you need to build mscorlib locally from the coreclr repo.
+
+The following steps can be used manually to produce a coverage report, but a customizable batch file can be found [here](facade-code-coverage.bat). Changing the parameters in the first couple of lines lets you run a coverage report easily for any facade project.
+
+1. Build the local test project (`msbuild /T:Build`)
+3. Build coreclr locally in Debug or Release (`build.cmd all Debug skiptests`)
+2. Navigate to the built test directory in the corefx bin (e.g. `bin/tests/AnyOS.AnyCPU.Debug/System.Runtime/netcoreapp1.0` for `System.Runtime`
+4. Delete `coreclr.dll`, `mscorlib.dll` and `mscorlib.ni.dll` from that directory
+5. Copy all files in the coreclr bin directory to the test directory
+6. Run an OpenCover command with `xunit.console.netcore.exe`. For example:
+
+       <corefx-root>/packages/OpenCover/<opencover-version>/tools/OpenCover.Console.exe -filter:"+[*]* -[*.Tests]* -[xunit.*]*" -excludebyfile:"*\Common\src\System\SR.*" -nodefaultfilters -excludebyattribute:*.ExcludeFromCodeCoverage* -skipautoprops -hideskipped:All -threshold:1 -returntargetcode -register:user -targetdir:<path-to corefx-bin> -target:CoreRun.exe -output:coverage.xml -targetargs:"xunit.console.netcore.exe System.Runtime.Tests -xml testResults.xml -notrait Benchmark=true -notrait category=OuterLoop -notrait category=failing -notrait category=nonwindowstests"
+
+7. Run a ReportGenerator command with the generated `coverage.xml` file. For example:
+
+       <corefx-root>/packages/ReportGenerator/<opencover-version>/tools/ReportGenerator.exe -reporttypes:Html;Badges -reports:coverage.xml
diff --git a/docs/libraries/building/facade-code-coverage.bat b/docs/libraries/building/facade-code-coverage.bat
new file mode 100644 (file)
index 0000000..465a338
--- /dev/null
@@ -0,0 +1,67 @@
+@echo off
+:: Example settings for System.Runtime
+SET project=System.Runtime
+SET msbuildargs=/T:Build
+SET testsubdir=AnyOS.AnyCPU.Debug
+SET filter="+[*]* -[*.Tests]* -[*]System.Collections.* -[*]System.Diagnostics.* -[*]System.Globalization.* -[*]System.IO.* -[*]System.Reflection.* -[*]System.Resources.* -[*]System.Runtime.* -[*]System.Security.* -[*]System.StubHelpers.* -[*]System.Threading.* -[*]Microsoft.* -[*]Windows.* -[*]System.App* -[*]System.Text.Decoder* -[*]System.Text.Encoder* -[*]System.Text.*Encoding -[*]System.Text.Internal* -[xunit.*]*"
+
+:: Update this when OpenCover or ReportGenerator are updated
+SET opencoverversion=4.6.519
+SET reportgeneratorversion=2.4.3
+
+:: Assumes that the corefx and coreclr repo folders are in the same parent folder
+SET root=C:\Users\Hugh\Documents\Github
+
+SET corefx=%root%\corefx
+SET coreclr=%root%\coreclr
+
+SET packages=%corefx%\packages
+SET opencover=%packages%\OpenCover\%opencoverversion%\tools\OpenCover.Console.exe
+SET reportgenerator=%packages%\ReportGenerator\%reportgeneratorversion%\tools\ReportGenerator.exe
+
+SET targetdir=%corefx%\bin\tests\%testsubdir%\%project%.Tests\netcoreapp1.0
+
+SET resultsfile=testresults.xml
+SET coveragefile=coverage.xml
+
+SET coveragedir=coverage
+
+SET originalfolder=%cd%
+SET sourcefolder=%corefx%\src\%project%\tests
+
+SET coreclrbuild=%coreclr%\bin\Product\Windows_NT.x64.Debug
+
+:: Build the library
+cd %sourcefolder%
+msbuild %msbuildargs%
+cd %originalfolder%
+
+:: Delete old files (see #8381 for why)
+del %targetdir%\coreclr.dll
+del %targetdir%\mscorlib.dll
+del %targetdir%\mscorlib.ni.dll
+
+:: Copy over our local build files
+For %%a in (
+%coreclrbuild%\mscorlib.dll
+%coreclrbuild%\PDB\mscorlib.pdb
+%coreclrbuild%\coreclr.dll
+%coreclrbuild%\PDB\coreclr.pdb
+%coreclrbuild%\CoreRun.exe
+%coreclrbuild%\CoreConsole.exe
+%coreclrbuild%\clretwrc.dll
+%coreclrbuild%\clrjit.dll
+%coreclrbuild%\dbgshim.dll
+%coreclrbuild%\mscordaccore.dll
+%coreclrbuild%\mscordbi.dll
+%coreclrbuild%\mscorrc.debug.dll
+%coreclrbuild%\mscorrc.dll
+%coreclrbuild%\sos.dll
+) do copy /b/v/y "%%~a" "%targetdir%\"
+
+:: Now, run the actual tests and generate a coverage report
+SET corerunargs=xunit.console.netcore.exe %project%.Tests.dll -xml %resultsfile% -notrait category=OuterLoop -notrait category=failing -notrait category=nonwindowstests
+
+%opencover% -filter:%filter% -excludebyfile:"*\Common\src\System\SR.*" -nodefaultfilters -excludebyattribute:*.ExcludeFromCodeCoverage* -skipautoprops -hideskipped:All -threshold:1 -returntargetcode -register:user -targetdir:%targetdir% -target:CoreRun.exe -output:%coveragefile% -targetargs:"%corerunargs%"
+
+%reportgenerator% -targetdir:%coveragedir% -reporttypes:Html;Badges -reports:%coveragefile% -verbosity:Error
\ No newline at end of file