Merge pull request #12429 from mikedn/dead-qmark
[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') And ('$(BuildOS)' == 'Windows_NT')">.NETFramework</TargetFrameworkIdentifier>
82     <TargetFrameworkVersion Condition ="('$(BuildTestsAgainstPackages)' != 'true') And ('$(BuildOS)' == 'Windows_NT')">v4.5</TargetFrameworkVersion>
83     <NugetTargetMonikerShort Condition ="'$(BuildTestsAgainstPackages)' != 'true'">net45</NugetTargetMonikerShort>
84     <IsXunitWrapperProject>true</IsXunitWrapperProject>
85     <SkipSigning>true</SkipSigning>
86     <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB}%3B{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
87     <SolutionDir Condition="%24(SolutionDir) == '' Or %24(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
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     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
101   </ItemGroup>
102    <ItemGroup>
103     <ProjectReference Include="$(SourceDir)Common\Desktop.Coreclr.TestWrapper\Desktop.Coreclr.TestWrapper.csproj" Condition="('$(BuildTestsAgainstPackages)' != 'true') And ('$(BuildOS)' == 'Windows_NT')">
104       <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
105       <Name>coreclr</Name>
106     </ProjectReference>
107     <ProjectReference Include="$(SourceDir)Common\Coreclr.TestWrapper\Coreclr.TestWrapper.csproj" Condition="('$(BuildTestsAgainstPackages)' == 'true') Or ('$(BuildOS)' != 'Windows_NT')">
108       <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
109       <Name>coreclr</Name>
110     </ProjectReference>
111   </ItemGroup>
112  
113   <ItemGroup>
114     <Reference Include="System" />
115     <Reference Include="System.Runtime" />
116     <Reference Include="mscorlib" />
117   </ItemGroup>
118   <Import Project="$(SourceDir)dir.targets" />
119   <PropertyGroup>
120     <OutDir>$(XunitTestBinBase)\$(CategoryWithSlash)\</OutDir>
121     <ProjectAssetsFile Condition="'$(BuildTestsAgainstPackages)' != 'true'">%24(TestWrappersPackagesConfigFileDirectory)obj/project.assets.json</ProjectAssetsFile>
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 Condition="'$(RunningOnUnix)' != 'true'" >$([System.String]::Copy('$(_CMDDIR)').Replace("$(_CMDDIR_Grandparent)\",""))</CategoryWithSlash>
156       <CategoryWithSlash Condition="'$(RunningOnUnix)' == 'true'" >$([System.String]::Copy('$(_CMDDIR)').Replace("$(_CMDDIR_Grandparent)/",""))</CategoryWithSlash>
157       <Category Condition="'$(RunningOnUnix)' != 'true'" >$([System.String]::Copy('$(CategoryWithSlash)').Replace('\','.'))</Category>
158       <Category Condition="'$(RunningOnUnix)' == 'true'" >$([System.String]::Copy('$(CategoryWithSlash)').Replace('/','.'))</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                 string operatingSystem = System.Environment.GetEnvironmentVariable("OS")%3B
201                 runningInWindows = (operatingSystem != null && operatingSystem.StartsWith("Windows"))%3B
202             }
203         }
204
205 ]]>
206       </_XunitProlog>
207
208       <_XunitEpilog Condition=" '$(_XunitEpilog)'=='' ">
209       <![CDATA[
210 }
211
212 ]]>
213       </_XunitEpilog>
214     </PropertyGroup>
215
216     <ItemGroup>
217       <CanonicalExcludeList Include="%(ExcludeList.FullPath)" Condition="$(HaveExcludes)"/>
218     </ItemGroup>
219
220     <PropertyGroup>
221       <TestExecutableReplacement Condition="'$(TargetsWindows)' != 'true' ">testExecutable = testExecutable.Replace("\\", "/")%3B</TestExecutableReplacement>
222     </PropertyGroup>
223
224     <ItemGroup>
225       <AllCMDsPresent Include="$(_CMDDIR)\**\*.cmd" Condition="'$(RunningOnUnix)' != 'true'" />
226       <AllCMDsPresent Include="$(_CMDDIR)\**\*.sh" Condition="'$(RunningOnUnix)' == 'true'" />
227       <AllCMDExcludeFilter Include="@(CanonicalExcludeList)" Condition="$(HaveExcludes)"/>
228       <AllCMDs Include="@(AllCMDsPresent)" Exclude="@(AllCMDExcludeFilter)"/>
229
230       <AllCommands Include="@(AllCMDs)" >
231         <_FactName Condition="'$(RunningOnUnix)' != 'true'" >$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_").Replace("\","_").Replace("-","_"))</_FactName>
232         <_ClassName Condition="'$(RunningOnUnix)' != 'true'" >$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace("cmd","").Replace(".","_").Replace("\","_").Replace("-","_"))</_ClassName>
233         <_FactName Condition="'$(RunningOnUnix)' == 'true'" >$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_").Replace("/","_").Replace("-","_"))</_FactName>
234         <_ClassName Condition="'$(RunningOnUnix)' == 'true'" >$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace("sh","").Replace(".","_").Replace("/","_").Replace("-","_"))</_ClassName>
235
236         <_XunitFact >
237           <![CDATA[
238
239         public class %(AllCommands._ClassName)
240         {
241             [Fact]
242             public void %(AllCommands._FactName)()
243             {
244                 int ret = -100%3B
245                 string outputFile = null%3B
246                 string errorFile = null%3B
247                 string testExecutable = null%3B
248                 Exception infraEx = null%3B
249
250                 try
251                 {
252                   CoreclrTestWrapperLib wrapper = new CoreclrTestWrapperLib()%3B
253                   string testSubfolder = @"\$(Category)\$([System.String]::Copy('%(AllCMDs.RelativeDir)').Replace("$(_CMDDIR)\",''))"%3B
254                   outputFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).output.txt")%3B
255                   errorFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).error.txt")%3B
256                   testExecutable = System.IO.Path.GetFullPath(_Global.testBinaryBase + @"$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",''))")%3B
257                   $(TestExecutableReplacement)
258
259                   if (!_Global.runningInWindows) {
260                       testExecutable = testExecutable.Replace(".cmd", ".sh")%3B
261                   }
262
263                   System.IO.Directory.CreateDirectory(_Global.reportBase + testSubfolder)%3B
264
265                   ret = wrapper.RunTest(testExecutable, outputFile, errorFile)%3B
266                 }
267                 catch (Exception ex)
268                 {
269                     infraEx = ex%3B
270                 }
271
272                 if (ret != CoreclrTestWrapperLib.EXIT_SUCCESS_CODE)
273                 {
274                     string sErrorText = null%3B
275                     try
276                     {
277                         sErrorText = System.IO.File.ReadAllText(errorFile)%3B
278                     }
279                     catch(Exception ex)
280                     {
281                       sErrorText = "Unable to read error file: " + errorFile%3B
282                     }
283
284                     string outputText = null%3B
285                     try
286                     {
287                         System.IO.StreamReader outputReader = new System.IO.StreamReader(outputFile)%3B
288                         outputText = outputReader.ReadToEnd()%3B
289                         outputReader.Close()%3B
290                     }
291                     catch(Exception ex)
292                     {
293                         outputText = "Unable to read output file: " + outputFile%3B
294                     }
295
296                     string msg = infraEx != null ? "Test Infrastructure Failure: " + infraEx.Message
297                                                  : sErrorText + "\n\n" +
298                                                    "Return code:      " + ret + "\n" +
299                                                    "Raw output file:      " + outputFile + "\n" +
300                                                    "Raw output:\n" + outputText + "\n" +
301                                                    "To run the test:\n" +
302                                                    "> set CORE_ROOT=" + _Global.coreRoot + "\n" +
303                                                    "> " + testExecutable + "\n"%3B
304
305                     Assert.True(ret == CoreclrTestWrapperLib.EXIT_SUCCESS_CODE, msg)%3B
306                 }
307             }
308        }
309
310         ]]>
311         </_XunitFact>
312       </AllCommands>
313       <AllXUnitFacts Include= "%(AllCommands._XunitFact)" />
314     </ItemGroup>
315
316   </Target>
317
318   <Target Name="CreateAllWrappers" DependsOnTargets="GetListOfTestCmds;FindCmdDirectories">
319     <MSBuild Projects="$(MSBuildProjectFile)" Targets="CreateXunitWrapper;BuildXunitWrapper" Properties="_CMDDIR=%(TestDirectories.Identity)" />
320   </Target>
321
322   <Target Name="GetListOfTestCmds">
323     <ItemGroup>
324       <AllRunnableTestPaths Include="$(XunitTestBinBase)\**\*.cmd" />
325     </ItemGroup>
326   </Target>
327
328   <!-- If we want to overwrite the desired CoreCLR package version, we need to get the new version from the generated props file in bin/obj -->
329   <Import Condition="'$(OverwriteCoreClrPackageVersion)' == 'true'" Project="$(BuildVersionFile)" />
330
331   <PropertyGroup Condition="'$(OverwriteCoreClrPackageVersion)' == 'true'">
332     <VersionToRestore Condition="'$(StableVersion)' != ''">$(StableVersion)</VersionToRestore>
333     <VersionToRestore Condition="'$(VersionToRestore)' == ''">$(PackageVersion)-$(PreReleaseLabel)-$(BuildNumberMajor)-$(BuildNumberMinor)</VersionToRestore>
334     <DesiredPackageVersionArg>$(VersionToRestore)</DesiredPackageVersionArg>
335   </PropertyGroup> 
336
337   <Import Project="tests.targets" />
338   <Import Project="publishdependency.targets" />
339
340   <PropertyGroup>
341     <TargetRid Condition="'$(RuntimeId)' != ''">$(RuntimeId)</TargetRid>
342     <TargetRid Condition="'$(RuntimeId)' == ''">$(TestNugetRuntimeId)</TargetRid>
343     <DesiredPackageVersionArg Condition="'$(DesiredPackageVersionArg)' == ''">$(CoreClrPackageVersion)</DesiredPackageVersionArg>
344   </PropertyGroup>
345
346   <Target Name="CreateTestOverlay">
347     <MSBuild Projects="$(MSBuildProjectFile)"
348              Targets="CopyDependecyToCoreRoot"
349              Properties="Language=C#;TargetRid=$(TargetRid)" />
350   </Target>
351
352   <Target Name="BinPlaceRef">
353     <!-- Copy mscorlib.dll from TargetingPack to bin/Product/ref, if we're building against packages -->
354     <MSBuild Projects="$(MSBuildProjectFile)"
355              Targets="CopyDependencyToRef"
356              Properties="Language=C#;TargetRid=$(TargetRid)"
357              Condition=" '$(BuildTestsAgainstPackages)'=='true' " />
358   </Target>
359
360   <Target Name="BinPlaceProduct">
361     <!-- Copy test dependencies to bin/Product, if we're building against packages -->
362     <MSBuild Projects="$(MSBuildProjectFile)"
363              Targets="CopyDependencyToProduct"
364              Properties="Language=C#;TargetRid=$(TargetRid)"
365              Condition=" '$(BuildTestsAgainstPackages)'=='true' " />
366   </Target>
367
368   <Target Name="RunPerfTests" Condition="'$(Performance)'=='true'">  
369     <Message Text="Executing steps for perf tests" Importance="High"/>  
370     
371     <!-- generate project.json for runtime dependency -->  
372     <MSBuild Projects="$(MSBuildProjectFile)"  
373              Targets="CreateTestRuntimeJsonFile"/>  
374      
375     <!-- generate project.lock.json file corresponding to above json file -->
376     <MSBuild Projects="src\Common\test_dependencies\test_dependencies.csproj"/>
377     
378     <!-- Package each perf test, upload it and trigger event to execute the tests -->  
379     <MSBuild Projects="$(MSBuildProjectFile)" Targets="UploadPerfAssemblies" />  
380   </Target>  
381
382
383   <Target Name="Build">
384
385     <!-- generate project.lock.json file corresponding to above json file -->
386     <MSBuild Projects="src\Common\test_dependencies\test_dependencies.csproj"
387              Condition=" '$(BuildWrappers)'=='true' " />
388
389     <!-- Default for building -->
390     <MSBuild Projects="$(MSBuildProjectFile)"
391              Targets="CreateAllWrappers"
392              Properties="_CMDDIR=%(TestDirectories.Identity)"
393              Condition=" '$(BuildWrappers)'=='true' " />
394
395     <!-- Execution -->
396
397     <MSBuild Projects="$(MSBuildProjectFile)"
398              Targets="CreateTestOverlay"
399              Condition=" '$(GenerateRuntimeLayout)'=='true' "/>
400
401     <MSBuild Projects="$(MSBuildProjectFile)" Targets="RunTests"
402              Condition=" '$(RunTests)'=='true' "/>
403   </Target>
404
405   <Target Name="Clean">
406     <RemoveDir Condition=" '$(BuildWrappers)'=='true'" Directories="$(XunitWrapperGeneratedCSDirBase);$(XunitWrapperOutputIntermediatedDirBase)" ContinueOnError="WarnAndContinue" /> 
407   </Target>
408 </Project>