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 <XunitWrapperOutputIntermediatedDirBase>$(XunitTestBinBase)\Tests\</XunitWrapperOutputIntermediatedDirBase>
10 <MSBuildEnableAllPropertyFunctions>1</MSBuildEnableAllPropertyFunctions>
14 <DisabledTestDir Include="Common" />
15 <_SkipTestDir Include="@(DisabledTestDir)" />
18 <Target Name="Rebuild" />
20 <Target Name="FindCmdDirectories" DependsOnTargets="GetListOfTestCmds">
22 <Error Condition="!Exists('$(XunitTestBinBase)')"
23 Text="$(XunitTestBinBase) does not exist. Please run buildtest.cmd from the (repo root)\tests at least once to get the tests built." />
27 <AllTestDirsNonCanonicalPaths Include="$([System.IO.Directory]::GetDirectories(`$(XunitTestBinBase)`))" />
28 <AllTestDirsPaths Include="@(AllTestDirsNonCanonicalPaths)" />
29 <AllTestDirsPaths Include="@(AllTestDirsNonCanonicalPaths)" >
30 <Path>$([System.IO.Path]::GetFullPath(%(Identity)))</Path>
32 <NonExcludedTestDirectories Include="@(AllTestDirsPaths -> '%(Path)')" Exclude="@(_SkipTestDir -> '$(XunitTestBinBase)%(Identity)')" />
33 <TopLevelDirectories Include="@(NonExcludedTestDirectories)" />
34 <SecondLevel Include="$([System.IO.Directory]::GetDirectories(%(TopLevelDirectories.Identity)))" />
35 <SecondLevelDirectories Include="@(SecondLevel)">
36 <Path>$([System.IO.Path]::GetFullPath(%(AllRunnableTestPaths.Identity)))</Path>
37 </SecondLevelDirectories>
38 <TestDirectoriesWithDup Include="@(SecondLevelDirectories -> '%(Identity)')" Condition="$([System.String]::new('%(Path)').StartsWith('%(Identity)'))" />
42 <RemoveDuplicates Inputs="@(TestDirectoriesWithDup)">
44 TaskParameter="Filtered"
45 ItemName="TestDirectories"/>
50 <Import Project="$(__Exclude)" Condition="'$(__Exclude)' != '' AND '$(XunitTestBinBase)' != ''" />
52 <HaveExcludes>False</HaveExcludes>
53 <HaveExcludes Condition="'$(__Exclude)' != ''">True</HaveExcludes>
56 <Target Name="CreateXunitWrapper" DependsOnTargets="CreateXunitFacts">
68 <XunitWrapperGenCsProj>
70 <?xml version="1.0" encoding="utf-8"?>
71 <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
73 <Import Project="$(SourceDir)dir.props" />
75 <Configuration Condition=" '%24(Configuration)' == '' ">Debug</Configuration>
76 <Platform Condition=" '%24(Platform)' == '' ">AnyCPU</Platform>
77 <AssemblyName>$(XunitWrapper)</AssemblyName>
78 <SchemaVersion>2.0</SchemaVersion>
79 <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
80 <OutputType>Library</OutputType>
81 <TargetFrameworkIdentifier Condition ="('$(BuildTestsAgainstPackages)' != 'true') And ('$(BuildOS)' == 'Windows_NT')">.NETFramework</TargetFrameworkIdentifier>
82 <TargetFrameworkVersion Condition ="('$(BuildTestsAgainstPackages)' != 'true') And ('$(BuildOS)' == 'Windows_NT')">v4.5</TargetFrameworkVersion>
83 <NugetTargetMonikerShort Condition ="'$(BuildTestsAgainstPackages)' != 'true'">net45</NugetTargetMonikerShort>
84 <IsXunitWrapperProject>true</IsXunitWrapperProject>
85 <SkipSigning>true</SkipSigning>
86 <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB}%3B{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
87 <SolutionDir Condition="%24(SolutionDir) == '' Or %24(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
88 <CLRTestKind>BuildOnly</CLRTestKind>
89 <IsTestProject>true</IsTestProject>
91 <!-- Default configurations to help VS understand the configurations -->
92 <PropertyGroup Condition=" '%24(Configuration)|%24(Platform)' == 'Debug|AnyCPU' ">
94 <PropertyGroup Condition=" '%24(Configuration)|%24(Platform)' == 'Release|AnyCPU' ">
97 <Compile Include="$(XunitWrapper).cs" />
100 <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
103 <ProjectReference Include="$(SourceDir)Common\Desktop.Coreclr.TestWrapper\Desktop.Coreclr.TestWrapper.csproj" Condition="('$(BuildTestsAgainstPackages)' != 'true') And ('$(BuildOS)' == 'Windows_NT')">
104 <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
107 <ProjectReference Include="$(SourceDir)Common\Coreclr.TestWrapper\Coreclr.TestWrapper.csproj" Condition="('$(BuildTestsAgainstPackages)' == 'true') Or ('$(BuildOS)' != 'Windows_NT')">
108 <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
114 <Reference Include="System" />
115 <Reference Include="System.Runtime" />
116 <Reference Include="mscorlib" />
118 <Import Project="$(SourceDir)dir.targets" />
120 <OutDir>$(XunitTestBinBase)\$(CategoryWithSlash)\</OutDir>
121 <ProjectAssetsFile Condition="'$(BuildTestsAgainstPackages)' != 'true'">%24(TestWrappersPackagesConfigFileDirectory)obj/project.assets.json</ProjectAssetsFile>
125 </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"/>
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>
161 <XunitWrapperOutputDir>$(XunitWrapperOutputIntermediatedDirBase)$(Category)</XunitWrapperOutputDir>
164 <_XunitProlog Condition=" '$(_XunitProlog)'=='' ">
168 using System.Collections.Generic%3B
169 using System.Diagnostics%3B
170 using System.Reflection%3B
171 using CoreclrTestLib%3B
173 namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").Replace("-","_"))
175 internal class _Global
177 internal static bool runningInWindows%3B
178 internal static string reportBase%3B
179 internal static string testBinaryBase%3B
180 internal static string coreRoot%3B
184 reportBase = System.Environment.GetEnvironmentVariable(%22XunitTestReportDirBase%22)%3B
185 testBinaryBase = System.IO.Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath)%3B
186 coreRoot = System.IO.Path.GetFullPath(System.Environment.GetEnvironmentVariable(%22CORE_ROOT%22))%3B
188 if (String.IsNullOrEmpty(reportBase)) {
189 reportBase = System.IO.Path.Combine(testBinaryBase, "Reports")%3B
193 reportBase = System.IO.Path.GetFullPath(reportBase)%3B
196 if (String.IsNullOrEmpty(coreRoot)) {
197 throw new ArgumentException("Environment variable CORE_ROOT is not set")%3B
200 string operatingSystem = System.Environment.GetEnvironmentVariable("OS")%3B
201 runningInWindows = (operatingSystem != null && operatingSystem.StartsWith("Windows"))%3B
208 <_XunitEpilog Condition=" '$(_XunitEpilog)'=='' ">
217 <CanonicalExcludeList Include="%(ExcludeList.FullPath)" Condition="$(HaveExcludes)"/>
221 <TestExecutableReplacement Condition="'$(TargetsWindows)' != 'true' ">testExecutable = testExecutable.Replace("\\", "/")%3B</TestExecutableReplacement>
225 <AllCMDsPresent Include="$(_CMDDIR)\**\*.cmd" Condition="'$(RunningOnUnix)' != 'true'" />
226 <AllCMDsPresent Include="$(_CMDDIR)\**\*.sh" Condition="'$(RunningOnUnix)' == 'true'" />
227 <AllCMDExcludeFilter Include="@(CanonicalExcludeList)" Condition="$(HaveExcludes)"/>
228 <AllCMDs Include="@(AllCMDsPresent)" Exclude="@(AllCMDExcludeFilter)"/>
230 <AllCommands Include="@(AllCMDs)" >
231 <_FactName Condition="'$(RunningOnUnix)' != 'true'" >$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_").Replace("\","_").Replace("-","_"))</_FactName>
232 <_ClassName Condition="'$(RunningOnUnix)' != 'true'" >$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace("cmd","").Replace(".","_").Replace("\","_").Replace("-","_"))</_ClassName>
233 <_FactName Condition="'$(RunningOnUnix)' == 'true'" >$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_").Replace("/","_").Replace("-","_"))</_FactName>
234 <_ClassName Condition="'$(RunningOnUnix)' == 'true'" >$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace("sh","").Replace(".","_").Replace("/","_").Replace("-","_"))</_ClassName>
239 public class %(AllCommands._ClassName)
242 public void %(AllCommands._FactName)()
245 string outputFile = null%3B
246 string errorFile = null%3B
247 string testExecutable = null%3B
248 Exception infraEx = null%3B
252 CoreclrTestWrapperLib wrapper = new CoreclrTestWrapperLib()%3B
253 string testSubfolder = @"\$(Category)\$([System.String]::Copy('%(AllCMDs.RelativeDir)').Replace("$(_CMDDIR)\",''))"%3B
254 outputFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).output.txt")%3B
255 errorFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).error.txt")%3B
256 testExecutable = System.IO.Path.GetFullPath(_Global.testBinaryBase + @"$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",''))")%3B
257 $(TestExecutableReplacement)
259 if (!_Global.runningInWindows) {
260 testExecutable = testExecutable.Replace(".cmd", ".sh")%3B
263 System.IO.Directory.CreateDirectory(_Global.reportBase + testSubfolder)%3B
265 ret = wrapper.RunTest(testExecutable, outputFile, errorFile)%3B
272 if (ret != CoreclrTestWrapperLib.EXIT_SUCCESS_CODE)
274 string sErrorText = null%3B
277 sErrorText = System.IO.File.ReadAllText(errorFile)%3B
281 sErrorText = "Unable to read error file: " + errorFile%3B
284 string outputText = null%3B
287 System.IO.StreamReader outputReader = new System.IO.StreamReader(outputFile)%3B
288 outputText = outputReader.ReadToEnd()%3B
289 outputReader.Close()%3B
293 outputText = "Unable to read output file: " + outputFile%3B
296 string msg = infraEx != null ? "Test Infrastructure Failure: " + infraEx.Message
297 : sErrorText + "\n\n" +
298 "Return code: " + ret + "\n" +
299 "Raw output file: " + outputFile + "\n" +
300 "Raw output:\n" + outputText + "\n" +
301 "To run the test:\n" +
302 "> set CORE_ROOT=" + _Global.coreRoot + "\n" +
303 "> " + testExecutable + "\n"%3B
305 Assert.True(ret == CoreclrTestWrapperLib.EXIT_SUCCESS_CODE, msg)%3B
313 <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" />
328 <!-- 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 -->
329 <Import Condition="'$(OverwriteCoreClrPackageVersion)' == 'true'" Project="$(BuildVersionFile)" />
331 <PropertyGroup Condition="'$(OverwriteCoreClrPackageVersion)' == 'true'">
332 <VersionToRestore Condition="'$(StableVersion)' != ''">$(StableVersion)</VersionToRestore>
333 <VersionToRestore Condition="'$(VersionToRestore)' == ''">$(PackageVersion)-$(PreReleaseLabel)-$(BuildNumberMajor)-$(BuildNumberMinor)</VersionToRestore>
334 <DesiredPackageVersionArg>$(VersionToRestore)</DesiredPackageVersionArg>
337 <Import Project="tests.targets" />
338 <Import Project="publishdependency.targets" />
341 <TargetRid Condition="'$(RuntimeId)' != ''">$(RuntimeId)</TargetRid>
342 <TargetRid Condition="'$(RuntimeId)' == ''">$(TestNugetRuntimeId)</TargetRid>
343 <DesiredPackageVersionArg Condition="'$(DesiredPackageVersionArg)' == ''">$(CoreClrPackageVersion)</DesiredPackageVersionArg>
346 <Target Name="CreateTestOverlay">
347 <MSBuild Projects="$(MSBuildProjectFile)"
348 Targets="CopyDependecyToCoreRoot"
349 Properties="Language=C#;TargetRid=$(TargetRid)" />
352 <Target Name="BinPlaceRef">
353 <!-- Copy mscorlib.dll from TargetingPack to bin/Product/ref, if we're building against packages -->
354 <MSBuild Projects="$(MSBuildProjectFile)"
355 Targets="CopyDependencyToRef"
356 Properties="Language=C#;TargetRid=$(TargetRid)"
357 Condition=" '$(BuildTestsAgainstPackages)'=='true' " />
360 <Target Name="BinPlaceProduct">
361 <!-- Copy test dependencies to bin/Product, if we're building against packages -->
362 <MSBuild Projects="$(MSBuildProjectFile)"
363 Targets="CopyDependencyToProduct"
364 Properties="Language=C#;TargetRid=$(TargetRid)"
365 Condition=" '$(BuildTestsAgainstPackages)'=='true' " />
368 <!-- All the test projects need to add dependency to currently built runtime as they require that to run.
369 In addition the version number of built runtime can change so all project.json needs to be dynamically generated.
370 Instead the following task creates a project.json with dependencies like Microsoft.netcore.runtime.coreclr ..etc.
372 <Target Name="CreateTestRuntimeJsonFile">
374 <CoreclrPackage Include="$(CORE_ROOT)\.nuget\**\Microsoft.NETCore.Runtime.CoreCLR.*.nupkg"/>
377 <CoreclrPackageFileName>%(CoreclrPackage.Filename)</CoreclrPackageFileName>
378 <!-- Get package version number from nuget package filename at core_root -->
379 <CoreClrPackageVersion Condition="'$(BuildTestsAgainstPackages)'!='true'">$([System.String]::Copy('$(CoreclrPackageFileName)').Replace('Microsoft.NETCore.Runtime.CoreCLR.',''))</CoreClrPackageVersion>
380 <TestRuntimeJsonContents>
384 "Microsoft.NETCore.Runtime.CoreCLR": "$(CoreClrPackageVersion)",
385 "Microsoft.NETCore.TestHost": "1.0.0-rc3-24117-00"
391 "$(TestNugetRuntimeId)":{}
396 </TestRuntimeJsonContents>
399 <MakeDir Directories="$(TestRuntimeProjectJsonDir)" Condition="!Exists('$(TestRuntimeProjectJsonDir)')" />
401 <!-- Write the file -->
403 File="$(TestRuntimeProjectJson)"
404 Lines="$(TestRuntimeJsonContents)"
409 <Target Name="RunPerfTests" Condition="'$(Performance)'=='true'">
410 <Message Text="Executing steps for perf tests" Importance="High"/>
412 <!-- generate project.json for runtime dependency -->
413 <MSBuild Projects="$(MSBuildProjectFile)"
414 Targets="CreateTestRuntimeJsonFile"/>
416 <!-- generate project.lock.json file corresponding to above json file -->
417 <MSBuild Projects="src\Common\test_dependencies\test_dependencies.csproj"/>
419 <!-- Package each perf test, upload it and trigger event to execute the tests -->
420 <MSBuild Projects="$(MSBuildProjectFile)" Targets="UploadPerfAssemblies" />
424 <Target Name="Build">
426 <!-- generate project.json for runtime dependency -->
427 <MSBuild Projects="$(MSBuildProjectFile)"
428 Targets="CreateTestRuntimeJsonFile"
429 Condition=" '$(BuildWrappers)'=='true' " />
431 <!-- generate project.lock.json file corresponding to above json file -->
432 <MSBuild Projects="src\Common\test_dependencies\test_dependencies.csproj"
433 Condition=" '$(BuildWrappers)'=='true' " />
435 <!-- Default for building -->
436 <MSBuild Projects="$(MSBuildProjectFile)"
437 Targets="CreateAllWrappers"
438 Properties="_CMDDIR=%(TestDirectories.Identity)"
439 Condition=" '$(BuildWrappers)'=='true' " />
443 <MSBuild Projects="$(MSBuildProjectFile)"
444 Targets="CreateTestOverlay"
445 Condition=" '$(GenerateRuntimeLayout)'=='true' "/>
447 <MSBuild Projects="$(MSBuildProjectFile)" Targets="RunTests"
448 Condition=" '$(RunTests)'=='true' "/>
451 <Target Name="Clean">
452 <RemoveDir Condition=" '$(BuildWrappers)'=='true'" Directories="$(XunitWrapperGeneratedCSDirBase);$(XunitWrapperOutputIntermediatedDirBase)" ContinueOnError="WarnAndContinue" />