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 <Path>$([System.IO.Path]::GetFullPath(%(AllRunnableTestPaths.Identity)))</Path>
34 </NonExcludedTestDirectories>
35 <TestDirectoriesWithDup Include="@(NonExcludedTestDirectories -> '%(Identity)')" Condition="$([System.String]::new('%(Path)').StartsWith('%(Identity)'))" />
39 <RemoveDuplicates Inputs="@(TestDirectoriesWithDup)">
41 TaskParameter="Filtered"
42 ItemName="TestDirectories"/>
48 <Import Project="$(__Exclude0)" Condition="'$(__Exclude0)' != '' AND '$(XunitTestBinBase)' != ''" />
49 <Import Project="$(__Exclude)" Condition="'$(__Exclude)' != '' AND '$(XunitTestBinBase)' != ''" />
51 <HaveExcludes>False</HaveExcludes>
52 <HaveExcludes Condition="('$(__Exclude0)' != '') Or ('$(__Exclude)' != '')">True</HaveExcludes>
55 <Target Name="CreateXunitWrapper" DependsOnTargets="CreateXunitFacts">
67 <XunitVersionCompiled>2.1.0</XunitVersionCompiled>
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>.NETFramework</TargetFrameworkIdentifier>
82 <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
83 <IsXunitWrapperProject>true</IsXunitWrapperProject>
84 <SkipSigning>true</SkipSigning>
85 <AppDesignerFolder>Properties</AppDesignerFolder>
86 <FileAlignment>512</FileAlignment>
87 <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
88 <SolutionDir Condition="%24(SolutionDir) == '' Or %24(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
89 <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
90 <CLRTestKind>BuildOnly</CLRTestKind>
91 <IsTestProject>true</IsTestProject>
93 <!-- Default configurations to help VS understand the configurations -->
94 <PropertyGroup Condition=" '%24(Configuration)|%24(Platform)' == 'Debug|AnyCPU' ">
96 <PropertyGroup Condition=" '%24(Configuration)|%24(Platform)' == 'Release|AnyCPU' ">
99 <Compile Include="$(XunitWrapper).cs" />
102 <None Include="%24(TestWrappersPackagesConfigFileDirectory)project.json" />
105 <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
108 <ProjectReference Include="$(SourceDir)Common\Desktop.Coreclr.TestWrapper\Desktop.Coreclr.TestWrapper.csproj">
109 <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
115 <Reference Include="System" />
116 <Reference Include="System.Runtime" />
117 <Reference Include="mscorlib" />
120 <ProjectJson>%24(TestWrappersPackagesConfigFileDirectory)project.json</ProjectJson>
121 <ProjectLockJson>%24(TestWrappersPackagesConfigFileDirectory)project.lock.json</ProjectLockJson>
123 <Import Project="$(SourceDir)dir.targets" />
124 <Import Project="$(ProjectDir)helix.targets" />
126 <OutDir>$(XunitTestBinBase)\$(Category)\</OutDir>
130 </XunitWrapperGenCsProj>
134 <!-- <Exec Command="md" -->
135 <MakeDir Directories="$(XunitWrapperGeneratedCSDirBase)$(Category)"/>
137 <!-- Write the file -->
139 File="$(XunitWrapperSrcDir)\$(XunitWrapper).cs"
140 Lines="$(_XunitWrapperGen)"
143 <!-- Write the file -->
145 File="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj"
146 Lines="$(XunitWrapperGenCsProj)"
150 <Target Name="BuildXunitWrapper">
151 <MSBuild Projects="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj"
152 Properties="RestorePackages=false"/>
155 <Target Name="CreateXunitFacts">
156 <!-- NOTE! semicolons must be escaped with %3B boooo -->
159 <_CMDDIR_Parent>$([System.IO.Path]::GetDirectoryName($(_CMDDIR)))</_CMDDIR_Parent>
160 <Category>$([System.String]::Copy('$(_CMDDIR)').Replace($(_CMDDIR_Parent)\,''))</Category>
161 <XunitWrapper>$(Category).XUnitWrapper</XunitWrapper>
162 <XunitWrapperSrcDir>$(XunitWrapperGeneratedCSDirBase)$(Category)</XunitWrapperSrcDir>
163 <XunitWrapperOutputDir>$(XunitWrapperOutputIntermediatedDirBase)$(Category)</XunitWrapperOutputDir>
166 <_XunitProlog Condition=" '$(_XunitProlog)'=='' ">
170 using System.Collections.Generic%3B
171 using System.Diagnostics%3B
172 using System.Reflection%3B
173 using CoreclrTestLib%3B
175 namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").Replace("-","_"))
177 internal class _Global
179 internal static bool runningInWindows%3B
180 internal static string reportBase%3B
181 internal static string testBinaryBase%3B
182 internal static string coreRoot%3B
186 reportBase = System.Environment.GetEnvironmentVariable(%22XunitTestReportDirBase%22)%3B
187 testBinaryBase = System.IO.Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath)%3B
188 coreRoot = System.IO.Path.GetFullPath(System.Environment.GetEnvironmentVariable(%22CORE_ROOT%22))%3B
190 if (String.IsNullOrEmpty(reportBase)) {
191 reportBase = System.IO.Path.Combine(testBinaryBase, "Reports")%3B
195 reportBase = System.IO.Path.GetFullPath(reportBase)%3B
198 if (String.IsNullOrEmpty(coreRoot)) {
199 throw new ArgumentException("Environment variable CORE_ROOT is not set")%3B
202 runningInWindows = System.Environment.GetEnvironmentVariable("OS").StartsWith("Windows")%3B
209 <_XunitEpilog Condition=" '$(_XunitEpilog)'=='' ">
218 <CanonicalExcludeList Include="%(ExcludeList.FullPath)" Condition="$(HaveExcludes)"/>
222 <AllCMDsPresent Include="$(_CMDDIR)\**\*.cmd" />
223 <AllCMDExcludeFilter Include="@(CanonicalExcludeList)" Condition="$(HaveExcludes)"/>
224 <AllCMDs Include="@(AllCMDsPresent)" Exclude="@(AllCMDExcludeFilter)"/>
226 <AllCommands Include="@(AllCMDs)" >
227 <_FactName>$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_").Replace("\","_").Replace("-","_"))</_FactName>
228 <_ClassName>$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace("cmd","").Replace(".","_").Replace("\","_").Replace("-","_"))</_ClassName>
233 public class %(AllCommands._ClassName)
236 public void %(AllCommands._FactName)()
239 string outputFile = null%3B
240 string errorFile = null%3B
241 string testExecutable = null%3B
242 Exception infraEx = null%3B
246 CoreclrTestWrapperLib wrapper = new CoreclrTestWrapperLib()%3B
247 string testSubfolder = @"\$(Category)\$([System.String]::Copy('%(AllCMDs.RelativeDir)').Replace("$(_CMDDIR)\",''))"%3B
248 outputFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).output.txt")%3B
249 errorFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).error.txt")%3B
250 testExecutable = System.IO.Path.GetFullPath(_Global.testBinaryBase + @"$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",''))")%3B
252 if (!_Global.runningInWindows) {
253 testExecutable = testExecutable.Replace(".cmd", ".sh")%3B
256 System.IO.Directory.CreateDirectory(_Global.reportBase + testSubfolder)%3B
258 ret = wrapper.RunTest(testExecutable, outputFile, errorFile)%3B
265 if (ret != CoreclrTestWrapperLib.EXIT_SUCCESS_CODE)
267 string sErrorText = null%3B
270 sErrorText = System.IO.File.ReadAllText(errorFile)%3B
274 sErrorText = "Unable to read error file: " + errorFile%3B
277 string outputText = null%3B
280 System.IO.StreamReader outputReader = new System.IO.StreamReader(outputFile)%3B
281 outputText = outputReader.ReadToEnd()%3B
282 outputReader.Close()%3B
286 outputText = "Unable to read output file: " + outputFile%3B
289 string msg = infraEx != null ? "Test Infrastructure Failure: " + infraEx.Message
290 : sErrorText + "\n\n" +
291 "Return code: " + ret + "\n" +
292 "Raw output file: " + outputFile + "\n" +
293 "Raw output:\n" + outputText + "\n" +
294 "To run the test:\n" +
295 "> set CORE_ROOT=" + _Global.coreRoot + "\n" +
296 "> " + testExecutable + "\n"%3B
298 Assert.True(ret == CoreclrTestWrapperLib.EXIT_SUCCESS_CODE, msg)%3B
306 <AllXUnitFacts Include= "%(AllCommands._XunitFact)" />
311 <Target Name="CreateAllWrappers" DependsOnTargets="GetListOfTestCmds;FindCmdDirectories">
312 <MSBuild Projects="$(MSBuildProjectFile)" Targets="CreateXunitWrapper" Properties="_CMDDIR=%(TestDirectories.Identity)" />
315 Contents of a project.json that will be restored once with errors turned off. This works
316 around the package being incompatible with dotnet restore. Only the package contents are
317 required so the compatibility errors can be ignored.
320 <XunitRunnerRestoreGenConfig>{ "dependencies": { "xunit.runner.msbuild": "$(XunitPackageVersion)" }, "frameworks": { "net45": {} } }</XunitRunnerRestoreGenConfig>
321 <XunitRunnerRestoreProjectDir>$(BaseOutputPath)\tempRestoreProject</XunitRunnerRestoreProjectDir>
322 <XunitRunnerRestoreProjectJsonPath>$(XunitRunnerRestoreProjectDir)\project.json</XunitRunnerRestoreProjectJsonPath>
325 <MakeDir Directories="$(XunitRunnerRestoreProjectDir)" />
326 <WriteLinesToFile File="$(XunitRunnerRestoreProjectJsonPath)"
327 Lines="$(XunitRunnerRestoreGenConfig)"
330 <Exec Command="$(DnuRestoreCommand) "$(XunitRunnerRestoreProjectJsonPath)""
331 StandardOutputImportance="Low"
332 CustomErrorRegularExpression="^Unable to resolve .*"
333 IgnoreExitCode="true"
334 IgnoreStandardErrorWarningFormat="true" />
336 <MSBuild Projects="$(MSBuildProjectFile)" Targets="BuildXunitWrapper" Properties="_CMDDIR=%(TestDirectories.Identity)" />
339 <Target Name="GetListOfTestCmds">
341 <AllRunnableTestPaths Include="$(XunitTestBinBase)\**\*.cmd" />
345 <Import Project="tests.targets" />
346 <Import Project="publishdependency.targets" />
348 <Target Name="CreateTestOverlay">
349 <MSBuild Projects="$(MSBuildProjectFile)"
350 Targets="CopyDependecyToCoreRoot"
351 Properties="Language=C#" />
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 In order to avoid regenerating project.json for all the tests projects...I added a common project for all the tests.
357 This project is at tests\src\common\test_runtime\test_runtime.csproj. This project is adding common dependencies to
358 all the tests like dependency on Microsoft.netcore.runtime.coreclr ..etc. Project.json for this project is dynamically
359 generated via task CreateTestRuntimeJsonFile. -->
360 <Target Name="CreateTestRuntimeJsonFile">
362 <CoreclrPackage Include="$(CORE_ROOT)\.nuget\**\Microsoft.NETCore.Runtime.CoreCLR.*.nupkg"/>
365 <CoreclrPackageFileName>%(CoreclrPackage.Filename)</CoreclrPackageFileName>
366 <!-- Get package version number from nuget package filename at core_root -->
367 <CoreClrPackageVersion Condition="'$(BuildTestsAgainstPackages)'!='true'">$([System.String]::Copy('$(CoreclrPackageFileName)').Replace('Microsoft.NETCore.Runtime.CoreCLR.',''))</CoreClrPackageVersion>
368 <TestRuntimeJsonContents>
372 "Microsoft.NETCore.Runtime.CoreCLR": "$(CoreClrPackageVersion)",
373 "Microsoft.NETCore.TestHost": "1.0.0-rc3-24117-00"
379 "$(TestNugetRuntimeId)":{}
384 </TestRuntimeJsonContents>
387 <MakeDir Directories="$(TestRuntimeProjectJsonDir)" Condition="!Exists('$(TestRuntimeProjectJsonDir)')" />
389 <!-- Write the file -->
391 File="$(TestRuntimeProjectJson)"
392 Lines="$(TestRuntimeJsonContents)"
397 <Target Name="RunPerfTests" Condition="'$(Performance)'=='true'">
398 <Message Text="Executing steps for perf tests" Importance="High"/>
400 <!-- generate project.json for runtime dependency -->
401 <MSBuild Projects="$(MSBuildProjectFile)"
402 Targets="CreateTestRuntimeJsonFile"/>
404 <!-- generate project.lock.json file corresponding to above json file -->
405 <MSBuild Projects="src\Common\test_runtime\test_runtime.csproj"/>
407 <!-- Package each perf test, upload it and trigger event to execute the tests -->
408 <MSBuild Projects="$(MSBuildProjectFile)" Targets="UploadPerfAssemblies" />
412 <Target Name="Build">
414 <!-- generate project.json for runtime dependency -->
415 <MSBuild Projects="$(MSBuildProjectFile)"
416 Targets="CreateTestRuntimeJsonFile"
417 Condition=" '$(BuildWrappers)'=='true' " />
419 <!-- generate project.lock.json file corresponding to above json file -->
420 <MSBuild Projects="src\Common\test_runtime\test_runtime.csproj"
421 Condition=" '$(BuildWrappers)'=='true' " />
423 <!-- Default for building -->
424 <MSBuild Projects="$(MSBuildProjectFile)"
425 Targets="CreateAllWrappers"
426 Properties="_CMDDIR=%(TestDirectories.Identity)"
427 Condition=" '$(BuildWrappers)'=='true' " />
431 <MSBuild Projects="$(MSBuildProjectFile)"
432 Targets="CreateTestOverlay"
433 Condition=" '$(GenerateRuntimeLayout)'=='true' "/>
435 <MSBuild Projects="$(MSBuildProjectFile)" Targets="RunTests"
436 Condition=" '$(RunTests)'=='true' "/>
439 <Target Name="Clean">
440 <RemoveDir Condition=" '$(BuildWrappers)'=='true'" Directories="$(XunitWrapperGeneratedCSDirBase);$(XunitWrapperOutputIntermediatedDirBase)" ContinueOnError="WarnAndContinue" />