1 <?xml version="1.0" encoding="utf-8"?>
2 <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <Import Project="src\dir.props" />
4 <Import Project="$(ToolsDir)Build.Post.targets" Condition="Exists('$(ToolsDir)Build.Post.targets') AND '$(BuildWrappers)' == 'true'" />
5 <Import Project="helixperftasks.targets" Condition="'$(Performance)'=='true'"/>
7 <XunitTestBinBase Condition="'$(XunitTestBinBase)'==''" >$(BaseOutputPathWithConfig)</XunitTestBinBase>
8 <XunitWrapperGeneratedCSDirBase>$(XunitTestBinBase)\TestWrappers\</XunitWrapperGeneratedCSDirBase>
9 <MSBuildEnableAllPropertyFunctions>1</MSBuildEnableAllPropertyFunctions>
12 <!-- TestHost destinations -->
14 <NETCoreAppTestSharedFxVersion>9.9.9</NETCoreAppTestSharedFxVersion>
15 <TestHostRootPath>$(BinDir)testhost\</TestHostRootPath>
16 <NETCoreAppTestHostFxrPath>$(TestHostRootPath)host\fxr\$(NETCoreAppTestSharedFxVersion)\</NETCoreAppTestHostFxrPath>
17 <NETCoreAppTestSharedFrameworkPath>$(TestHostRootPath)shared\Microsoft.NETCore.App\$(NETCoreAppTestSharedFxVersion)\</NETCoreAppTestSharedFrameworkPath>
21 <DisabledTestDir Include="Common" />
22 <_SkipTestDir Include="@(DisabledTestDir)" />
25 <Target Name="Rebuild" />
27 <Target Name="FindCmdDirectories" DependsOnTargets="GetListOfTestCmds">
29 <Error Condition="!Exists('$(XunitTestBinBase)')"
30 Text="$(XunitTestBinBase) does not exist. Please run build-test.cmd from the repo root at least once to get the tests built." />
34 <AllTestDirsNonCanonicalPaths Include="$([System.IO.Directory]::GetDirectories(`$(XunitTestBinBase)`))" />
35 <AllTestDirsPaths Include="@(AllTestDirsNonCanonicalPaths)" />
36 <AllTestDirsPaths Include="@(AllTestDirsNonCanonicalPaths)" >
37 <Path>$([System.IO.Path]::GetFullPath(%(Identity)))</Path>
39 <NonExcludedTestDirectories Include="@(AllTestDirsPaths -> '%(Path)')" Exclude="@(_SkipTestDir -> '$(XunitTestBinBase)%(Identity)')" />
40 <TopLevelDirectories Include="@(NonExcludedTestDirectories)" />
41 <SecondLevel Include="$([System.IO.Directory]::GetDirectories(%(TopLevelDirectories.Identity)))" />
42 <SecondLevelDirectories Include="@(SecondLevel)">
43 <Path>$([System.IO.Path]::GetFullPath(%(AllRunnableTestPaths.Identity)))</Path>
44 </SecondLevelDirectories>
45 <TestDirectoriesWithDup Include="@(SecondLevelDirectories -> '%(Identity)')" Condition="$([System.String]::new('%(Path)').StartsWith('%(Identity)'))" />
49 <RemoveDuplicates Inputs="@(TestDirectoriesWithDup)">
51 TaskParameter="Filtered"
52 ItemName="TestDirectories"/>
57 <!-- Target to check the test build, to see if it looks ok. We've had several cases where a change inadvertently and drastically changes
58 the set of tests that are built, and that change is unnoticed. The most common case is for a build of the Priority 1 tests
59 to only build the Priority 0 tests. This target is run after a test build to verify that the basic number of tests that were
60 built is basically what was expected.
62 <Target Name="CheckTestBuild" DependsOnTargets="GetListOfTestCmds">
63 <Error Condition="!Exists('$(XunitTestBinBase)')"
64 Text="$(XunitTestBinBase) does not exist. Please run build-test.cmd from the repo root at least once to get the tests built." />
67 <TestCount>@(AllRunnableTestPaths->Count())</TestCount>
70 <Message Text="Found $(TestCount) built tests"/>
72 <Error Condition="'$(CLRTestPriorityToBuild)' == '0' and '$(TestCount)' <= 2000" Text="Unexpected test count. Expected > 2000, found $(TestCount).'" />
73 <Error Condition="'$(CLRTestPriorityToBuild)' == '0' and '$(TestCount)' >= 3000" Text="Unexpected test count. Expected < 3000, found $(TestCount).'" />
74 <Error Condition="'$(CLRTestPriorityToBuild)' == '1' and '$(TestCount)' <= 11500" Text="Unexpected test count. Expected > 1150, found $(TestCount).'" />
75 <Error Condition="'$(CLRTestPriorityToBuild)' != '0' and '$(CLRTestPriorityToBuild)' != '1'" Text="Unknown priority $(CLRTestPriorityToBuild)" />
78 <Import Project="$(__Exclude)" Condition="'$(__Exclude)' != '' AND '$(XunitTestBinBase)' != ''" />
80 <HaveExcludes>False</HaveExcludes>
81 <HaveExcludes Condition="'$(__Exclude)' != ''">True</HaveExcludes>
84 <Target Name="CreateXunitWrapper" DependsOnTargets="CreateXunitFacts">
96 <XunitWrapperGenCsProj>
100 <Import Project="$(ProjectDir)dir.sdkbuild.props" />
103 <OutputPath>$(XUnitTestBinBase)\$(CategoryWithSlash)</OutputPath>
104 <RuntimeFrameworkVersion>$(MicrosoftNETCoreAppPackageVersion)</RuntimeFrameworkVersion>
107 <Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
110 <Compile Include="$(XunitWrapper).cs" />
114 <ProjectReference Include="$(SourceDir)Common\Coreclr.TestWrapper\Coreclr.TestWrapper.csproj" />
118 <PackageReference Include="xunit" Version="$(XunitPackageVersion)" />
119 <PackageReference Include="xunit.runner.console" Version="$(XunitPackageVersion)" />
122 <Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
126 </XunitWrapperGenCsProj>
129 <!-- <Exec Command="md" -->
130 <MakeDir Directories="$(XunitWrapperGeneratedCSDirBase)$(Category)"/>
132 <!-- Write the file -->
134 File="$(XunitWrapperSrcDir)\$(XunitWrapper).cs"
135 Lines="$(_XunitWrapperGen)"
138 <!-- Write the file -->
140 File="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj"
141 Lines="$(XunitWrapperGenCsProj)"
145 <Target Name="BuildXunitWrapper">
146 <MSBuild Projects="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj" Targets="Restore;Build" />
149 <Target Name="CreateXunitFacts">
150 <!-- NOTE! semicolons must be escaped with %3B boooo -->
153 <_CMDDIR_Parent>$([System.IO.Path]::GetDirectoryName($(_CMDDIR)))</_CMDDIR_Parent>
154 <_CMDDIR_Grandparent>$([System.IO.Path]::GetDirectoryName($(_CMDDIR_Parent)))</_CMDDIR_Grandparent>
155 <CategoryWithSlash Condition="'$(RunningOnUnix)' != 'true'" >$([System.String]::Copy('$(_CMDDIR)').Replace("$(_CMDDIR_Grandparent)\",""))</CategoryWithSlash>
156 <CategoryWithSlash Condition="'$(RunningOnUnix)' == 'true'" >$([System.String]::Copy('$(_CMDDIR)').Replace("$(_CMDDIR_Grandparent)/",""))</CategoryWithSlash>
157 <Category Condition="'$(RunningOnUnix)' != 'true'" >$([System.String]::Copy('$(CategoryWithSlash)').Replace('\','.'))</Category>
158 <Category Condition="'$(RunningOnUnix)' == 'true'" >$([System.String]::Copy('$(CategoryWithSlash)').Replace('/','.'))</Category>
159 <XunitWrapper>$(Category).XUnitWrapper</XunitWrapper>
160 <XunitWrapperSrcDir>$(XunitWrapperGeneratedCSDirBase)$(Category)</XunitWrapperSrcDir>
163 <_XunitProlog Condition=" '$(_XunitProlog)'=='' ">
167 using System.Collections.Generic%3B
168 using System.Diagnostics%3B
169 using System.Reflection%3B
170 using CoreclrTestLib%3B
172 namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").Replace("-","_"))
174 internal class _Global
176 internal static bool runningInWindows%3B
177 internal static string reportBase%3B
178 internal static string testBinaryBase%3B
179 internal static string coreRoot%3B
183 reportBase = System.Environment.GetEnvironmentVariable(%22XunitTestReportDirBase%22)%3B
184 testBinaryBase = System.IO.Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath)%3B
185 coreRoot = System.Environment.GetEnvironmentVariable(%22CORE_ROOT%22)%3B
187 if (String.IsNullOrEmpty(reportBase)) {
188 reportBase = System.IO.Path.Combine(testBinaryBase, "Reports")%3B
192 reportBase = System.IO.Path.GetFullPath(reportBase)%3B
195 if (String.IsNullOrEmpty(coreRoot)) {
196 throw new ArgumentException("Environment variable CORE_ROOT is not set")%3B
199 coreRoot = System.IO.Path.GetFullPath(coreRoot)%3B
201 string operatingSystem = System.Environment.GetEnvironmentVariable("OS")%3B
202 runningInWindows = (operatingSystem != null && operatingSystem.StartsWith("Windows"))%3B
209 <_XunitEpilog Condition=" '$(_XunitEpilog)'=='' ">
218 <CanonicalExcludeList Include="%(ExcludeList.FullPath)" Condition="$(HaveExcludes)"/>
222 <TestExecutableReplacement Condition="'$(TargetsWindows)' != 'true' ">testExecutable = testExecutable.Replace("\\", "/")%3B</TestExecutableReplacement>
226 <AllCMDsPresent Include="$(_CMDDIR)\**\*.cmd" Condition="'$(RunningOnUnix)' != 'true'" />
227 <AllCMDsPresent Include="$(_CMDDIR)\**\*.sh" Condition="'$(RunningOnUnix)' == 'true'" />
228 <AllCMDExcludeFilter Include="@(CanonicalExcludeList)" Condition="$(HaveExcludes)"/>
229 <AllCMDs Include="@(AllCMDsPresent)" Exclude="@(AllCMDExcludeFilter)"/>
231 <AllCommands Include="@(AllCMDs)" >
232 <_FactName Condition="'$(RunningOnUnix)' != 'true'" >$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_").Replace("\","_").Replace("-","_"))</_FactName>
233 <_ClassName Condition="'$(RunningOnUnix)' != 'true'" >$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace("cmd","").Replace(".","_").Replace("\","_").Replace("-","_"))</_ClassName>
234 <_FactName Condition="'$(RunningOnUnix)' == 'true'" >$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_").Replace("/","_").Replace("-","_"))</_FactName>
235 <_ClassName Condition="'$(RunningOnUnix)' == 'true'" >$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace("sh","").Replace(".","_").Replace("/","_").Replace("-","_"))</_ClassName>
240 public class %(AllCommands._ClassName)
243 public void %(AllCommands._FactName)()
246 string outputFile = null%3B
247 string errorFile = null%3B
248 string testExecutable = null%3B
249 Exception infraEx = null%3B
253 CoreclrTestWrapperLib wrapper = new CoreclrTestWrapperLib()%3B
254 string testSubfolder = @"\$(Category)\$([System.String]::Copy('%(AllCMDs.RelativeDir)').Replace("$(_CMDDIR)$([System.IO.Path]::DirectorySeparatorChar)",''))"%3B
255 outputFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).output.txt")%3B
256 errorFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).error.txt")%3B
257 testExecutable = System.IO.Path.GetFullPath(_Global.testBinaryBase + @"$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",''))")%3B
258 $(TestExecutableReplacement)
260 if (!_Global.runningInWindows) {
261 testExecutable = testExecutable.Replace(".cmd", ".sh")%3B
264 System.IO.Directory.CreateDirectory(_Global.reportBase + testSubfolder)%3B
266 ret = wrapper.RunTest(testExecutable, outputFile, errorFile)%3B
273 if (ret != CoreclrTestWrapperLib.EXIT_SUCCESS_CODE)
275 string sErrorText = null%3B
278 sErrorText = System.IO.File.ReadAllText(errorFile)%3B
282 sErrorText = $"Unable to read error file: {errorFile}\n{ex}"%3B
285 string outputText = null%3B
288 System.IO.StreamReader outputReader = new System.IO.StreamReader(outputFile)%3B
289 outputText = outputReader.ReadToEnd()%3B
290 outputReader.Close()%3B
294 outputText = $"Unable to read error file: {outputFile}\n{ex}"%3B
297 string msg = infraEx != null ? "Test Infrastructure Failure: " + infraEx.ToString()
298 : sErrorText + "\n\n" +
299 "Return code: " + ret + "\n" +
300 "Raw output file: " + outputFile + "\n" +
301 "Raw output:\n" + outputText + "\n" +
302 "To run the test:\n" +
303 "> set CORE_ROOT=" + _Global.coreRoot + "\n" +
304 "> " + testExecutable + "\n"%3B
306 Assert.True(ret == CoreclrTestWrapperLib.EXIT_SUCCESS_CODE, msg)%3B
314 <AllXUnitFacts Include= "%(AllCommands._XunitFact)" />
318 <Target Name="CreateAllWrappers" DependsOnTargets="GetListOfTestCmds;FindCmdDirectories">
319 <MSBuild Projects="$(MSBuildProjectFile)" Targets="CreateXunitWrapper;BuildXunitWrapper" Properties="_CMDDIR=%(TestDirectories.Identity)" />
322 <Target Name="GetListOfTestCmds">
324 <AllRunnableTestPaths Include="$(XunitTestBinBase)\**\*.cmd" Condition="'$(BuildOS)' == 'Windows_NT'" />
325 <AllRunnableTestPaths Include="$(XunitTestBinBase)\**\*.sh" Condition="'$(BuildOS)' != 'Windows_NT'" />
329 <!-- If we want to overwrite the desired CoreCLR package version, we need to get the new version from the generated props file in bin/obj -->
330 <Import Condition="'$(OverwriteCoreClrPackageVersion)' == 'true'" Project="$(BuildVersionFile)" />
332 <PropertyGroup Condition="'$(OverwriteCoreClrPackageVersion)' == 'true'">
333 <VersionToRestore Condition="'$(StableVersion)' != ''">$(StableVersion)</VersionToRestore>
334 <VersionToRestore Condition="'$(VersionToRestore)' == ''">$(PackageVersion)-$(PreReleaseLabel)-$(BuildNumberMajor)-$(BuildNumberMinor)</VersionToRestore>
335 <DesiredPackageVersionArg>$(VersionToRestore)</DesiredPackageVersionArg>
338 <Import Project="tests.targets" />
339 <Import Project="publishdependency.targets" />
342 <DesiredPackageVersionArg Condition="'$(DesiredPackageVersionArg)' == ''">$(MicrosoftNETCoreRuntimeCoreCLRPackageVersion)</DesiredPackageVersionArg>
345 <Target Name="CreateTestOverlay">
346 <MSBuild Projects="$(MSBuildProjectFile)"
347 Targets="CopyDependecyToCoreRoot"
348 Properties="Language=C#;TargetRid=$(TargetRid)" />
351 <Target Name="BinPlaceRef">
352 <!-- Copy mscorlib.dll from TargetingPack to bin/Product/ref, if we're building against packages -->
353 <MSBuild Projects="$(MSBuildProjectFile)"
354 Targets="CopyDependencyToRef"
355 Properties="Language=C#;TargetRid=$(TargetRid)"
356 Condition=" '$(BuildTestsAgainstPackages)'=='true' " />
359 <Target Name="BinPlaceProduct">
360 <!-- Copy test dependencies to bin/Product, if we're building against packages -->
361 <MSBuild Projects="$(MSBuildProjectFile)"
362 Targets="CopyDependencyToProduct"
363 Properties="Language=C#;TargetRid=$(TargetRid)"
364 Condition=" '$(BuildTestsAgainstPackages)'=='true' " />
367 <Target Name="ResolveTestHostDependencies">
368 <MSBuild Projects="$(MSBuildThisFileDirectory)src\Common\CoreFX\CoreFX.depproj"
369 Properties="OutputPath=$(NETCoreAppTestSharedFrameworkPath);" />
372 <Target Name="CreateTestHost" DependsOnTargets="ResolveTestHostDependencies">
373 <MSBuild Projects="$(MSBuildProjectFile)"
374 Targets="SetupTestingHost"/>
376 <MSBuild Projects="$(MSBuildProjectFile)"
377 Targets="GenerateTestSharedFrameworkDepsFile"/>
380 <UsingTask TaskName="GenerateDepsJson" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll"/>
381 <!-- After we copied all the framework libraries we need to generate a deps.json file for the shared test framework -->
382 <Target Name="GenerateTestSharedFrameworkDepsFile" AfterTargets="SetupTestingHost">
384 <!-- This is for HostPolicy, CoreCLR and Jit dependencies to continue to remain inside of the dep.json -->
385 <ExceptionForDepsJson Include="microsoft.netcore.app" />
387 <!-- TODO: We should see about generating this from scratch instead of relying on a previous deps file as a template -->
388 <_sharedFrameworkDepsJson Include="$(ToolsDir)dotnetcli\shared\Microsoft.NETCore.App\*\Microsoft.NETCore.App.deps.json" />
392 <_OriginalDepsJsonPath>%(_sharedFrameworkDepsJson.FullPath)</_OriginalDepsJsonPath>
393 <_OutputTestSharedFrameworkDepsPath>$(NETCoreAppTestSharedFrameworkPath)\Microsoft.NETCore.App.deps.json</_OutputTestSharedFrameworkDepsPath>
396 <GenerateDepsJson DepsJsonPath="$(_OriginalDepsJsonPath)"
397 GenerateNewDepsJson="true"
398 RuntimeDirectory="$(NETCoreAppTestSharedFrameworkPath)"
399 DepsExceptions="@(ExceptionForDepsJson)"
400 OutputPath="$(_OutputTestSharedFrameworkDepsPath)"/>
403 <Target Name="SetupTestingHost" AfterTargets="CreateTestOverlay" Condition="'$(CreateTestHost)' != 'false'">
405 <PropertyGroup Condition="'$(OSGroup)'=='Windows_NT'">
406 <HostFxrFileName>hostfxr</HostFxrFileName>
407 <HostFxrFileExtension>dll</HostFxrFileExtension>
408 <DotnetExecutableName>dotnet.exe</DotnetExecutableName>
409 <HostPolicyFileName>hostpolicy</HostPolicyFileName>
410 <HostPolicyExtension>dll</HostPolicyExtension>
413 <PropertyGroup Condition="'$(OSGroup)'!='Windows_NT'">
414 <HostFxrFileName>libhostfxr</HostFxrFileName>
415 <HostFxrFileExtension Condition="'$(OSGroup)' == 'Linux' Or '$(OSGroup)' == 'FreeBSD'">so</HostFxrFileExtension>
416 <HostFxrFileExtension Condition="$(OSGroup) =='OSX'">dylib</HostFxrFileExtension>
417 <HostPolicyFileName>libhostpolicy</HostPolicyFileName>
418 <HostPolicyExtension>$(HostFxrFileExtension)</HostPolicyExtension>
419 <DotnetExecutableName>dotnet</DotnetExecutableName>
423 <!-- Workaround for packages on which Microsoft.NetCoreApp expresses a dependency
424 The <PackageToInclude> element doesn't allow a version to be specified and we end up with clashing assembly versions in Core_Root-->
425 <NetCoreAppPackagedAssemblies Include="System.Text.Encoding.CodePages.dll"/>
426 <!-- Use xunit dependencies defined in CoreFX.depproj instead of conflicting versions from test dependencies. -->
427 <TestDependenciesToExclude Include="$(CORE_ROOT)\**\xunit*"/>
428 <CoreCLRBinariesToExclude Include="@(NetCoreAppPackagedAssemblies);@(TestDependenciesToExclude -> '%(Identity)')" />
432 <CoreCLRBinaries Include="$(CORE_ROOT)\**\*.*" Exclude="$(CORE_ROOT)\**\@(CoreCLRBinariesToExclude -> '%(Identity)' )" />
433 <HostFxFile Include="$(ToolsDir)\dotnetcli\**\$(HostFxrFileName).$(HostFxrFileExtension)" />
434 <DotnetExe Include="$(ToolsDir)\dotnetcli\$(DotnetExecutableName)" />
435 <HostPolicyFile Include="$(ToolsDir)\dotnetcli\**\$(HostPolicyFileName).$(HostPolicyExtension)" />
438 <Copy SourceFiles="@(HostFxFile)"
439 DestinationFolder="$(NETCoreAppTestHostFxrPath)"
440 SkipUnchangedFiles="true"
441 UseHardlinksIfPossible="true" />
443 <!-- Should this be referenced from a NuGet package? -->
444 <Copy SourceFiles="@(HostPolicyFile)"
445 DestinationFolder="$(NETCoreAppTestSharedFrameworkPath)"
446 SkipUnchangedFiles="true"
447 UseHardlinksIfPossible="true" />
449 <Copy SourceFiles="@(DotnetExe)"
450 DestinationFolder="$(TestHostRootPath)"
451 SkipUnchangedFiles="true"
452 UseHardlinksIfPossible="true" />
454 <Copy SourceFiles="@(CoreCLRBinaries)"
455 DestinationFolder="$(NETCoreAppTestSharedFrameworkPath)"
456 SkipUnchangedFiles="true" />
459 <Target Name="RunPerfTests" Condition="'$(Performance)'=='true'">
460 <Message Text="Executing steps for perf tests" Importance="High"/>
462 <!-- generate project.json for runtime dependency -->
463 <MSBuild Projects="$(MSBuildProjectFile)"
464 Targets="CreateTestRuntimeJsonFile"/>
466 <!-- generate project.lock.json file corresponding to above json file -->
467 <MSBuild Projects="src\Common\test_dependencies\test_dependencies.csproj"/>
469 <!-- Package each perf test, upload it and trigger event to execute the tests -->
470 <MSBuild Projects="$(MSBuildProjectFile)" Targets="UploadPerfAssemblies" />
474 <Target Name="Build">
476 <!-- generate project.lock.json file corresponding to above json file -->
477 <MSBuild Projects="src\Common\test_dependencies\test_dependencies.csproj"
478 Condition=" '$(BuildWrappers)'=='true' " />
480 <!-- Default for building -->
481 <MSBuild Projects="$(MSBuildProjectFile)"
482 Targets="CreateAllWrappers"
483 Properties="_CMDDIR=%(TestDirectories.Identity)"
484 Condition=" '$(BuildWrappers)'=='true' " />
488 <MSBuild Projects="$(MSBuildProjectFile)"
489 Targets="CreateTestOverlay"
490 Condition=" '$(GenerateRuntimeLayout)'=='true' "/>
492 <MSBuild Projects="$(MSBuildProjectFile)"
493 Targets="CreateTestHost"
494 Condition=" '$(GenerateTestHost)'=='true' "/>
496 <MSBuild Projects="$(MSBuildProjectFile)" Targets="RunTests"
497 Condition=" '$(RunTests)'=='true' "/>
500 <Target Name="Clean">
501 <RemoveDir Condition=" '$(BuildWrappers)'=='true'" Directories="$(XunitWrapperGeneratedCSDirBase);" ContinueOnError="WarnAndContinue" />