b703e20ae77e325d25a79e6c3fc59031f02698fa
[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         <Path>$([System.IO.Path]::GetFullPath(%(Identity)))</Path>
30       </AllTestDirsPaths>
31
32       <NonExcludedTestDirectories Include="@(AllTestDirsPaths -> '%(Path)')" Exclude="@(_SkipTestDir -> '$(XunitTestBinBase)%(Identity)')">
33         <Path>$([System.IO.Path]::GetFullPath(%(AllRunnableTestPaths.Identity)))</Path>
34       </NonExcludedTestDirectories>
35       
36       <TestDirectoriesWithDup Include="@(NonExcludedTestDirectories -> '%(Identity)')" Condition="$([System.String]::new('%(Path)').StartsWith('%(Identity)'))" />
37
38     </ItemGroup>
39
40       <RemoveDuplicates
41             Inputs="@(TestDirectoriesWithDup)">
42             <Output
43                 TaskParameter="Filtered"
44                 ItemName="TestDirectories"/>
45         </RemoveDuplicates>
46     <Message Text= "TestDirectories= @(TestDirectories)"/>
47     <Message Text= "NonExcludedTestDirectories= @(NonExcludedTestDirectories)"/>
48   </Target>
49
50   
51
52   <Import Project="$(__Exclude)" Condition="'$(__Exclude)' != '' AND '$(XunitTestBinBase)' != ''" /> 
53
54   <Target Name="CreateXunitWrapper"
55            DependsOnTargets="CreateXunitFacts">
56
57     <PropertyGroup>
58       <_XunitWrapperGen >
59         <![CDATA[
60         
61 $(_XunitProlog)
62 @(AllXUnitFacts)
63 $(_XunitEpilog)
64
65 ]]>
66       </_XunitWrapperGen>
67       <XunitVersionCompiled>2.0.0-beta5-build2785</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.common.props" />
74     <Import Project="$(SourceDir)\packages\xunit.core.$(XunitVersionCompiled)\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid\xunit.core.props" Condition="Exists('$(SourceDir)\packages\xunit.core.$(XunitVersionCompiled)\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid\xunit.core.props')" />
75     <Import Project="%24(MSBuildExtensionsPath)\%24(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('%24(MSBuildExtensionsPath)\%24(MSBuildToolsVersion)\Microsoft.Common.props')" />
76   <PropertyGroup>
77     <Configuration Condition=" '%24(Configuration)' == '' ">Debug</Configuration>
78     <Platform Condition=" '%24(Platform)' == '' ">AnyCPU</Platform>
79     <AssemblyName>$(XunitWrapper)</AssemblyName>
80     <SchemaVersion>2.0</SchemaVersion>
81     <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
82     <OutputType>Library</OutputType>
83     <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
84     <AppDesignerFolder>Properties</AppDesignerFolder>
85     <FileAlignment>512</FileAlignment>
86     <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB}%3B{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
87     <ReferencePath>%24(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
88     <SolutionDir Condition="%24(SolutionDir) == '' Or %24(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
89     <RestorePackages>true</RestorePackages>
90     <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
91     <GenerateRunScript>false</GenerateRunScript>
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     <CodeAnalysisDependentAssemblyPaths Condition=" '%24(VS100COMNTOOLS)' != '' " Include="%24(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
100       <Visible>False</Visible>
101     </CodeAnalysisDependentAssemblyPaths>
102   </ItemGroup>
103   <ItemGroup>
104     <Compile Include="$(XunitWrapper).cs" />
105   </ItemGroup>
106   <ItemGroup>
107   </ItemGroup>
108   <ItemGroup>
109     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
110   </ItemGroup>
111    <ItemGroup>
112     <ProjectReference Include="$(SourceDir)\Common\Desktop.Coreclr.TestWrapper\Desktop.Coreclr.TestWrapper.csproj">
113       <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
114       <Name>coreclr</Name>
115     </ProjectReference>
116   </ItemGroup>
117  
118   <ItemGroup>
119     <Reference Include="System" />
120     <Reference Include="xunit.abstractions">
121       <HintPath>$(SourceDir)\packages\xunit.abstractions.$(XunitVersionCompiled)\lib\net35\xunit.abstractions.dll</HintPath>
122       <Private>True</Private>
123     </Reference>
124     <Reference Include="xunit.assert">
125       <HintPath>$(SourceDir)\packages\xunit.assert.$(XunitVersionCompiled)\lib\portable-net45+aspnetcore50+win+wpa81+wp80+monoandroid+monotouch10\xunit.assert.dll</HintPath>
126       <Private>True</Private>
127     </Reference>
128     <Reference Include="xunit.core">
129       <HintPath>$(SourceDir)\packages\xunit.core.$(XunitVersionCompiled)\lib\portable-net45+aspnetcore50+win+wpa81+wp80+monotouch+monoandroid\xunit.core.dll</HintPath>
130       <Private>True</Private>
131     </Reference>
132   </ItemGroup>
133   <PropertyGroup>
134      <OutDir>$(XunitWrapperOutputIntermediatedDirBase)\XunitRunner\</OutDir>
135      <OutputPath>$(XunitWrapperOutputIntermediatedDirBase)\XunitRunner\</OutputPath>
136   </PropertyGroup>
137   <Import Project="%24(MSBuildToolsPath)\Microsoft.CSharp.targets" />
138   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
139     <PropertyGroup>
140       <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
141     </PropertyGroup>
142     <Error Condition="!Exists('$(SourceDir)\packages\xunit.core.$(XunitVersionCompiled)\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SourceDir)\packages\xunit.core.$(XunitVersionCompiled)\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid\xunit.core.props'))" />
143   </Target>
144 </Project>
145
146
147   ]]>
148       </XunitWrapperGenCsProj>
149       <XunitWrapperGenPackConfig>
150         <![CDATA[
151         <?xml version="1.0" encoding="utf-8"?>
152        <packages>
153        <packages>
154       <package id="xunit" version="2.0.0-beta5-build2785" targetFramework="net45" />
155      <package id="xunit.abstractions" version="2.0.0-beta5-build2785" targetFramework="net45" />
156      <package id="xunit.assert" version="2.0.0-beta5-build2785" targetFramework="net45" />
157      <package id="xunit.core" version="2.0.0-beta5-build2785" targetFramework="net45" />
158 </packages>
159       </packages>
160       ]]>
161       </XunitWrapperGenPackConfig>
162
163     </PropertyGroup>
164
165     <!-- <Exec Command="md" -->
166     <MakeDir  Directories="$(XunitWrapperGeneratedCSDirBase)$(Category)"/>
167     <!-- Write the file -->
168     <WriteLinesToFile
169       File="$(XunitWrapperSrcDir)\$(XunitWrapper).cs"
170       Lines="$(_XunitWrapperGen)"
171       Overwrite="true" />
172     <!-- Write the file -->
173     <WriteLinesToFile
174       File="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj"
175       Lines="$(XunitWrapperGenCsProj)"
176       Overwrite="true" />
177
178     <!-- Write the file -->
179     <WriteLinesToFile
180       File="$(XunitWrapperSrcDir)\packages.config"
181       Lines="$(XunitWrapperGenPackConfig)"
182       Overwrite="true" />
183
184   <MSBuild Projects="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj" />
185   </Target>
186   <Target Name="CreateXunitFacts">
187     <!-- NOTE! semicolons must be escaped with %3B boooo -->
188    
189     <PropertyGroup>
190       <_CMDDIR_Parent>$([System.IO.Path]::GetDirectoryName($(_CMDDIR)))</_CMDDIR_Parent>
191       <Category>$([System.String]::Copy('$(_CMDDIR)').Replace($(_CMDDIR_Parent)\,''))</Category>
192       <XunitWrapper>$(Category).XUnitWrapper</XunitWrapper>
193       <XunitWrapperSrcDir>$(XunitWrapperGeneratedCSDirBase)$(Category)</XunitWrapperSrcDir>
194       <XunitWrapperOutputDir>$(XunitWrapperOutputIntermediatedDirBase)$(Category)</XunitWrapperOutputDir>
195     </PropertyGroup>
196     <PropertyGroup>
197       <_XunitProlog Condition=" '$(_XunitProlog)'=='' ">
198         <![CDATA[
199 using Xunit%3B
200 using System%3B
201 using System.Collections.Generic%3B
202 using System.Diagnostics%3B
203 using CoreclrTestLib%3B
204
205 namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").Replace("-","_"))
206 {
207
208 ]]>
209       </_XunitProlog>
210     <_XunitEpilog Condition=" '$(_XunitEpilog)'=='' ">
211       <![CDATA[
212 }
213
214 ]]>
215        </_XunitEpilog>
216     </PropertyGroup>
217
218     <ItemGroup>
219         <CanonicalExcludeList Include="%(ExcludeList.FullPath)" Condition="'$(__Exclude)' != ''"/>
220     </ItemGroup>
221
222     <ItemGroup>
223         <AllCMDsPresent Include="$(_CMDDIR)\**\*.cmd" />
224         <AllCMDExcludeFilter Include="@(CanonicalExcludeList)" Condition="'$(__Exclude)' != ''"/>
225         <AllCMDs Include="@(AllCMDsPresent)" Exclude="@(AllCMDExcludeFilter)"/>
226         
227       <AllCommamds Include="@(AllCMDs)" >
228
229         <_FactName>$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_"))</_FactName>
230         <_XunitFact >
231           <![CDATA[
232              
233 public class $([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace("cmd","").Replace(".","_").Replace("\","_").Replace("-","_"))
234     {
235                static bool category_initlialized = false%3B
236                static bool runningInWindows = false%3B
237                static string reportbase%3B
238                static string TestBinaryBase%3B
239                static string core_root%3B
240                static void init()
241                {
242                    if (!category_initlialized)
243                    {
244                        reportbase = System.IO.Path.GetFullPath(System.Environment.GetEnvironmentVariable(%22XunitTestReportDirBase%22))%3B
245                        TestBinaryBase = System.IO.Path.GetFullPath(System.Environment.GetEnvironmentVariable(%22XunitTestBinBase%22))%3B
246                        core_root = System.IO.Path.GetFullPath(System.Environment.GetEnvironmentVariable(%22CORE_ROOT%22))%3B
247                        if (String.IsNullOrEmpty(reportbase)){
248                       
249                            throw new ArgumentException("Env variables XunitTestReportDirBase is not set") %3B
250                        }
251                            
252                        if (String.IsNullOrEmpty(TestBinaryBase)){
253                         
254                            throw new ArgumentException("Env variables XunitTestBinBase is not set")%3B
255                        }
256                        
257                        if (String.IsNullOrEmpty(core_root)){
258                         
259                            throw new ArgumentException("Env variables CORE_ROOT is not set")%3B
260                        }
261                        runningInWindows = System.Environment.GetEnvironmentVariable("OS").StartsWith("Windows")%3B
262
263                        
264                        category_initlialized = true%3B
265                    }
266                }
267     
268                 [Fact]
269                 public void $([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_").Replace("\","_").Replace("-","_"))()
270                 {
271                     int ret = -100%3B
272                     string msg ="Test Infrastructure Failure :\n"%3B
273                     try
274                     {
275                       init()%3B
276                       CoreclrTestWrapperLib wrapper = new CoreclrTestWrapperLib()%3B
277                       string testsubfolder = @"\$(Category)\$([System.String]::Copy('%(AllCMDs.RelativeDir)').Replace("$(_CMDDIR)\",''))"%3B
278                       string outputfile = System.IO.Path.GetFullPath(reportbase + testsubfolder + @"%(AllCMDs.FileName).output.txt")%3B
279                       string errorfile = System.IO.Path.GetFullPath(reportbase + testsubfolder + @"%(AllCMDs.FileName).error.txt")%3B
280                       string test_cmd = System.IO.Path.GetFullPath(TestBinaryBase + @"\$(Category)\$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",''))")%3B
281
282                     
283                       if (!runningInWindows){
284                     
285                           test_cmd = test_cmd.Replace(".cmd", ".sh")%3B
286                       }
287                     
288                       System.IO.Directory.CreateDirectory(reportbase + testsubfolder)%3B
289                     
290                       ret = wrapper.RunTest(test_cmd, outputfile, errorfile)%3B
291                     
292                       string err_text = System.IO.File.ReadAllText(errorfile)%3B
293                       msg = err_text + 
294                             @"Raw Output          :"+ outputfile + "\n" +
295                             @"To Run the test     :Step 1. set Core_Root="+ core_root + "\n" +
296                              "                     Step 2. "+test_cmd + "\n"%3B
297                       
298                     
299                     }
300                     catch (Exception Ex)
301                     {
302                        msg = msg  + Ex.Message%3B
303                     }
304                     
305                     Assert.True(ret == CoreclrTestWrapperLib.EXIT_SUCCESS_CODE, msg)%3B
306                 }
307                     
308        }
309    
310
311         ]]>
312         </_XunitFact>
313       </AllCommamds>
314       <AllXUnitFacts Include= "%(AllCommamds._XunitFact)" />
315     </ItemGroup>
316
317   </Target>
318
319   <Target Name="CreateAllWrappers"
320           DependsOnTargets="GetListOfTestCmds;FindCmdDirectories">
321
322     <MSBuild Projects="$(MSBuildProjectFile)" Targets="CreateXunitWrapper" Properties="_CMDDIR=%(TestDirectories.Identity)" />
323   </Target>
324
325   <Target Name="GetListOfTestCmds">
326   <ItemGroup>
327       <AllRunnableTestPaths Include="$(XunitTestBinBase)\**\*.cmd" />
328   </ItemGroup>
329   </Target> 
330   
331   <Import Project="tests.targets" />
332   <Import Project="publishdependency.targets" />
333   <Target Name="CreateXunitWrappers"
334           DependsOnTargets="Clean"
335           AfterTargets="Build">
336
337     <MSBuild Projects="$(MSBuildProjectFile)"
338              Targets="CreateAllWrappers"
339              Properties="_CMDDIR=%(TestDirectories.Identity)" />
340
341     <MSBuild Projects="$(MSBuildProjectFile)" Targets="CopyDependecyToCoreRoot"
342              Condition=" '$(NoRun)'!='true' "/>
343          
344     <MSBuild Projects="$(MSBuildProjectFile)" Targets="RunTests"
345              Condition=" '$(NoRun)'!='true' "/>
346   </Target>
347  
348   <Target Name="Build" />
349   <Target Name="Clean">
350     <RemoveDir Condition=" '$(NoBuild)'!='true'" Directories="$(XunitWrapperGeneratedCSDirBase);$(XunitWrapperOutputIntermediatedDirBase)" ContinueOnError="WarnAndContinue" /> 
351   </Target>
352 </Project>