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