Skip to content

Code coverage for System.Private.CoreLib is broken in CI #23345

Closed
dotnet/corefx
#37172

Description

@stephentoub

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.

cc: @mellinoe, @danmosemsft

Activity

  1. stephentoub commented on Aug 27, 2017

    @stephentoub
    MemberAuthor

    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 😦
    image

  2. stephentoub commented on Aug 27, 2017

    @stephentoub
    MemberAuthor

    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.

  3. danmoseley commented on Aug 30, 2017

    @danmoseley
    Contributor

    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.

  4. stephentoub commented on Aug 30, 2017

    @stephentoub
    MemberAuthor

    I tried that before I tried compiling from source... failed miserably.

  5. stephentoub commented on Oct 4, 2017

    @stephentoub
    MemberAuthor

    Summarizing current workaround, to get code coverage for corelib, one needs to:

    1. Build the coreclr repo
    2. Build corelib without crossgen (build windowsmscorlib release)
    3. Build the corefx repo with CoreCLROverridePath to target the local coreclr build
    4. Build the https://github.com/icsharpcode/NRefactory/ repo
    5. 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
    6. Before running tests with /p:Coverage=true, set COMPlus_ZapDisable=1
  6. danmoseley commented on Oct 4, 2017

    @danmoseley
    Contributor

    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?

  7. stephentoub commented on Oct 4, 2017

    @stephentoub
    MemberAuthor

    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.

  8. danmoseley commented on Oct 4, 2017

    @danmoseley
    Contributor

    No, it distributes it.

  9. stephentoub commented on Oct 4, 2017

    @stephentoub
    MemberAuthor
  10. danmoseley commented on Oct 9, 2017

    @danmoseley
    Contributor

    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.

  11. danmoseley commented on Oct 9, 2017

    @danmoseley
    Contributor

    Howver, I can verify that report generator works fine.

  12. danmoseley commented on Oct 9, 2017

    @danmoseley
    Contributor

    It would be interesting to try stepping over the guid check to see whether the corelib pdb works correctly.

  13. stephentoub commented on Oct 9, 2017

    @stephentoub
    MemberAuthor

    I am trying to get coverage to work without building CoreCLR myself, instead using the corelib pdb that is now gotten automatically.

    What source would that match to / use to generate the rendered code coverage report?

  14. 39 remaining items

  15. pjanotti commented on Jun 16, 2018

    @pjanotti
    Contributor

    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:

    1. 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.

    2. 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.

  16. stephentoub commented on Jun 16, 2018

    @stephentoub
    MemberAuthor

    Great summary, thanks.

  17. pjanotti commented on Jun 21, 2018

    @pjanotti
    Contributor

    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...

  18. pjanotti commented on Jun 22, 2018

    @pjanotti
    Contributor

    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).

  19. pjanotti commented on Jun 25, 2018

    @pjanotti
    Contributor

    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.

  20. pjanotti commented on Jul 10, 2018

    @pjanotti
    Contributor

    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

  21. ViktorHofer commented on Dec 6, 2018

    @ViktorHofer
    Member

    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.

  22. transferred this issue fromdotnet/corefxon Jan 31, 2020
  23. added this to the 3.0 milestone on Jan 31, 2020
  24. ghost locked as resolved and limited conversation to collaborators on Dec 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions