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="FindCmdDirectories" DependsOnTargets="GetListOfTestCmds">
20 <Error Condition="!Exists('$(XunitTestBinBase)')"
21 Text="$(XunitTestBinBase) does not exist. Please run buildtest.cmd from the (repo root)\tests at least once to get the tests built." />
25 <AllTestDirsNonCanonicalPaths Include="$([System.IO.Directory]::GetDirectories(`$(XunitTestBinBase)`))" />
26 <AllTestDirsPaths Include="@(AllTestDirsNonCanonicalPaths)" />
27 <AllTestDirsPaths Include="@(AllTestDirsNonCanonicalPaths)" >
28 <Path>$([System.IO.Path]::GetFullPath(%(Identity)))</Path>
30 <NonExcludedTestDirectories Include="@(AllTestDirsPaths -> '%(Path)')" Exclude="@(_SkipTestDir -> '$(XunitTestBinBase)%(Identity)')">
31 <Path>$([System.IO.Path]::GetFullPath(%(AllRunnableTestPaths.Identity)))</Path>
32 </NonExcludedTestDirectories>
33 <TestDirectoriesWithDup Include="@(NonExcludedTestDirectories -> '%(Identity)')" Condition="$([System.String]::new('%(Path)').StartsWith('%(Identity)'))" />
37 <RemoveDuplicates Inputs="@(TestDirectoriesWithDup)">
39 TaskParameter="Filtered"
40 ItemName="TestDirectories"/>
46 <Import Project="$(__Exclude0)" Condition="'$(__Exclude0)' != '' AND '$(XunitTestBinBase)' != ''" />
47 <Import Project="$(__Exclude)" Condition="'$(__Exclude)' != '' AND '$(XunitTestBinBase)' != ''" />
49 <HaveExcludes>False</HaveExcludes>
50 <HaveExcludes Condition="('$(__Exclude0)' != '') Or ('$(__Exclude)' != '')">True</HaveExcludes>
53 <Target Name="CreateXunitWrapper" DependsOnTargets="CreateXunitFacts">
65 <XunitVersionCompiled>2.1.0</XunitVersionCompiled>
66 <XunitWrapperGenCsProj>
68 <?xml version="1.0" encoding="utf-8"?>
69 <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
71 <Import Project="$(SourceDir)dir.props" />
73 <Configuration Condition=" '%24(Configuration)' == '' ">Debug</Configuration>
74 <Platform Condition=" '%24(Platform)' == '' ">AnyCPU</Platform>
75 <AssemblyName>$(XunitWrapper)</AssemblyName>
76 <SchemaVersion>2.0</SchemaVersion>
77 <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
78 <OutputType>Library</OutputType>
79 <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
80 <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
81 <IsXunitWrapperProject>true</IsXunitWrapperProject>
82 <SkipSigning>true</SkipSigning>
83 <AppDesignerFolder>Properties</AppDesignerFolder>
84 <FileAlignment>512</FileAlignment>
85 <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
86 <SolutionDir Condition="%24(SolutionDir) == '' Or %24(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
87 <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
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 <None Include="%24(TestWrappersPackagesConfigFileDirectory)project.json" />
103 <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
106 <ProjectReference Include="$(SourceDir)Common\Desktop.Coreclr.TestWrapper\Desktop.Coreclr.TestWrapper.csproj">
107 <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
113 <Reference Include="System" />
114 <Reference Include="System.Runtime" />
115 <Reference Include="mscorlib" />
118 <ProjectJson>%24(TestWrappersPackagesConfigFileDirectory)project.json</ProjectJson>
119 <ProjectLockJson>%24(TestWrappersPackagesConfigFileDirectory)project.lock.json</ProjectLockJson>
121 <Import Project="$(SourceDir)dir.targets" />
122 <Import Project="$(ProjectDir)helix.targets" />
124 <OutDir>$(XunitTestBinBase)\$(Category)\</OutDir>
128 </XunitWrapperGenCsProj>
132 <!-- <Exec Command="md" -->
133 <MakeDir Directories="$(XunitWrapperGeneratedCSDirBase)$(Category)"/>
135 <!-- Write the file -->
137 File="$(XunitWrapperSrcDir)\$(XunitWrapper).cs"
138 Lines="$(_XunitWrapperGen)"
141 <!-- Write the file -->
143 File="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj"
144 Lines="$(XunitWrapperGenCsProj)"
148 <Target Name="BuildXunitWrapper">
149 <MSBuild Projects="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj"
150 Properties="RestorePackages=false"/>
153 <Target Name="CreateXunitFacts">
154 <!-- NOTE! semicolons must be escaped with %3B boooo -->
157 <_CMDDIR_Parent>$([System.IO.Path]::GetDirectoryName($(_CMDDIR)))</_CMDDIR_Parent>
158 <Category>$([System.String]::Copy('$(_CMDDIR)').Replace($(_CMDDIR_Parent)\,''))</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 runningInWindows = System.Environment.GetEnvironmentVariable("OS").StartsWith("Windows")%3B
207 <_XunitEpilog Condition=" '$(_XunitEpilog)'=='' ">
216 <CanonicalExcludeList Include="%(ExcludeList.FullPath)" Condition="$(HaveExcludes)"/>
220 <AllCMDsPresent Include="$(_CMDDIR)\**\*.cmd" />
221 <AllCMDExcludeFilter Include="@(CanonicalExcludeList)" Condition="$(HaveExcludes)"/>
222 <AllCMDs Include="@(AllCMDsPresent)" Exclude="@(AllCMDExcludeFilter)"/>
224 <AllCommands Include="@(AllCMDs)" >
225 <_FactName>$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_").Replace("\","_").Replace("-","_"))</_FactName>
226 <_ClassName>$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace("cmd","").Replace(".","_").Replace("\","_").Replace("-","_"))</_ClassName>
231 public class %(AllCommands._ClassName)
234 public void %(AllCommands._FactName)()
237 string outputFile = null%3B
238 string errorFile = null%3B
239 string testExecutable = null%3B
240 Exception infraEx = null%3B
244 CoreclrTestWrapperLib wrapper = new CoreclrTestWrapperLib()%3B
245 string testSubfolder = @"\$(Category)\$([System.String]::Copy('%(AllCMDs.RelativeDir)').Replace("$(_CMDDIR)\",''))"%3B
246 outputFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).output.txt")%3B
247 errorFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).error.txt")%3B
248 testExecutable = System.IO.Path.GetFullPath(_Global.testBinaryBase + @"$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",''))")%3B
250 if (!_Global.runningInWindows) {
251 testExecutable = testExecutable.Replace(".cmd", ".sh")%3B
254 System.IO.Directory.CreateDirectory(_Global.reportBase + testSubfolder)%3B
256 ret = wrapper.RunTest(testExecutable, outputFile, errorFile)%3B
263 if (ret != CoreclrTestWrapperLib.EXIT_SUCCESS_CODE)
265 string sErrorText = null%3B
268 sErrorText = System.IO.File.ReadAllText(errorFile)%3B
272 sErrorText = "Unable to read error file: " + errorFile%3B
275 string outputText = null%3B
278 System.IO.StreamReader outputReader = new System.IO.StreamReader(outputFile)%3B
279 outputText = outputReader.ReadToEnd()%3B
280 outputReader.Close()%3B
284 outputText = "Unable to read output file: " + outputFile%3B
287 string msg = infraEx != null ? "Test Infrastructure Failure: " + infraEx.Message
288 : sErrorText + "\n\n" +
289 "Return code: " + ret + "\n" +
290 "Raw output file: " + outputFile + "\n" +
291 "Raw output:\n" + outputText + "\n" +
292 "To run the test:\n" +
293 "> set CORE_ROOT=" + _Global.coreRoot + "\n" +
294 "> " + testExecutable + "\n"%3B
296 Assert.True(ret == CoreclrTestWrapperLib.EXIT_SUCCESS_CODE, msg)%3B
304 <AllXUnitFacts Include= "%(AllCommands._XunitFact)" />
309 <Target Name="CreateAllWrappers" DependsOnTargets="GetListOfTestCmds;FindCmdDirectories">
310 <MSBuild Projects="$(MSBuildProjectFile)" Targets="CreateXunitWrapper" Properties="_CMDDIR=%(TestDirectories.Identity)" />
313 Contents of a project.json that will be restored once with errors turned off. This works
314 around the package being incompatible with dotnet restore. Only the package contents are
315 required so the compatibility errors can be ignored.
318 <XunitRunnerRestoreGenConfig>{ "dependencies": { "xunit.runner.msbuild": "$(XunitPackageVersion)" }, "frameworks": { "net45": {} } }</XunitRunnerRestoreGenConfig>
319 <XunitRunnerRestoreProjectDir>$(BaseOutputPath)\tempRestoreProject</XunitRunnerRestoreProjectDir>
320 <XunitRunnerRestoreProjectJsonPath>$(XunitRunnerRestoreProjectDir)\project.json</XunitRunnerRestoreProjectJsonPath>
323 <MakeDir Directories="$(XunitRunnerRestoreProjectDir)" />
324 <WriteLinesToFile File="$(XunitRunnerRestoreProjectJsonPath)"
325 Lines="$(XunitRunnerRestoreGenConfig)"
328 <Exec Command="$(DnuRestoreCommand) "$(XunitRunnerRestoreProjectJsonPath)""
329 StandardOutputImportance="Low"
330 CustomErrorRegularExpression="^Unable to resolve .*"
331 IgnoreExitCode="true"
332 IgnoreStandardErrorWarningFormat="true" />
334 <MSBuild Projects="$(MSBuildProjectFile)" Targets="BuildXunitWrapper" Properties="_CMDDIR=%(TestDirectories.Identity)" />
337 <Target Name="GetListOfTestCmds">
339 <AllRunnableTestPaths Include="$(XunitTestBinBase)\**\*.cmd" />
343 <Import Project="tests.targets" />
344 <Import Project="publishdependency.targets" />
346 <Target Name="CreateTestOverlay">
347 <MSBuild Projects="$(MSBuildProjectFile)"
348 Targets="CopyDependecyToCoreRoot"
349 Properties="Language=C#" />
352 <!-- All the test projects need to add dependency to currently built runtime as they require that to run.
353 In addition the version number of built runtime can change so all project.json needs to be dynamically generated.
354 In order to avoid regenerating project.json for all the tests projects...I added a common project for all the tests.
355 This project is at tests\src\common\test_runtime\test_runtime.csproj. This project is adding common dependencies to
356 all the tests like dependency on Microsoft.netcore.runtime.coreclr ..etc. Project.json for this project is dynamically
357 generated via task CreateTestRuntimeJsonFile. -->
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>$([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_runtime\test_runtime.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_runtime\test_runtime.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" />