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'">.NETFramework</TargetFrameworkIdentifier>
82 <TargetFrameworkVersion Condition ="'$(BuildTestsAgainstPackages)' != 'true'">v4.5</TargetFrameworkVersion>
83 <IsXunitWrapperProject>true</IsXunitWrapperProject>
84 <SkipSigning>true</SkipSigning>
85 <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
86 <SolutionDir Condition="%24(SolutionDir) == '' Or %24(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
87 <CLRTestKind>BuildOnly</CLRTestKind>
88 <IsTestProject>true</IsTestProject>
89 <ProjectJson Condition="'$(BuildTestsAgainstPackages)' != 'true'">%24(TestWrappersPackagesConfigFileDirectory)project.json</ProjectJson>
90 <ProjectLockJson Condition="'$(BuildTestsAgainstPackages)' != 'true'">%24(TestWrappersPackagesConfigFileDirectory)project.lock.json</ProjectLockJson>
92 <!-- Default configurations to help VS understand the configurations -->
93 <PropertyGroup Condition=" '%24(Configuration)|%24(Platform)' == 'Debug|AnyCPU' ">
95 <PropertyGroup Condition=" '%24(Configuration)|%24(Platform)' == 'Release|AnyCPU' ">
98 <Compile Include="$(XunitWrapper).cs" />
101 <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
104 <ProjectReference Include="$(SourceDir)Common\Desktop.Coreclr.TestWrapper\Desktop.Coreclr.TestWrapper.csproj" Condition="'$(BuildTestsAgainstPackages)' != 'true'">
105 <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
108 <ProjectReference Include="$(SourceDir)Common\Coreclr.TestWrapper\Coreclr.TestWrapper.csproj" Condition="'$(BuildTestsAgainstPackages)' == 'true'">
109 <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
115 <Reference Include="System" />
116 <Reference Include="System.Runtime" />
117 <Reference Include="mscorlib" />
119 <Import Project="$(SourceDir)dir.targets" />
121 <OutDir>$(XunitTestBinBase)\$(CategoryWithSlash)\</OutDir>
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>$([System.String]::Copy('$(_CMDDIR)').Replace($(_CMDDIR_Grandparent)\,''))</CategoryWithSlash>
156 <Category>$([System.String]::Copy('$(CategoryWithSlash)').Replace('\','.'))</Category>
157 <XunitWrapper>$(Category).XUnitWrapper</XunitWrapper>
158 <XunitWrapperSrcDir>$(XunitWrapperGeneratedCSDirBase)$(Category)</XunitWrapperSrcDir>
159 <XunitWrapperOutputDir>$(XunitWrapperOutputIntermediatedDirBase)$(Category)</XunitWrapperOutputDir>
162 <_XunitProlog Condition=" '$(_XunitProlog)'=='' ">
166 using System.Collections.Generic%3B
167 using System.Diagnostics%3B
168 using System.Reflection%3B
169 using CoreclrTestLib%3B
171 namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").Replace("-","_"))
173 internal class _Global
175 internal static bool runningInWindows%3B
176 internal static string reportBase%3B
177 internal static string testBinaryBase%3B
178 internal static string coreRoot%3B
182 reportBase = System.Environment.GetEnvironmentVariable(%22XunitTestReportDirBase%22)%3B
183 testBinaryBase = System.IO.Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath)%3B
184 coreRoot = System.IO.Path.GetFullPath(System.Environment.GetEnvironmentVariable(%22CORE_ROOT%22))%3B
186 if (String.IsNullOrEmpty(reportBase)) {
187 reportBase = System.IO.Path.Combine(testBinaryBase, "Reports")%3B
191 reportBase = System.IO.Path.GetFullPath(reportBase)%3B
194 if (String.IsNullOrEmpty(coreRoot)) {
195 throw new ArgumentException("Environment variable CORE_ROOT is not set")%3B
198 string operatingSystem = System.Environment.GetEnvironmentVariable("OS")%3B
199 runningInWindows = (operatingSystem != null && operatingSystem.StartsWith("Windows"))%3B
206 <_XunitEpilog Condition=" '$(_XunitEpilog)'=='' ">
215 <CanonicalExcludeList Include="%(ExcludeList.FullPath)" Condition="$(HaveExcludes)"/>
219 <TestExecutableReplacement Condition="'$(RuntimeID)' != '' ">testExecutable = testExecutable.Replace("\\", "/")%3B</TestExecutableReplacement>
223 <AllCMDsPresent Include="$(_CMDDIR)\**\*.cmd" />
224 <AllCMDExcludeFilter Include="@(CanonicalExcludeList)" Condition="$(HaveExcludes)"/>
225 <AllCMDs Include="@(AllCMDsPresent)" Exclude="@(AllCMDExcludeFilter)"/>
227 <AllCommands Include="@(AllCMDs)" >
228 <_FactName>$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_").Replace("\","_").Replace("-","_"))</_FactName>
229 <_ClassName>$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace("cmd","").Replace(".","_").Replace("\","_").Replace("-","_"))</_ClassName>
234 public class %(AllCommands._ClassName)
237 public void %(AllCommands._FactName)()
240 string outputFile = null%3B
241 string errorFile = null%3B
242 string testExecutable = null%3B
243 Exception infraEx = null%3B
247 CoreclrTestWrapperLib wrapper = new CoreclrTestWrapperLib()%3B
248 string testSubfolder = @"\$(Category)\$([System.String]::Copy('%(AllCMDs.RelativeDir)').Replace("$(_CMDDIR)\",''))"%3B
249 outputFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).output.txt")%3B
250 errorFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).error.txt")%3B
251 testExecutable = System.IO.Path.GetFullPath(_Global.testBinaryBase + @"$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",''))")%3B
252 $(TestExecutableReplacement)
254 if (!_Global.runningInWindows) {
255 testExecutable = testExecutable.Replace(".cmd", ".sh")%3B
258 System.IO.Directory.CreateDirectory(_Global.reportBase + testSubfolder)%3B
260 ret = wrapper.RunTest(testExecutable, outputFile, errorFile)%3B
267 if (ret != CoreclrTestWrapperLib.EXIT_SUCCESS_CODE)
269 string sErrorText = null%3B
272 sErrorText = System.IO.File.ReadAllText(errorFile)%3B
276 sErrorText = "Unable to read error file: " + errorFile%3B
279 string outputText = null%3B
282 System.IO.StreamReader outputReader = new System.IO.StreamReader(outputFile)%3B
283 outputText = outputReader.ReadToEnd()%3B
284 outputReader.Close()%3B
288 outputText = "Unable to read output file: " + outputFile%3B
291 string msg = infraEx != null ? "Test Infrastructure Failure: " + infraEx.Message
292 : sErrorText + "\n\n" +
293 "Return code: " + ret + "\n" +
294 "Raw output file: " + outputFile + "\n" +
295 "Raw output:\n" + outputText + "\n" +
296 "To run the test:\n" +
297 "> set CORE_ROOT=" + _Global.coreRoot + "\n" +
298 "> " + testExecutable + "\n"%3B
300 Assert.True(ret == CoreclrTestWrapperLib.EXIT_SUCCESS_CODE, msg)%3B
308 <AllXUnitFacts Include= "%(AllCommands._XunitFact)" />
313 <Target Name="CreateAllWrappers" DependsOnTargets="GetListOfTestCmds;FindCmdDirectories">
314 <MSBuild Projects="$(MSBuildProjectFile)" Targets="CreateXunitWrapper;BuildXunitWrapper" Properties="_CMDDIR=%(TestDirectories.Identity)" />
317 <Target Name="GetListOfTestCmds">
319 <AllRunnableTestPaths Include="$(XunitTestBinBase)\**\*.cmd" />
323 <Import Project="tests.targets" />
324 <Import Project="publishdependency.targets" />
326 <Target Name="CreateTestOverlay">
327 <MSBuild Projects="$(MSBuildProjectFile)"
328 Targets="CopyDependecyToCoreRoot"
329 Properties="Language=C#" />
332 <Target Name="CreateNonWindowsTestOverlay">
333 <MSBuild Projects="$(MSBuildProjectFile)"
334 Targets="CopyNonWindowsDependecyToCoreRoot"
335 Properties="Language=C#;NonWindowsRuntimeId=$(NonWindowsRuntimeId)" />
338 <Target Name="BinPlaceRef">
339 <!-- Copy mscorlib.dll from TargetingPack to bin/Product/ref, if we're building against packages -->
340 <MSBuild Projects="$(MSBuildProjectFile)"
341 Targets="CopyDependencyToRef"
342 Properties="Language=C#"
343 Condition=" '$(BuildTestsAgainstPackages)'=='true' " />
346 <Target Name="BinPlaceProduct">
347 <!-- Copy test dependencies to bin/Product, if we're building against packages -->
348 <MSBuild Projects="$(MSBuildProjectFile)"
349 Targets="CopyDependencyToProduct"
350 Properties="Language=C#"
351 Condition=" '$(BuildTestsAgainstPackages)'=='true' " />
354 <!-- All the test projects need to add dependency to currently built runtime as they require that to run.
355 In addition the version number of built runtime can change so all project.json needs to be dynamically generated.
356 Instead the following task creates a project.json with dependencies like Microsoft.netcore.runtime.coreclr ..etc.
358 <Target Name="CreateTestRuntimeJsonFile">
360 <CoreclrPackage Include="$(CORE_ROOT)\.nuget\**\Microsoft.NETCore.Runtime.CoreCLR.*.nupkg"/>
363 <CoreclrPackageFileName>%(CoreclrPackage.Filename)</CoreclrPackageFileName>
364 <!-- Get package version number from nuget package filename at core_root -->
365 <CoreClrPackageVersion Condition="'$(BuildTestsAgainstPackages)'!='true'">$([System.String]::Copy('$(CoreclrPackageFileName)').Replace('Microsoft.NETCore.Runtime.CoreCLR.',''))</CoreClrPackageVersion>
366 <TestRuntimeJsonContents>
370 "Microsoft.NETCore.Runtime.CoreCLR": "$(CoreClrPackageVersion)",
371 "Microsoft.NETCore.TestHost": "1.0.0-rc3-24117-00"
377 "$(TestNugetRuntimeId)":{}
382 </TestRuntimeJsonContents>
385 <MakeDir Directories="$(TestRuntimeProjectJsonDir)" Condition="!Exists('$(TestRuntimeProjectJsonDir)')" />
387 <!-- Write the file -->
389 File="$(TestRuntimeProjectJson)"
390 Lines="$(TestRuntimeJsonContents)"
395 <Target Name="RunPerfTests" Condition="'$(Performance)'=='true'">
396 <Message Text="Executing steps for perf tests" Importance="High"/>
398 <!-- generate project.json for runtime dependency -->
399 <MSBuild Projects="$(MSBuildProjectFile)"
400 Targets="CreateTestRuntimeJsonFile"/>
402 <!-- generate project.lock.json file corresponding to above json file -->
403 <MSBuild Projects="src\Common\test_dependencies\test_dependencies.csproj"/>
405 <!-- Package each perf test, upload it and trigger event to execute the tests -->
406 <MSBuild Projects="$(MSBuildProjectFile)" Targets="UploadPerfAssemblies" />
410 <Target Name="Build">
412 <!-- generate project.json for runtime dependency -->
413 <MSBuild Projects="$(MSBuildProjectFile)"
414 Targets="CreateTestRuntimeJsonFile"
415 Condition=" '$(BuildWrappers)'=='true' " />
417 <!-- generate project.lock.json file corresponding to above json file -->
418 <MSBuild Projects="src\Common\test_dependencies\test_dependencies.csproj"
419 Condition=" '$(BuildWrappers)'=='true' " />
421 <!-- Default for building -->
422 <MSBuild Projects="$(MSBuildProjectFile)"
423 Targets="CreateAllWrappers"
424 Properties="_CMDDIR=%(TestDirectories.Identity)"
425 Condition=" '$(BuildWrappers)'=='true' " />
429 <MSBuild Projects="$(MSBuildProjectFile)"
430 Targets="CreateTestOverlay"
431 Condition=" '$(GenerateRuntimeLayout)'=='true' "/>
433 <MSBuild Projects="$(MSBuildProjectFile)" Targets="RunTests"
434 Condition=" '$(RunTests)'=='true' "/>
437 <Target Name="Clean">
438 <RemoveDir Condition=" '$(BuildWrappers)'=='true'" Directories="$(XunitWrapperGeneratedCSDirBase);$(XunitWrapperOutputIntermediatedDirBase)" ContinueOnError="WarnAndContinue" />