Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.

Create a runtime dedicated to coverage using IL only #2077

Merged
merged 3 commits into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 40 additions & 47 deletions src/Microsoft.DotNet.Build.Tasks/PackageFiles/CodeCoverage.targets
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
<CodeCoverageEnabled Condition="'$(SkipTests)' != 'true' and '$(RunningOnUnix)' != 'true' and '$(Coverage)' == 'true' and '$(Performance)' != 'true'">true</CodeCoverageEnabled>
<CoverageReportDir Condition="'$(CoverageReportDir)' == ''">$(TestWorkingDir)coverage\</CoverageReportDir>

<RestoreIlPdbsWithHardlinks Condition="'$(RestoreIlPdbsWithHardlinks)' == ''">true</RestoreIlPdbsWithHardlinks>

<UseCoverageDedicatedRuntime Condition="'$(UseCoverageDedicatedRuntime)' == ''">true</UseCoverageDedicatedRuntime>
<CoverageDedicatedRuntimeDir>$(TestHostRootPath)shared/Microsoft.NETCore.App/10.10.10</CoverageDedicatedRuntimeDir>

<!-- This targets file has two modes one for individual projects and one for all -->
<GenerateCodeCoverageReportForAll Condition="'$(GenerateCodeCoverageReportForAll)'==''">false</GenerateCodeCoverageReportForAll>
<CoverageEnabledForProject Condition="'$(GenerateCodeCoverageReportForAll)'=='true'">false</CoverageEnabledForProject>
Expand Down Expand Up @@ -52,59 +53,58 @@
</PropertyGroup>
</Target>

<!-- Workaround OpenCover symbol matching behavior by moving pdb files for coverage runs -->
<Target Name="ReplaceIlPdbsOnTestHost" BeforeTargets="GenerateTestExecutionScripts" Condition="'$(CodeCoverageEnabled)'=='true'">
<Message Importance="high" Text="Replacing IL pdbs with respective pdbs for crossgen images (workaround OpenCover issue)." />
<ItemGroup>
<SelectedNiPdbFiles Include="@(_CodeCoverageAssemblies -> '$(NETCoreAppTestSharedFrameworkPath)ni/%(Identity).ni.pdb')"
Condition="Exists('$(NETCoreAppTestSharedFrameworkPath)/il/%(Identity).pdb') AND Exists('$(NETCoreAppTestSharedFrameworkPath)/ni/%(Identity).ni.pdb')" >
<IlPdbPath>$(NETCoreAppTestSharedFrameworkPath)%(Identity).pdb</IlPdbPath>
</SelectedNiPdbFiles>
</ItemGroup>

<!-- Delete the files under the test host to break any existing hardlinks -->
<Delete Files="@(SelectedNiPdbFiles -> '%(IlPdbPath)')" />

<!-- Put renamed pdbs in place -->
<Copy SourceFiles="@(SelectedNiPdbFiles)"
DestinationFiles="%(SelectedNiPdbFiles.IlPdbPath)"
SkipUnchangedFiles="true" />
</Target>

<!-- General task to restore pdbs that may have been replaced for OpenCover workaround -->
<Target Name="RestoreIlPdbs">
<Target Name="CreateCoverageDedicatedRuntime"
BeforeTargets="GenerateTestExecutionScripts"
Condition="'$(CodeCoverageEnabled)'=='true' and '$(UseCoverageDedicatedRuntime)'=='true'">
<PropertyGroup>
</PropertyGroup>
<ItemGroup>
<!-- Assume that all ni pdbs were replaced (ensures full restore) -->
<PdbsToRestore Include="$(NETCoreAppTestSharedFrameworkPath)il/*.pdb" />
<_RuntimeFiles Include="$(NETCoreAppTestSharedFrameworkPath)/*.*" />
<RuntimeFiles Include="%(_RuntimeFiles.Identity)" Condition="!Exists('$(NETCoreAppTestSharedFrameworkPath)il/%(Filename)%(Extension)')" />
<RuntimeFiles Include="$(NETCoreAppTestSharedFrameworkPath)il/*.*" />
<RuntimeFilesAmd64 Include="$(NETCoreAppTestSharedFrameworkPath)amd64/*.*" />
<RuntimeFilesx86 Include="$(NETCoreAppTestSharedFrameworkPath)x86/*.*" />
</ItemGroup>

<Copy SourceFiles="@(PdbsToRestore)"
DestinationFolder="$(NETCoreAppTestSharedFrameworkPath)"
SkipUnchangedFiles="true"
UseHardlinksIfPossible="$(RestoreIlPdbsWithHardlinks)" />
</Target>

<!-- Il pdbs may need to be restored due to previous coverage runs that replaced them with IL versions -->
<Target Name="RestoreIlPdbsForTestRun"
BeforeTargets="GenerateTestExecutionScripts"
DependsOnTargets="RestoreIlPdbs"
Condition="'$(CodeCoverageEnabled)' != 'true' AND '$(SkipTests)' != 'true' AND '$(RunningOnUnix)' != 'true'">
<Message Importance="normal" Text="Restoring IL pdbs that were potentially replaced with respective crossgen pdbs." />
<Copy SourceFiles="@(RuntimeFiles)"
DestinationFolder="$(CoverageDedicatedRuntimeDir)"
SkipUnchangedFiles="true"
UseHardlinksIfPossible="false" />
<Copy SourceFiles="@(RuntimeFilesAmd64)"
DestinationFolder="$(CoverageDedicatedRuntimeDir)/amd64/"
SkipUnchangedFiles="true"
UseHardlinksIfPossible="false" />
<Copy SourceFiles="@(RuntimeFilesx86)"
DestinationFolder="$(CoverageDedicatedRuntimeDir)/x86/"
SkipUnchangedFiles="true"
UseHardlinksIfPossible="false" />
</Target>

<!-- *********************************************************************************************** -->
<!-- As of 10/2017 OpenCover does not support portable PDBs, but we want the builds to generate
portable PDBs. Thus we generate windows PDBs from portable PDBs here. Can be removed
when OpenCover directly supports Portable PDBs (probably by early 2018) -->

<Choose>
<When Condition="'$(UseCoverageDedicatedRuntime)'=='true'">
<PropertyGroup>
<CoverageRuntimeDir>$(CoverageDedicatedRuntimeDir)</CoverageRuntimeDir>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<CoverageRuntimeDir>$(NETCoreAppTestSharedFrameworkPath)</CoverageRuntimeDir>
</PropertyGroup>
</Otherwise>
</Choose>

<Target Name="GenerateWindowsPdbsForAssemblyBeingTested"
BeforeTargets="GenerateTestExecutionScripts"
Condition="'$(CodeCoverageEnabled)' == 'true' and '$(TargetOS)'=='Windows_NT'">

<!-- We look for the DLL being tested for coverage and its PDB create a WindowsPDB\*.pdb which has
the windows PDB. -->
<ItemGroup>
<CandidateAssemblies Include="@(_CodeCoverageAssemblies -> '$(NETCoreAppTestSharedFrameworkPath)%(Identity)')" />
<CandidateAssemblies Include="@(_CodeCoverageAssemblies -> '$(CoverageRuntimeDir)/%(Identity)')" />

<ExistingPortableDllsToConvert
Include="@(CandidateAssemblies -> '%(Identity).dll' )"
Expand All @@ -127,7 +127,7 @@
it does unblock things and this is all intended to be temporary until OpenCover supports
portable PDBs directly -->
<Message Importance="high" Text="Replacing Portable PDB with Windows Pdb in place!" />
<Copy SourceFiles="%(ExistingPortableDllsToConvert.TargetPath)" DestinationFolder="$(NETCoreAppTestSharedFrameworkPath)" Condition="Exists('%(ExistingPortableDllsToConvert.TargetPath)')"/>
<Copy SourceFiles="%(ExistingPortableDllsToConvert.TargetPath)" DestinationFolder="$(CoverageRuntimeDir)" Condition="Exists('%(ExistingPortableDllsToConvert.TargetPath)')"/>
</Target>
<!-- *********************************************************************************************** -->

Expand Down Expand Up @@ -212,11 +212,4 @@
OutputReport="$(CoverageReportDir)\VisitedMethodsReport.xml"/>
</Target>

<!-- Restore IL pdbs to testhost -->
<Target Name="RestoreIlPdbsToTestHostAfterCoverageReports"
AfterTargets="GenerateIndividualCoverageReport;GenerateFullCoverageReport"
DependsOnTargets="RestoreIlPdbs">
<Message Importance="normal" Text="Restoring IL pdbs that were potentially replaced with respective crossgen pdbs." />
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"runtimeOptions": {
"framework": {
"name": "Microsoft.NETCore.App",
"version": "10.10.10"

This comment was marked as spam.

This comment was marked as spam.

}
}
}
25 changes: 23 additions & 2 deletions src/Microsoft.DotNet.Build.Tasks/PackageFiles/tests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
</ItemGroup>

<PropertyGroup Condition="'$(BuildingNETFxVertical)' != 'true'">
<XunitRuntimeConfig>$(ToolsDir)\xunit.console.netcore.runtimeconfig.json</XunitRuntimeConfig>
<TestRuntimeEnvVar Condition="'$(RunningOnUnix)'!='true'">%RUNTIME_PATH%\</TestRuntimeEnvVar>
<TestRuntimeEnvVar Condition="'$(RunningOnUnix)'=='true'">$RUNTIME_PATH/</TestRuntimeEnvVar>
<TestHostExecutablePath Condition="'$(RunningOnUnix)'!='true' AND '$(TestHostExecutablePath)' == '' AND '$(BuildingUAPAOTVertical)' != 'true'">$(TestRuntimeEnvVar)dotnet.exe</TestHostExecutablePath>
<TestHostExecutablePath Condition="'$(RunningOnUnix)'=='true' AND '$(TestHostExecutablePath)' == '' AND '$(BuildingUAPAOTVertical)' != 'true'">$(TestRuntimeEnvVar)dotnet</TestHostExecutablePath>

<XunitExecutable Condition="'$(XunitExecutable)' == ''">xunit.console.netcore.exe</XunitExecutable>
<XunitRuntimeConfigFile>xunit.console.netcore.runtimeconfig.json</XunitRuntimeConfigFile>

<DebugEngines>{2E36F1D4-B23C-435D-AB41-18E608940038}</DebugEngines>
</PropertyGroup>
Expand Down Expand Up @@ -96,6 +96,20 @@

<!-- The Code Coverage targets will override TestHost and TestCommandLine if coverage is enabled -->
<Import Project="$(MSBuildThisFileDirectory)CodeCoverage.targets" />
<Choose>
<When Condition="'$(CodeCoverageEnabled)'=='true' and '$(UseCoverageDedicatedRuntime)'=='true'">
<PropertyGroup>
<XunitRuntimeConfig>$(ToolsDir)coverage/$(XunitRuntimeConfigFile)</XunitRuntimeConfig>
<UsingCoverageDedicatedRuntime>true</UsingCoverageDedicatedRuntime>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<XunitRuntimeConfig>$(ToolsDir)$(XunitRuntimeConfigFile)</XunitRuntimeConfig>
<UsingCoverageDedicatedRuntime>false</UsingCoverageDedicatedRuntime>
</PropertyGroup>
</Otherwise>
</Choose>

<!-- In VS (2015 Preview or later currently required): Debug to run unit tests on CoreCLR. -->
<PropertyGroup Condition="'$(IsTestProject)'=='true'">
Expand All @@ -114,7 +128,14 @@
<RunTestsForProjectInputs Include="@(AllItemsFullPathWithTargetPath)" />
</ItemGroup>
<ItemGroup Condition="'$(BuildingNETFxVertical)' != 'true'">
<SupplementalTestData Condition="'$(SkipXunitRuntimeConfigCopying)' != 'true'" Include="$(XunitRuntimeConfig)" />
<!-- SupplementalTestData has its own properties to control hard links, however, with the coverage dedicated runtime that will override the original -->
<Delete Condition="'@(UsingCoverageDedicatedRuntime)' == 'true' and Exists('$(TestPath)$(XunitRuntimeConfigFile)')"
Files="'$(TestPath)$(XunitRuntimeConfigFile)'" />
<Copy Condition="'@(UsingCoverageDedicatedRuntime)' == 'true'"
SourceFiles="$(XunitRuntimeConfig)"
DestinationFolder="$(TestPath)"
UseHardLinksIfPossible="false" />
<SupplementalTestData Condition="'$(SkipXunitRuntimeConfigCopying)' != 'true' and '@(UsingCoverageDedicatedRuntime)' != 'true'" Include="$(XunitRuntimeConfig)" />
<SupplementalTestData Include="$(RuntimePath)xunit.console.netcore.exe" />
</ItemGroup>
<ItemGroup Condition="'$(BuildingNETFxVertical)' == 'true'">
Expand Down