You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Code coverage for System.Private.CoreLib is broken in CI #23345
It appears we're no longer able to get code coverage of System.Private.CoreLib, even when using CoreCLROverridePath, even when using set COMPlus_ZapDisable=1.
It looks like an issue with PDBs. I was able to work around this by doing build windowsmscorlib release after doing my full coreclr build; presumably something about the crossgen step done in the regular coreclr build is messing with the PDBs in a way that prevents OpenCover from successfully using the PDB, and build windowsmscorlib release skips crossgen.
Unfortunately, while this allows OpenCover to successfully run and index the data from System.Private.CoreLib, I then hit a StackOverflowException in ReportGenerator consuming it 😦
Overwrite the NRefactory binaries in the local directory containing the unzipped ReportGenerator binaries (e.g. corefx\packages\reportgenerator\2.5.0\tools) with those built from the NRefactory repo
Before running tests with /p:Coverage=true, set COMPlus_ZapDisable=1
I see ReportGenerator distributes NRefactory within its package -- so we don't need NRefactory to update their package necessarily, we just need ReportGenerator to include an updated one. I see ReportGenerator 3.0 has just come out, but it has the identical NRefactory that 2.5 has. Worth opening an issue on the ReportGenerator repo to ask?
we just need ReportGenerator to include an updated one
ReportGenerator just references the NRefactory NuGet package, no? If it actually distributes the binary, then yeah, we should just ask ReportGenerator to include the latest from source.
I am trying to get coverage to work without building CoreCLR myself, instead using the corelib pdb that is now gotten automatically. Note this is a Windows style PDB not a portable PDB. I cannot get Cecil to load this System.Private.Corelib.pdb - debugging Cecil, it seems to think it does not match the dll, because the guid does not match; the guid it gets from the pdb seems right per Symchk, the guid it reads from the dll header is unexpected. Symchk and VS consider the pdb to be a match. My next guess is to try Cecil 0.10, but it is not a drop in replacement: it needs changes in opencover.
Since there is some discussion on top with some outdated/incorrect information it seems useful to record the history of the issues affecting coverage and for System.Private.CoreLib in particular:
a. At that time the Profiler API had a bug that prevented OpenCover from instrumenting any crossgen assembly. That's why Stephen's attempts here failed.
b. Once the Profiler API was fixed OpenCover behavior regarding symbols, prevented it from instrumenting the methods in S.P.C.dll. OpenCover (current sources and version 4.6.519) bails on any assembly if it finds a pdb with same name and it fails to load it, i.e.: on firt mismatch it doesn't look in extra search paths (not typical symbol search algo). In this case S.P.C.pdb was for the IL version, so it didn't match S.P.C.dll.
Around 10/2017 pdbs became portable by default and since version 4.6.519 of OpenCover doesn't support portable PDBs a workaround was put in place to generate respective WindowsPDB. However, the workaround just target AssemblyBeingTestedName not any additional assemblies, like S.P.C.dll (this is a simple fix on CodeCoverage.targets).
One related issue that tripped me in the beginning of my investigation was the fact that current master sources of OpenCover w/ latest Mono.Cecil (that supports portable PDBs) failed with an unchanged CoreFx repo due to a bug (already fixed) in Mono.Cecil that prevented it from working with WindowsPDBs.
In summary: at the present, to make CoreLib work with OpenCover we can use either the native or IL S.P.C.dll, but, the S.P.C.pdb first found by OpenCover must match the version being loaded.
In my aspiration to avoid replacing native image CoreLib dll (more stable and less risky for dev boxes). I didn't notice something very important: using native image and fixing the PDB (needed due to OpenCover issue) doesn't get source information on the report for CoreLib. Worst, the way that I changed CodeCoverage.targets requires hacks to get source information for CoreLib on dev boxes. I expected source information for CoreLib to be broken on CI at least for the moment, but the intention was to have it working easily on devbox with CoreClrOverridePath... back to fixing this...
I'm working on having a dedicated folder for coverage with only IL to get source/line report for CoreLib. In the short run when running against CoreClr from a package (e.g.: CI) report will generate some messages like:
File 'E:\A\_work\104\s\src\System.Private.CoreLib\src\System\Runtime\InteropServices\WindowsRuntime\IteratorToEnumeratorAdapter.cs' does not exist (any more).
Creating report 770/1105 (Assembly: System.Private.CoreLib, Class: System.Runtime.InteropServices.WindowsRuntime.IteratorToEnumeratorAdapter`1)
...
Creating report 1104/1105 (Assembly: System.Private.CoreLib, Class: System.WeakReference`1)
File 'E:\A\_work\104\s\src\System.Private.CoreLib\src\System\WeakReferenceOfT.cs' does not exist (any more).
File 'E:\A\_work\104\s\src\System.Private.CoreLib\src\System\WeakReferenceOfT.cs' does not exist (any more).
Creating report 1105/1105 (Assembly: System.Private.CoreLib, Class: Windows.Foundation.Diagnostics.TracingStatusChangedEventArgs)
but since it doesn't fail the build I'm treating those as acceptable for now (one can even properly map the sources and get source coverage info for corelib).
Right now CoreLib is back in CI but as mentioned above just the percentage numbers for Line and Branch coverage, that will be fixed via dotnet/buildtools#2077 that runs against the IL version of CoreLib.
Daily coverage run has numbers for CoreLib, however, due to crashes it doesn't appear as the last coverage run. Closing this issue and following up on crashes and others in separate issues:
Reopening as System.Private.CoreLib numbers are busted again. With my recent work I overlooked some details and we use the native System.Private.CoreLib.dll again. I'll try to solve this.
Activity
stephentoub commentedon Aug 27, 2017
It looks like an issue with PDBs. I was able to work around this by doing
build windowsmscorlib releaseafter doing my full coreclr build; presumably something about the crossgen step done in the regular coreclr build is messing with the PDBs in a way that prevents OpenCover from successfully using the PDB, andbuild windowsmscorlib releaseskips crossgen.Unfortunately, while this allows OpenCover to successfully run and index the data from System.Private.CoreLib, I then hit a StackOverflowException in ReportGenerator consuming it 😦

stephentoub commentedon Aug 27, 2017
I built https://github.com/icsharpcode/NRefactory/ from source, overwrote the binaries in my ReportGenerator package directory (corefx\packages\reportgenerator\2.5.0\tools), and the stack overflow went away. So I'm unblocked for now, but this is not a good state.
danmoseley commentedon Aug 30, 2017
Seems the latest release of NRefactory is 6.0.0 beta 1 (https://www.nuget.org/packages/ICSharpCode.NRefactory/6.0.0-beta1) ... if you see it work with binaries from that package, we could ask ReportGenerator folk to consider upgrading their dependency.
stephentoub commentedon Aug 30, 2017
I tried that before I tried compiling from source... failed miserably.
stephentoub commentedon Oct 4, 2017
Summarizing current workaround, to get code coverage for corelib, one needs to:
build windowsmscorlib release)danmoseley commentedon Oct 4, 2017
I see ReportGenerator distributes NRefactory within its package -- so we don't need NRefactory to update their package necessarily, we just need ReportGenerator to include an updated one. I see ReportGenerator 3.0 has just come out, but it has the identical NRefactory that 2.5 has. Worth opening an issue on the ReportGenerator repo to ask?
stephentoub commentedon Oct 4, 2017
ReportGenerator just references the NRefactory NuGet package, no? If it actually distributes the binary, then yeah, we should just ask ReportGenerator to include the latest from source.
danmoseley commentedon Oct 4, 2017
No, it distributes it.
stephentoub commentedon Oct 4, 2017
danielpalme/ReportGenerator#105
WriteEntires and eventInstance tests completed
danmoseley commentedon Oct 6, 2017
I think 3.0.1 needs to go in two places
https://github.com/dotnet/buildtools/blob/master/src/Microsoft.DotNet.Build.Tasks/PackageFiles/CodeCoverage.targets#L9
https://github.com/dotnet/corefx/blob/7f1c480a6a280fbced29606120b507596bafbefc/external/test-runtime/XUnit.Runtime.depproj#L64
danmoseley commentedon Oct 9, 2017
I am trying to get coverage to work without building CoreCLR myself, instead using the corelib pdb that is now gotten automatically. Note this is a Windows style PDB not a portable PDB. I cannot get Cecil to load this System.Private.Corelib.pdb - debugging Cecil, it seems to think it does not match the dll, because the guid does not match; the guid it gets from the pdb seems right per Symchk, the guid it reads from the dll header is unexpected. Symchk and VS consider the pdb to be a match. My next guess is to try Cecil 0.10, but it is not a drop in replacement: it needs changes in opencover.
danmoseley commentedon Oct 9, 2017
Howver, I can verify that report generator works fine.
danmoseley commentedon Oct 9, 2017
It would be interesting to try stepping over the guid check to see whether the corelib pdb works correctly.
stephentoub commentedon Oct 9, 2017
What source would that match to / use to generate the rendered code coverage report?
39 remaining items
pjanotti commentedon Jun 16, 2018
Since there is some discussion on top with some outdated/incorrect information it seems useful to record the history of the issues affecting coverage and for
System.Private.CoreLibin particular:When S.P.C.ni.dll was renamed to S.P.C.dll coverage was broken due to two issues:
a. At that time the Profiler API had a bug that prevented OpenCover from instrumenting any crossgen assembly. That's why Stephen's attempts here failed.
b. Once the Profiler API was fixed OpenCover behavior regarding symbols, prevented it from instrumenting the methods in S.P.C.dll. OpenCover (current sources and version 4.6.519) bails on any assembly if it finds a pdb with same name and it fails to load it, i.e.: on firt mismatch it doesn't look in extra search paths (not typical symbol search algo). In this case S.P.C.pdb was for the IL version, so it didn't match S.P.C.dll.
Around 10/2017 pdbs became portable by default and since version 4.6.519 of OpenCover doesn't support portable PDBs a workaround was put in place to generate respective WindowsPDB. However, the workaround just target
AssemblyBeingTestedNamenot any additional assemblies, like S.P.C.dll (this is a simple fix on CodeCoverage.targets).One related issue that tripped me in the beginning of my investigation was the fact that current master sources of OpenCover w/ latest Mono.Cecil (that supports portable PDBs) failed with an unchanged CoreFx repo due to a bug (already fixed) in Mono.Cecil that prevented it from working with WindowsPDBs.
In summary: at the present, to make CoreLib work with OpenCover we can use either the native or IL S.P.C.dll, but, the S.P.C.pdb first found by OpenCover must match the version being loaded.
stephentoub commentedon Jun 16, 2018
Great summary, thanks.
pjanotti commentedon Jun 21, 2018
In my aspiration to avoid replacing native image CoreLib dll (more stable and less risky for dev boxes). I didn't notice something very important: using native image and fixing the PDB (needed due to OpenCover issue) doesn't get source information on the report for CoreLib. Worst, the way that I changed
CodeCoverage.targetsrequires hacks to get source information for CoreLib on dev boxes. I expected source information for CoreLib to be broken on CI at least for the moment, but the intention was to have it working easily on devbox with CoreClrOverridePath... back to fixing this...pjanotti commentedon Jun 22, 2018
I'm working on having a dedicated folder for coverage with only IL to get source/line report for CoreLib. In the short run when running against CoreClr from a package (e.g.: CI) report will generate some messages like:
but since it doesn't fail the build I'm treating those as acceptable for now (one can even properly map the sources and get source coverage info for corelib).
pjanotti commentedon Jun 25, 2018
Right now CoreLib is back in CI but as mentioned above just the percentage numbers for Line and Branch coverage, that will be fixed via dotnet/buildtools#2077 that runs against the IL version of CoreLib.
pjanotti commentedon Jul 10, 2018
Daily coverage run has numbers for CoreLib, however, due to crashes it doesn't appear as the last coverage run. Closing this issue and following up on crashes and others in separate issues:
Some other related PRs:
dotnet/corefx#30972
dotnet/corefx#30967
dotnet/corefx#30966
dotnet/buildtools#2094
ViktorHofer commentedon Dec 6, 2018
Reopening as System.Private.CoreLib numbers are busted again. With my recent work I overlooked some details and we use the native System.Private.CoreLib.dll again. I'll try to solve this.