Merge pull request #11054 from wtgodbe/spacing
[platform/upstream/coreclr.git] / tests / runtest.proj
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'"/> 
6   <PropertyGroup>
7     <XunitTestBinBase Condition="'$(XunitTestBinBase)'==''" >$(BaseOutputPathWithConfig)</XunitTestBinBase>
8     <XunitWrapperGeneratedCSDirBase>$(XunitTestBinBase)\TestWrappers\</XunitWrapperGeneratedCSDirBase>
9     <XunitWrapperOutputIntermediatedDirBase>$(XunitTestBinBase)\Tests\</XunitWrapperOutputIntermediatedDirBase>
10     <MSBuildEnableAllPropertyFunctions>1</MSBuildEnableAllPropertyFunctions>
11   </PropertyGroup>
12
13   <ItemGroup>
14     <DisabledTestDir Include="Common" />
15     <_SkipTestDir Include="@(DisabledTestDir)" />
16   </ItemGroup>
17
18   <Target Name="Rebuild" />
19
20   <Target Name="FindCmdDirectories" DependsOnTargets="GetListOfTestCmds">
21
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." />
24
25     <ItemGroup>
26
27       <AllTestDirsNonCanonicalPaths Include="$([System.IO.Directory]::GetDirectories(`$(XunitTestBinBase)`))" />
28       <AllTestDirsPaths Include="@(AllTestDirsNonCanonicalPaths)" />
29       <AllTestDirsPaths Include="@(AllTestDirsNonCanonicalPaths)" >
30         <Path>$([System.IO.Path]::GetFullPath(%(Identity)))</Path>
31       </AllTestDirsPaths>
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)'))" />
39
40     </ItemGroup>
41
42     <RemoveDuplicates Inputs="@(TestDirectoriesWithDup)">
43       <Output
44           TaskParameter="Filtered"
45           ItemName="TestDirectories"/>
46     </RemoveDuplicates>
47
48   </Target>
49
50   <Import Project="$(__Exclude)" Condition="'$(__Exclude)' != '' AND '$(XunitTestBinBase)' != ''" /> 
51   <PropertyGroup>
52     <HaveExcludes>False</HaveExcludes>
53     <HaveExcludes Condition="'$(__Exclude)' != ''">True</HaveExcludes>
54   </PropertyGroup>
55
56   <Target Name="CreateXunitWrapper" DependsOnTargets="CreateXunitFacts">
57
58     <PropertyGroup>
59       <_XunitWrapperGen >
60         <![CDATA[
61         
62 $(_XunitProlog)
63 @(AllXUnitFacts)
64 $(_XunitEpilog)
65
66 ]]>
67       </_XunitWrapperGen>
68       <XunitWrapperGenCsProj>
69         <![CDATA[
70 <?xml version="1.0" encoding="utf-8"?>
71 <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
72     
73   <Import Project="$(SourceDir)dir.props" />
74   <PropertyGroup>
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>
91   </PropertyGroup>
92   <!-- Default configurations to help VS understand the configurations -->
93   <PropertyGroup Condition=" '%24(Configuration)|%24(Platform)' == 'Debug|AnyCPU' ">
94   </PropertyGroup>
95   <PropertyGroup Condition=" '%24(Configuration)|%24(Platform)' == 'Release|AnyCPU' ">
96   </PropertyGroup>
97   <ItemGroup>
98     <Compile Include="$(XunitWrapper).cs" />
99   </ItemGroup>
100   <ItemGroup>
101     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
102   </ItemGroup>
103    <ItemGroup>
104     <ProjectReference Include="$(SourceDir)Common\Desktop.Coreclr.TestWrapper\Desktop.Coreclr.TestWrapper.csproj" Condition="'$(BuildTestsAgainstPackages)' != 'true'">
105       <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
106       <Name>coreclr</Name>
107     </ProjectReference>
108     <ProjectReference Include="$(SourceDir)Common\Coreclr.TestWrapper\Coreclr.TestWrapper.csproj" Condition="'$(BuildTestsAgainstPackages)' == 'true'">
109       <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
110       <Name>coreclr</Name>
111     </ProjectReference>
112   </ItemGroup>
113  
114   <ItemGroup>
115     <Reference Include="System" />
116     <Reference Include="System.Runtime" />
117     <Reference Include="mscorlib" />
118   </ItemGroup>
119   <Import Project="$(SourceDir)dir.targets" />
120   <PropertyGroup>
121      <OutDir>$(XunitTestBinBase)\$(CategoryWithSlash)\</OutDir>
122   </PropertyGroup>
123 </Project>
124         ]]>
125       </XunitWrapperGenCsProj>
126
127     </PropertyGroup>
128
129     <!-- <Exec Command="md" -->
130     <MakeDir  Directories="$(XunitWrapperGeneratedCSDirBase)$(Category)"/>
131
132     <!-- Write the file -->
133     <WriteLinesToFile
134       File="$(XunitWrapperSrcDir)\$(XunitWrapper).cs"
135       Lines="$(_XunitWrapperGen)"
136       Overwrite="true" />
137
138     <!-- Write the file -->
139     <WriteLinesToFile
140       File="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj"
141       Lines="$(XunitWrapperGenCsProj)"
142       Overwrite="true" />
143   </Target>
144   
145   <Target Name="BuildXunitWrapper">
146     <MSBuild Projects="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj"/>
147   </Target>
148
149   <Target Name="CreateXunitFacts">
150     <!-- NOTE! semicolons must be escaped with %3B boooo -->
151
152     <PropertyGroup>
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>
160     </PropertyGroup>
161     <PropertyGroup>
162       <_XunitProlog Condition=" '$(_XunitProlog)'=='' ">
163         <![CDATA[
164 using Xunit%3B
165 using System%3B
166 using System.Collections.Generic%3B
167 using System.Diagnostics%3B
168 using System.Reflection%3B
169 using CoreclrTestLib%3B
170
171 namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").Replace("-","_"))
172 {
173         internal class _Global
174         {
175             internal static bool runningInWindows%3B
176             internal static string reportBase%3B
177             internal static string testBinaryBase%3B
178             internal static string coreRoot%3B
179
180             static _Global()
181             {
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
185
186                 if (String.IsNullOrEmpty(reportBase)) {
187                     reportBase = System.IO.Path.Combine(testBinaryBase, "Reports")%3B
188                 }
189                 else
190                 {
191                     reportBase = System.IO.Path.GetFullPath(reportBase)%3B
192                 }
193
194                 if (String.IsNullOrEmpty(coreRoot)) {
195                     throw new ArgumentException("Environment variable CORE_ROOT is not set")%3B
196                 }
197
198                 string operatingSystem = System.Environment.GetEnvironmentVariable("OS")%3B
199                 runningInWindows = (operatingSystem != null && operatingSystem.StartsWith("Windows"))%3B
200             }
201         }
202
203 ]]>
204       </_XunitProlog>
205
206       <_XunitEpilog Condition=" '$(_XunitEpilog)'=='' ">
207       <![CDATA[
208 }
209
210 ]]>
211       </_XunitEpilog>
212     </PropertyGroup>
213
214     <ItemGroup>
215       <CanonicalExcludeList Include="%(ExcludeList.FullPath)" Condition="$(HaveExcludes)"/>
216     </ItemGroup>
217
218     <PropertyGroup>
219       <TestExecutableReplacement Condition="'$(TargetsWindows)' != 'true' ">testExecutable = testExecutable.Replace("\\", "/")%3B</TestExecutableReplacement>
220     </PropertyGroup>
221
222     <ItemGroup>
223       <AllCMDsPresent Include="$(_CMDDIR)\**\*.cmd" />
224       <AllCMDExcludeFilter Include="@(CanonicalExcludeList)" Condition="$(HaveExcludes)"/>
225       <AllCMDs Include="@(AllCMDsPresent)" Exclude="@(AllCMDExcludeFilter)"/>
226
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>
230
231         <_XunitFact >
232           <![CDATA[
233
234         public class %(AllCommands._ClassName)
235         {
236             [Fact]
237             public void %(AllCommands._FactName)()
238             {
239                 int ret = -100%3B
240                 string outputFile = null%3B
241                 string errorFile = null%3B
242                 string testExecutable = null%3B
243                 Exception infraEx = null%3B
244
245                 try
246                 {
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)
253
254                   if (!_Global.runningInWindows) {
255                       testExecutable = testExecutable.Replace(".cmd", ".sh")%3B
256                   }
257
258                   System.IO.Directory.CreateDirectory(_Global.reportBase + testSubfolder)%3B
259
260                   ret = wrapper.RunTest(testExecutable, outputFile, errorFile)%3B
261                 }
262                 catch (Exception ex)
263                 {
264                     infraEx = ex%3B
265                 }
266
267                 if (ret != CoreclrTestWrapperLib.EXIT_SUCCESS_CODE)
268                 {
269                     string sErrorText = null%3B
270                     try
271                     {
272                         sErrorText = System.IO.File.ReadAllText(errorFile)%3B
273                     }
274                     catch(Exception ex)
275                     {
276                       sErrorText = "Unable to read error file: " + errorFile%3B
277                     }
278
279                     string outputText = null%3B
280                     try
281                     {
282                         System.IO.StreamReader outputReader = new System.IO.StreamReader(outputFile)%3B
283                         outputText = outputReader.ReadToEnd()%3B
284                         outputReader.Close()%3B
285                     }
286                     catch(Exception ex)
287                     {
288                         outputText = "Unable to read output file: " + outputFile%3B
289                     }
290
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
299
300                     Assert.True(ret == CoreclrTestWrapperLib.EXIT_SUCCESS_CODE, msg)%3B
301                 }
302             }
303        }
304
305         ]]>
306         </_XunitFact>
307       </AllCommands>
308       <AllXUnitFacts Include= "%(AllCommands._XunitFact)" />
309     </ItemGroup>
310
311   </Target>
312
313   <Target Name="CreateAllWrappers" DependsOnTargets="GetListOfTestCmds;FindCmdDirectories">
314     <MSBuild Projects="$(MSBuildProjectFile)" Targets="CreateXunitWrapper;BuildXunitWrapper" Properties="_CMDDIR=%(TestDirectories.Identity)" />
315   </Target>
316
317   <Target Name="GetListOfTestCmds">
318     <ItemGroup>
319       <AllRunnableTestPaths Include="$(XunitTestBinBase)\**\*.cmd" />
320     </ItemGroup>
321   </Target> 
322
323   <Import Project="tests.targets" />
324   <Import Project="publishdependency.targets" />
325
326   <PropertyGroup>
327     <TargetRid Condition="'$(RuntimeId)' != ''">$(RuntimeId)</TargetRid>
328     <TargetRid Condition="'$(RuntimeId)' == ''">$(TestNugetRuntimeId)</TargetRid>
329   </PropertyGroup>
330
331   <Target Name="CreateTestOverlay">
332     <MSBuild Projects="$(MSBuildProjectFile)"
333              Targets="CopyDependecyToCoreRoot"
334              Properties="Language=C#;TargetRid=$(TargetRid)" />
335   </Target>
336
337   <Target Name="BinPlaceRef">
338     <!-- Copy mscorlib.dll from TargetingPack to bin/Product/ref, if we're building against packages -->
339     <MSBuild Projects="$(MSBuildProjectFile)"
340              Targets="CopyDependencyToRef"
341              Properties="Language=C#;TargetRid=$(TargetRid)"
342              Condition=" '$(BuildTestsAgainstPackages)'=='true' " />
343   </Target>
344
345   <Target Name="BinPlaceProduct">
346     <!-- Copy test dependencies to bin/Product, if we're building against packages -->
347     <MSBuild Projects="$(MSBuildProjectFile)"
348              Targets="CopyDependencyToProduct"
349              Properties="Language=C#;TargetRid=$(TargetRid)"
350              Condition=" '$(BuildTestsAgainstPackages)'=='true' " />
351   </Target>
352
353   <!-- All the test projects need to add dependency to currently built runtime as they require that to run. 
354        In addition the version number of built runtime can change so all project.json needs to be dynamically generated.
355        Instead the following task creates a project.json with dependencies like  Microsoft.netcore.runtime.coreclr ..etc.
356         -->
357   <Target Name="CreateTestRuntimeJsonFile">
358     <ItemGroup>
359       <CoreclrPackage Include="$(CORE_ROOT)\.nuget\**\Microsoft.NETCore.Runtime.CoreCLR.*.nupkg"/>
360     </ItemGroup>
361     <PropertyGroup>
362       <CoreclrPackageFileName>%(CoreclrPackage.Filename)</CoreclrPackageFileName>
363       <!-- Get package version number from nuget package filename at core_root -->
364       <CoreClrPackageVersion Condition="'$(BuildTestsAgainstPackages)'!='true'">$([System.String]::Copy('$(CoreclrPackageFileName)').Replace('Microsoft.NETCore.Runtime.CoreCLR.',''))</CoreClrPackageVersion>
365       <TestRuntimeJsonContents>
366         <![CDATA[
367 {
368   "dependencies": {
369     "Microsoft.NETCore.Runtime.CoreCLR": "$(CoreClrPackageVersion)",
370     "Microsoft.NETCore.TestHost": "1.0.0-rc3-24117-00"
371   },
372   "frameworks": {
373     "dnxcore50": {}
374   },
375   "runtimes": {
376     "$(TestNugetRuntimeId)":{}
377   }
378 }
379
380         ]]>
381       </TestRuntimeJsonContents>
382     </PropertyGroup>
383
384     <MakeDir Directories="$(TestRuntimeProjectJsonDir)" Condition="!Exists('$(TestRuntimeProjectJsonDir)')" />
385
386     <!-- Write the file -->
387     <WriteLinesToFile
388       File="$(TestRuntimeProjectJson)"
389       Lines="$(TestRuntimeJsonContents)"
390       Overwrite="true" />
391
392   </Target>
393
394   <Target Name="RunPerfTests" Condition="'$(Performance)'=='true'">  
395     <Message Text="Executing steps for perf tests" Importance="High"/>  
396     
397     <!-- generate project.json for runtime dependency -->  
398     <MSBuild Projects="$(MSBuildProjectFile)"  
399              Targets="CreateTestRuntimeJsonFile"/>  
400      
401     <!-- generate project.lock.json file corresponding to above json file -->
402     <MSBuild Projects="src\Common\test_dependencies\test_dependencies.csproj"/>
403     
404     <!-- Package each perf test, upload it and trigger event to execute the tests -->  
405     <MSBuild Projects="$(MSBuildProjectFile)" Targets="UploadPerfAssemblies" />  
406   </Target>  
407
408
409   <Target Name="Build">
410
411     <!-- generate project.json for runtime dependency -->
412     <MSBuild Projects="$(MSBuildProjectFile)"
413              Targets="CreateTestRuntimeJsonFile"
414              Condition=" '$(BuildWrappers)'=='true' " />
415
416     <!-- generate project.lock.json file corresponding to above json file -->
417     <MSBuild Projects="src\Common\test_dependencies\test_dependencies.csproj"
418              Condition=" '$(BuildWrappers)'=='true' " />
419
420     <!-- Default for building -->
421     <MSBuild Projects="$(MSBuildProjectFile)"
422              Targets="CreateAllWrappers"
423              Properties="_CMDDIR=%(TestDirectories.Identity)"
424              Condition=" '$(BuildWrappers)'=='true' " />
425
426     <!-- Execution -->
427
428     <MSBuild Projects="$(MSBuildProjectFile)"
429              Targets="CreateTestOverlay"
430              Condition=" '$(GenerateRuntimeLayout)'=='true' "/>
431
432     <MSBuild Projects="$(MSBuildProjectFile)" Targets="RunTests"
433              Condition=" '$(RunTests)'=='true' "/>
434   </Target>
435
436   <Target Name="Clean">
437     <RemoveDir Condition=" '$(BuildWrappers)'=='true'" Directories="$(XunitWrapperGeneratedCSDirBase);$(XunitWrapperOutputIntermediatedDirBase)" ContinueOnError="WarnAndContinue" /> 
438   </Target>
439 </Project>