Merge pull request #6579 from CarolEidt/LessConservativeGtObj
[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         <Path>$([System.IO.Path]::GetFullPath(%(AllRunnableTestPaths.Identity)))</Path>
34       </NonExcludedTestDirectories>
35       <TestDirectoriesWithDup Include="@(NonExcludedTestDirectories -> '%(Identity)')" Condition="$([System.String]::new('%(Path)').StartsWith('%(Identity)'))" />
36
37     </ItemGroup>
38
39     <RemoveDuplicates Inputs="@(TestDirectoriesWithDup)">
40       <Output
41           TaskParameter="Filtered"
42           ItemName="TestDirectories"/>
43     </RemoveDuplicates>
44
45   </Target>
46
47
48   <Import Project="$(__Exclude0)" Condition="'$(__Exclude0)' != '' AND '$(XunitTestBinBase)' != ''" /> 
49   <Import Project="$(__Exclude)" Condition="'$(__Exclude)' != '' AND '$(XunitTestBinBase)' != ''" /> 
50   <PropertyGroup>
51     <HaveExcludes>False</HaveExcludes>
52     <HaveExcludes Condition="('$(__Exclude0)' != '') Or ('$(__Exclude)' != '')">True</HaveExcludes>
53   </PropertyGroup>
54
55   <Target Name="CreateXunitWrapper" DependsOnTargets="CreateXunitFacts">
56
57     <PropertyGroup>
58       <_XunitWrapperGen >
59         <![CDATA[
60         
61 $(_XunitProlog)
62 @(AllXUnitFacts)
63 $(_XunitEpilog)
64
65 ]]>
66       </_XunitWrapperGen>
67       <XunitVersionCompiled>2.1.0</XunitVersionCompiled>
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>.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>
92   </PropertyGroup>
93   <!-- Default configurations to help VS understand the configurations -->
94   <PropertyGroup Condition=" '%24(Configuration)|%24(Platform)' == 'Debug|AnyCPU' ">
95   </PropertyGroup>
96   <PropertyGroup Condition=" '%24(Configuration)|%24(Platform)' == 'Release|AnyCPU' ">
97   </PropertyGroup>
98   <ItemGroup>
99     <Compile Include="$(XunitWrapper).cs" />
100   </ItemGroup>
101   <ItemGroup>
102     <None Include="%24(TestWrappersPackagesConfigFileDirectory)project.json" />
103   </ItemGroup>
104   <ItemGroup>
105     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
106   </ItemGroup>
107    <ItemGroup>
108     <ProjectReference Include="$(SourceDir)Common\Desktop.Coreclr.TestWrapper\Desktop.Coreclr.TestWrapper.csproj">
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   <PropertyGroup>
120     <ProjectJson>%24(TestWrappersPackagesConfigFileDirectory)project.json</ProjectJson>
121     <ProjectLockJson>%24(TestWrappersPackagesConfigFileDirectory)project.lock.json</ProjectLockJson>
122   </PropertyGroup>
123   <Import Project="$(SourceDir)dir.targets" />
124   <Import Project="$(ProjectDir)helix.targets" />
125   <PropertyGroup>
126      <OutDir>$(XunitTestBinBase)\$(Category)\</OutDir>
127   </PropertyGroup>
128 </Project>
129         ]]>
130       </XunitWrapperGenCsProj>
131
132     </PropertyGroup>
133
134     <!-- <Exec Command="md" -->
135     <MakeDir  Directories="$(XunitWrapperGeneratedCSDirBase)$(Category)"/>
136
137     <!-- Write the file -->
138     <WriteLinesToFile
139       File="$(XunitWrapperSrcDir)\$(XunitWrapper).cs"
140       Lines="$(_XunitWrapperGen)"
141       Overwrite="true" />
142
143     <!-- Write the file -->
144     <WriteLinesToFile
145       File="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj"
146       Lines="$(XunitWrapperGenCsProj)"
147       Overwrite="true" />
148   </Target>
149   
150   <Target Name="BuildXunitWrapper">
151     <MSBuild Projects="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj"
152              Properties="RestorePackages=false"/>
153   </Target>
154
155   <Target Name="CreateXunitFacts">
156     <!-- NOTE! semicolons must be escaped with %3B boooo -->
157
158     <PropertyGroup>
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>
164     </PropertyGroup>
165     <PropertyGroup>
166       <_XunitProlog Condition=" '$(_XunitProlog)'=='' ">
167         <![CDATA[
168 using Xunit%3B
169 using System%3B
170 using System.Collections.Generic%3B
171 using System.Diagnostics%3B
172 using System.Reflection%3B
173 using CoreclrTestLib%3B
174
175 namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").Replace("-","_"))
176 {
177         internal class _Global
178         {
179             internal static bool runningInWindows%3B
180             internal static string reportBase%3B
181             internal static string testBinaryBase%3B
182             internal static string coreRoot%3B
183
184             static _Global()
185             {
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
189
190                 if (String.IsNullOrEmpty(reportBase)) {
191                     reportBase = System.IO.Path.Combine(testBinaryBase, "Reports")%3B
192                 }
193                 else
194                 {
195                     reportBase = System.IO.Path.GetFullPath(reportBase)%3B
196                 }
197
198                 if (String.IsNullOrEmpty(coreRoot)) {
199                     throw new ArgumentException("Environment variable CORE_ROOT is not set")%3B
200                 }
201
202                 runningInWindows = System.Environment.GetEnvironmentVariable("OS").StartsWith("Windows")%3B
203             }
204         }
205
206 ]]>
207       </_XunitProlog>
208
209       <_XunitEpilog Condition=" '$(_XunitEpilog)'=='' ">
210       <![CDATA[
211 }
212
213 ]]>
214       </_XunitEpilog>
215     </PropertyGroup>
216
217     <ItemGroup>
218       <CanonicalExcludeList Include="%(ExcludeList.FullPath)" Condition="$(HaveExcludes)"/>
219     </ItemGroup>
220
221     <ItemGroup>
222       <AllCMDsPresent Include="$(_CMDDIR)\**\*.cmd" />
223       <AllCMDExcludeFilter Include="@(CanonicalExcludeList)" Condition="$(HaveExcludes)"/>
224       <AllCMDs Include="@(AllCMDsPresent)" Exclude="@(AllCMDExcludeFilter)"/>
225
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>
229
230         <_XunitFact >
231           <![CDATA[
232
233         public class %(AllCommands._ClassName)
234         {
235             [Fact]
236             public void %(AllCommands._FactName)()
237             {
238                 int ret = -100%3B
239                 string outputFile = null%3B
240                 string errorFile = null%3B
241                 string testExecutable = null%3B
242                 Exception infraEx = null%3B
243
244                 try
245                 {
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
251
252                   if (!_Global.runningInWindows) {
253                       testExecutable = testExecutable.Replace(".cmd", ".sh")%3B
254                   }
255
256                   System.IO.Directory.CreateDirectory(_Global.reportBase + testSubfolder)%3B
257
258                   ret = wrapper.RunTest(testExecutable, outputFile, errorFile)%3B
259                 }
260                 catch (Exception ex)
261                 {
262                     infraEx = ex%3B
263                 }
264
265                 if (ret != CoreclrTestWrapperLib.EXIT_SUCCESS_CODE)
266                 {
267                     string sErrorText = null%3B
268                     try
269                     {
270                         sErrorText = System.IO.File.ReadAllText(errorFile)%3B
271                     }
272                     catch(Exception ex)
273                     {
274                       sErrorText = "Unable to read error file: " + errorFile%3B
275                     }
276
277                     string outputText = null%3B
278                     try
279                     {
280                         System.IO.StreamReader outputReader = new System.IO.StreamReader(outputFile)%3B
281                         outputText = outputReader.ReadToEnd()%3B
282                         outputReader.Close()%3B
283                     }
284                     catch(Exception ex)
285                     {
286                         outputText = "Unable to read output file: " + outputFile%3B
287                     }
288
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
297
298                     Assert.True(ret == CoreclrTestWrapperLib.EXIT_SUCCESS_CODE, msg)%3B
299                 }
300             }
301        }
302
303         ]]>
304         </_XunitFact>
305       </AllCommands>
306       <AllXUnitFacts Include= "%(AllCommands._XunitFact)" />
307     </ItemGroup>
308
309   </Target>
310
311   <Target Name="CreateAllWrappers" DependsOnTargets="GetListOfTestCmds;FindCmdDirectories">
312     <MSBuild Projects="$(MSBuildProjectFile)" Targets="CreateXunitWrapper" Properties="_CMDDIR=%(TestDirectories.Identity)" />
313
314     <!--
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.
318     -->
319     <PropertyGroup>
320       <XunitRunnerRestoreGenConfig>{ "dependencies": { "xunit.runner.msbuild": "$(XunitPackageVersion)" }, "frameworks": { "net45": {} } }</XunitRunnerRestoreGenConfig>
321       <XunitRunnerRestoreProjectDir>$(BaseOutputPath)\tempRestoreProject</XunitRunnerRestoreProjectDir>
322       <XunitRunnerRestoreProjectJsonPath>$(XunitRunnerRestoreProjectDir)\project.json</XunitRunnerRestoreProjectJsonPath>
323     </PropertyGroup>
324     
325     <MakeDir Directories="$(XunitRunnerRestoreProjectDir)" />
326     <WriteLinesToFile File="$(XunitRunnerRestoreProjectJsonPath)"
327                       Lines="$(XunitRunnerRestoreGenConfig)"
328                       Overwrite="true" />
329     
330     <Exec Command="$(DnuRestoreCommand) &quot;$(XunitRunnerRestoreProjectJsonPath)&quot;"
331           StandardOutputImportance="Low"
332           CustomErrorRegularExpression="^Unable to resolve .*"
333           IgnoreExitCode="true" 
334           IgnoreStandardErrorWarningFormat="true" />
335
336     <MSBuild Projects="$(MSBuildProjectFile)" Targets="BuildXunitWrapper" Properties="_CMDDIR=%(TestDirectories.Identity)" />
337   </Target>
338
339   <Target Name="GetListOfTestCmds">
340     <ItemGroup>
341       <AllRunnableTestPaths Include="$(XunitTestBinBase)\**\*.cmd" />
342     </ItemGroup>
343   </Target> 
344
345   <Import Project="tests.targets" />
346   <Import Project="publishdependency.targets" />
347
348   <Target Name="CreateTestOverlay">
349     <MSBuild Projects="$(MSBuildProjectFile)"
350              Targets="CopyDependecyToCoreRoot"
351              Properties="Language=C#" />
352   </Target>
353
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">
361     <ItemGroup>
362       <CoreclrPackage Include="$(CORE_ROOT)\.nuget\**\Microsoft.NETCore.Runtime.CoreCLR.*.nupkg"/>
363     </ItemGroup>
364     <PropertyGroup>
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>
369         <![CDATA[
370 {
371   "dependencies": {
372     "Microsoft.NETCore.Runtime.CoreCLR": "$(CoreClrPackageVersion)",
373     "Microsoft.NETCore.TestHost": "1.0.0-rc3-24117-00"
374   },
375   "frameworks": {
376     "dnxcore50": {}
377   },
378   "runtimes": {
379     "$(TestNugetRuntimeId)":{}
380   }
381 }
382
383         ]]>
384       </TestRuntimeJsonContents>
385     </PropertyGroup>
386
387     <MakeDir Directories="$(TestRuntimeProjectJsonDir)" Condition="!Exists('$(TestRuntimeProjectJsonDir)')" />
388
389     <!-- Write the file -->
390     <WriteLinesToFile
391       File="$(TestRuntimeProjectJson)"
392       Lines="$(TestRuntimeJsonContents)"
393       Overwrite="true" />
394
395   </Target>
396
397   <Target Name="RunPerfTests" Condition="'$(Performance)'=='true'">  
398     <Message Text="Executing steps for perf tests" Importance="High"/>  
399     
400     <!-- generate project.json for runtime dependency -->  
401     <MSBuild Projects="$(MSBuildProjectFile)"  
402              Targets="CreateTestRuntimeJsonFile"/>  
403      
404     <!-- generate project.lock.json file corresponding to above json file -->
405     <MSBuild Projects="src\Common\test_runtime\test_runtime.csproj"/>
406     
407     <!-- Package each perf test, upload it and trigger event to execute the tests -->  
408     <MSBuild Projects="$(MSBuildProjectFile)" Targets="UploadPerfAssemblies" />  
409   </Target>  
410
411
412   <Target Name="Build">
413
414     <!-- generate project.json for runtime dependency -->
415     <MSBuild Projects="$(MSBuildProjectFile)"
416              Targets="CreateTestRuntimeJsonFile"
417              Condition=" '$(BuildWrappers)'=='true' " />
418
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' " />
422
423     <!-- Default for building -->
424     <MSBuild Projects="$(MSBuildProjectFile)"
425              Targets="CreateAllWrappers"
426              Properties="_CMDDIR=%(TestDirectories.Identity)"
427              Condition=" '$(BuildWrappers)'=='true' " />
428
429     <!-- Execution -->
430
431     <MSBuild Projects="$(MSBuildProjectFile)"
432              Targets="CreateTestOverlay"
433              Condition=" '$(GenerateRuntimeLayout)'=='true' "/>
434
435     <MSBuild Projects="$(MSBuildProjectFile)" Targets="RunTests"
436              Condition=" '$(RunTests)'=='true' "/>
437   </Target>
438
439   <Target Name="Clean">
440     <RemoveDir Condition=" '$(BuildWrappers)'=='true'" Directories="$(XunitWrapperGeneratedCSDirBase);$(XunitWrapperOutputIntermediatedDirBase)" ContinueOnError="WarnAndContinue" /> 
441   </Target>
442 </Project>