Move CoreCLR to the modern build tools and dnx
[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
5   <PropertyGroup>
6     <XunitTestBinBase Condition="'$(XunitTestBinBase)'==''" >$(BaseOutputPathWithConfig)</XunitTestBinBase>
7     <XunitWrapperGeneratedCSDirBase>$(SourceDir)\TestWrappers_$(Platform)_$(Configuration)\</XunitWrapperGeneratedCSDirBase>
8     <XunitWrapperOutputIntermediatedDirBase>$(XunitTestBinBase)\Tests\</XunitWrapperOutputIntermediatedDirBase>
9     <MSBuildEnableAllPropertyFunctions>1</MSBuildEnableAllPropertyFunctions>
10   </PropertyGroup>
11
12   <ItemGroup>
13     <DisabledTestDir Include="Common" />
14     <_SkipTestDir Include="@(DisabledTestDir)" />
15   </ItemGroup>
16   
17
18   <Target Name="FindCmdDirectories"
19           DependsOnTargets="GetListOfTestCmds"
20           >
21
22     <Error Condition="!Exists('$(XunitTestBinBase)')" 
23         Text="$(XunitTestBinBase) does not exists. Please run buildtest.cmd from the (repo root)\tests at least once to get the tests built." />
24     <ItemGroup>            
25   
26       <AllTestDirsNonCanonicalPaths Include="$([System.IO.Directory]::GetDirectories(`$(XunitTestBinBase)`))" />
27
28       <AllTestDirsPaths Include="@(AllTestDirsNonCanonicalPaths)" />
29       <AllTestDirsPaths Include="@(AllTestDirsNonCanonicalPaths)" >
30         <Path>$([System.IO.Path]::GetFullPath(%(Identity)))</Path>
31       </AllTestDirsPaths>
32
33       <NonExcludedTestDirectories Include="@(AllTestDirsPaths -> '%(Path)')" Exclude="@(_SkipTestDir -> '$(XunitTestBinBase)%(Identity)')">
34         <Path>$([System.IO.Path]::GetFullPath(%(AllRunnableTestPaths.Identity)))</Path>
35       </NonExcludedTestDirectories>
36       
37       <TestDirectoriesWithDup Include="@(NonExcludedTestDirectories -> '%(Identity)')" Condition="$([System.String]::new('%(Path)').StartsWith('%(Identity)'))" />
38
39     </ItemGroup>
40
41       <RemoveDuplicates
42             Inputs="@(TestDirectoriesWithDup)">
43             <Output
44                 TaskParameter="Filtered"
45                 ItemName="TestDirectories"/>
46         </RemoveDuplicates>
47   </Target>
48
49   
50
51   <Import Project="$(__Exclude)" Condition="'$(__Exclude)' != '' AND '$(XunitTestBinBase)' != ''" /> 
52
53   <Target Name="CreateXunitWrapper"
54            DependsOnTargets="CreateXunitFacts">
55
56     <PropertyGroup>
57       <_XunitWrapperGen >
58         <![CDATA[
59         
60 $(_XunitProlog)
61 @(AllXUnitFacts)
62 $(_XunitEpilog)
63
64 ]]>
65       </_XunitWrapperGen>
66       <XunitVersionCompiled>2.0.0-beta5-build2785</XunitVersionCompiled>
67       <XunitWrapperGenCsProj>
68         <![CDATA[
69 <?xml version="1.0" encoding="utf-8"?>
70 <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
71     
72   <Import Project="%24([MSBuild]::GetDirectoryNameOfFileAbove(%24(MSBuildThisFileDirectory), dir.props))\dir.props" />
73   <PropertyGroup>
74     <Configuration Condition=" '%24(Configuration)' == '' ">Debug</Configuration>
75     <Platform Condition=" '%24(Platform)' == '' ">AnyCPU</Platform>
76     <AssemblyName>$(XunitWrapper)</AssemblyName>
77     <SchemaVersion>2.0</SchemaVersion>
78     <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
79     <OutputType>Library</OutputType>
80     <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
81     <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
82     <IsXunitWrapperProject>true</IsXunitWrapperProject>
83     <SkipSigning>true</SkipSigning>
84     <AppDesignerFolder>Properties</AppDesignerFolder>
85     <FileAlignment>512</FileAlignment>
86     <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
87     <SolutionDir Condition="%24(SolutionDir) == '' Or %24(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
88     <RestorePackages>true</RestorePackages>
89     <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
90     <GenerateRunScript>false</GenerateRunScript>
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   </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   <Import Project="%24([MSBuild]::GetDirectoryNameOfFileAbove(%24(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
118   <PropertyGroup>
119      <OutDir>$(XunitWrapperOutputIntermediatedDirBase)\XunitRunner\</OutDir>
120   </PropertyGroup>
121 </Project>
122         ]]>
123       </XunitWrapperGenCsProj>
124       <XunitWrapperGenPackConfig>
125         <![CDATA[
126 {
127   "dependencies": {
128     "xunit" : "2.0.0-beta5-build2785",
129     "xunit.abstractions" : "2.0.0-beta5-build2785",
130     "xunit.assert" : "2.0.0-beta5-build2785",
131     "xunit.core" : "2.0.0-beta5-build2785",
132     "xunit.execution" : "2.0.0-beta5-build2785",
133     "xunit.runners" : "2.0.0-beta5-build2785"
134   },
135   "frameworks": {
136     "net45": {}
137   }
138 }
139       ]]>
140       </XunitWrapperGenPackConfig>
141
142     </PropertyGroup>
143
144     <!-- <Exec Command="md" -->
145     <MakeDir  Directories="$(XunitWrapperGeneratedCSDirBase)$(Category)"/>
146     <!-- Write the file -->
147     <WriteLinesToFile
148       File="$(XunitWrapperSrcDir)\$(XunitWrapper).cs"
149       Lines="$(_XunitWrapperGen)"
150       Overwrite="true" />
151     <!-- Write the file -->
152     <WriteLinesToFile
153       File="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj"
154       Lines="$(XunitWrapperGenCsProj)"
155       Overwrite="true" />
156
157     <!-- Write the file -->
158     <WriteLinesToFile
159       File="$(XunitWrapperSrcDir)\project.json"
160       Lines="$(XunitWrapperGenPackConfig)"
161       Overwrite="true" />
162
163   <MSBuild Projects="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj" />
164   </Target>
165   <Target Name="CreateXunitFacts">
166     <!-- NOTE! semicolons must be escaped with %3B boooo -->
167    
168     <PropertyGroup>
169       <_CMDDIR_Parent>$([System.IO.Path]::GetDirectoryName($(_CMDDIR)))</_CMDDIR_Parent>
170       <Category>$([System.String]::Copy('$(_CMDDIR)').Replace($(_CMDDIR_Parent)\,''))</Category>
171       <XunitWrapper>$(Category).XUnitWrapper</XunitWrapper>
172       <XunitWrapperSrcDir>$(XunitWrapperGeneratedCSDirBase)$(Category)</XunitWrapperSrcDir>
173       <XunitWrapperOutputDir>$(XunitWrapperOutputIntermediatedDirBase)$(Category)</XunitWrapperOutputDir>
174     </PropertyGroup>
175     <PropertyGroup>
176       <_XunitProlog Condition=" '$(_XunitProlog)'=='' ">
177         <![CDATA[
178 using Xunit%3B
179 using System%3B
180 using System.Collections.Generic%3B
181 using System.Diagnostics%3B
182 using CoreclrTestLib%3B
183
184 namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").Replace("-","_"))
185 {
186
187 ]]>
188       </_XunitProlog>
189     <_XunitEpilog Condition=" '$(_XunitEpilog)'=='' ">
190       <![CDATA[
191 }
192
193 ]]>
194        </_XunitEpilog>
195     </PropertyGroup>
196
197     <ItemGroup>
198         <CanonicalExcludeList Include="%(ExcludeList.FullPath)" Condition="'$(__Exclude)' != ''"/>
199     </ItemGroup>
200
201     <ItemGroup>
202         <AllCMDsPresent Include="$(_CMDDIR)\**\*.cmd" />
203         <AllCMDExcludeFilter Include="@(CanonicalExcludeList)" Condition="'$(__Exclude)' != ''"/>
204         <AllCMDs Include="@(AllCMDsPresent)" Exclude="@(AllCMDExcludeFilter)"/>
205         
206       <AllCommamds Include="@(AllCMDs)" >
207
208         <_FactName>$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_"))</_FactName>
209         <_XunitFact >
210           <![CDATA[
211              
212 public class $([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace("cmd","").Replace(".","_").Replace("\","_").Replace("-","_"))
213     {
214                static bool category_initlialized = false%3B
215                static bool runningInWindows = false%3B
216                static string reportbase%3B
217                static string TestBinaryBase%3B
218                static string core_root%3B
219                static void init()
220                {
221                    if (!category_initlialized)
222                    {
223                        reportbase = System.IO.Path.GetFullPath(System.Environment.GetEnvironmentVariable(%22XunitTestReportDirBase%22))%3B
224                        TestBinaryBase = System.IO.Path.GetFullPath(System.Environment.GetEnvironmentVariable(%22XunitTestBinBase%22))%3B
225                        core_root = System.IO.Path.GetFullPath(System.Environment.GetEnvironmentVariable(%22CORE_ROOT%22))%3B
226                        if (String.IsNullOrEmpty(reportbase)){
227                       
228                            throw new ArgumentException("Env variables XunitTestReportDirBase is not set") %3B
229                        }
230                            
231                        if (String.IsNullOrEmpty(TestBinaryBase)){
232                         
233                            throw new ArgumentException("Env variables XunitTestBinBase is not set")%3B
234                        }
235                        
236                        if (String.IsNullOrEmpty(core_root)){
237                         
238                            throw new ArgumentException("Env variables CORE_ROOT is not set")%3B
239                        }
240                        runningInWindows = System.Environment.GetEnvironmentVariable("OS").StartsWith("Windows")%3B
241
242                        
243                        category_initlialized = true%3B
244                    }
245                }
246     
247                 [Fact]
248                 public void $([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_").Replace("\","_").Replace("-","_"))()
249                 {
250                     int ret = -100%3B
251                     string msg ="Test Infrastructure Failure :\n"%3B
252                     try
253                     {
254                       init()%3B
255                       CoreclrTestWrapperLib wrapper = new CoreclrTestWrapperLib()%3B
256                       string testsubfolder = @"\$(Category)\$([System.String]::Copy('%(AllCMDs.RelativeDir)').Replace("$(_CMDDIR)\",''))"%3B
257                       string outputfile = System.IO.Path.GetFullPath(reportbase + testsubfolder + @"%(AllCMDs.FileName).output.txt")%3B
258                       string errorfile = System.IO.Path.GetFullPath(reportbase + testsubfolder + @"%(AllCMDs.FileName).error.txt")%3B
259                       string test_cmd = System.IO.Path.GetFullPath(TestBinaryBase + @"\$(Category)\$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",''))")%3B
260
261                     
262                       if (!runningInWindows){
263                     
264                           test_cmd = test_cmd.Replace(".cmd", ".sh")%3B
265                       }
266                     
267                       System.IO.Directory.CreateDirectory(reportbase + testsubfolder)%3B
268                     
269                       ret = wrapper.RunTest(test_cmd, outputfile, errorfile)%3B
270                     
271                       string err_text = System.IO.File.ReadAllText(errorfile)%3B
272                       msg = err_text + 
273                             @"Raw Output          :"+ outputfile + "\n" +
274                             @"To Run the test     :Step 1. set Core_Root="+ core_root + "\n" +
275                              "                     Step 2. "+test_cmd + "\n"%3B
276                       
277                     
278                     }
279                     catch (Exception Ex)
280                     {
281                        msg = msg  + Ex.Message%3B
282                     }
283                     
284                     Assert.True(ret == CoreclrTestWrapperLib.EXIT_SUCCESS_CODE, msg)%3B
285                 }
286                     
287        }
288    
289
290         ]]>
291         </_XunitFact>
292       </AllCommamds>
293       <AllXUnitFacts Include= "%(AllCommamds._XunitFact)" />
294     </ItemGroup>
295
296   </Target>
297
298   <Target Name="CreateAllWrappers"
299           DependsOnTargets="GetListOfTestCmds;FindCmdDirectories">
300
301     <MSBuild Projects="$(MSBuildProjectFile)" Targets="CreateXunitWrapper" Properties="_CMDDIR=%(TestDirectories.Identity)" />
302   </Target>
303
304   <Target Name="GetListOfTestCmds">
305     <ItemGroup>
306       <AllRunnableTestPaths Include="$(XunitTestBinBase)\**\*.cmd" />
307     </ItemGroup>
308   </Target> 
309   
310   <Import Project="tests.targets" />
311   <Import Project="publishdependency.targets" />
312  
313   <Target Name="Build">
314     <!-- Default for building -->
315     <MSBuild Projects="$(MSBuildProjectFile)"
316          Targets="CreateAllWrappers"
317          Properties="_CMDDIR=%(TestDirectories.Identity)"
318          Condition=" '$(NoBuild)'!='true' " />
319          
320     <!-- Execution -->
321     
322     <MSBuild Projects="$(MSBuildProjectFile)" Targets="CopyDependecyToCoreRoot"
323              Condition=" '$(NoRun)'!='true' "/>
324          
325     <MSBuild Projects="$(MSBuildProjectFile)" Targets="RunTests"
326              Condition=" '$(NoRun)'!='true' "/>
327   </Target>
328   
329   <Target Name="Clean">
330     <RemoveDir Condition=" '$(NoBuild)'!='true'" Directories="$(XunitWrapperGeneratedCSDirBase);$(XunitWrapperOutputIntermediatedDirBase)" ContinueOnError="WarnAndContinue" /> 
331   </Target>
332 </Project>