1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="src\dir.props" />
<Import Project="$(ToolsDir)Build.Post.targets" Condition="Exists('$(ToolsDir)Build.Post.targets') AND '$(BuildWrappers)' == 'true'" />
<Import Project="helixperftasks.targets" Condition="'$(Performance)'=='true'"/>
<PropertyGroup>
<XunitTestBinBase Condition="'$(XunitTestBinBase)'==''" >$(BaseOutputPathWithConfig)</XunitTestBinBase>
<XunitWrapperGeneratedCSDirBase>$(XunitTestBinBase)\TestWrappers\</XunitWrapperGeneratedCSDirBase>
<XunitWrapperOutputIntermediatedDirBase>$(XunitTestBinBase)\Tests\</XunitWrapperOutputIntermediatedDirBase>
<MSBuildEnableAllPropertyFunctions>1</MSBuildEnableAllPropertyFunctions>
</PropertyGroup>
<ItemGroup>
<DisabledTestDir Include="Common" />
<_SkipTestDir Include="@(DisabledTestDir)" />
</ItemGroup>
<Target Name="FindCmdDirectories" DependsOnTargets="GetListOfTestCmds">
<Error Condition="!Exists('$(XunitTestBinBase)')"
Text="$(XunitTestBinBase) does not exist. Please run buildtest.cmd from the (repo root)\tests at least once to get the tests built." />
<ItemGroup>
<AllTestDirsNonCanonicalPaths Include="$([System.IO.Directory]::GetDirectories(`$(XunitTestBinBase)`))" />
<AllTestDirsPaths Include="@(AllTestDirsNonCanonicalPaths)" />
<AllTestDirsPaths Include="@(AllTestDirsNonCanonicalPaths)" >
<Path>$([System.IO.Path]::GetFullPath(%(Identity)))</Path>
</AllTestDirsPaths>
<NonExcludedTestDirectories Include="@(AllTestDirsPaths -> '%(Path)')" Exclude="@(_SkipTestDir -> '$(XunitTestBinBase)%(Identity)')">
<Path>$([System.IO.Path]::GetFullPath(%(AllRunnableTestPaths.Identity)))</Path>
</NonExcludedTestDirectories>
<TestDirectoriesWithDup Include="@(NonExcludedTestDirectories -> '%(Identity)')" Condition="$([System.String]::new('%(Path)').StartsWith('%(Identity)'))" />
</ItemGroup>
<RemoveDuplicates Inputs="@(TestDirectoriesWithDup)">
<Output
TaskParameter="Filtered"
ItemName="TestDirectories"/>
</RemoveDuplicates>
</Target>
<Import Project="$(__Exclude0)" Condition="'$(__Exclude0)' != '' AND '$(XunitTestBinBase)' != ''" />
<Import Project="$(__Exclude)" Condition="'$(__Exclude)' != '' AND '$(XunitTestBinBase)' != ''" />
<PropertyGroup>
<HaveExcludes>False</HaveExcludes>
<HaveExcludes Condition="('$(__Exclude0)' != '') Or ('$(__Exclude)' != '')">True</HaveExcludes>
</PropertyGroup>
<Target Name="CreateXunitWrapper" DependsOnTargets="CreateXunitFacts">
<PropertyGroup>
<_XunitWrapperGen >
<![CDATA[
$(_XunitProlog)
@(AllXUnitFacts)
$(_XunitEpilog)
]]>
</_XunitWrapperGen>
<XunitVersionCompiled>2.1.0</XunitVersionCompiled>
<XunitWrapperGenCsProj>
<![CDATA[
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(SourceDir)dir.props" />
<PropertyGroup>
<Configuration Condition=" '%24(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '%24(Platform)' == '' ">AnyCPU</Platform>
<AssemblyName>$(XunitWrapper)</AssemblyName>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
<OutputType>Library</OutputType>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<IsXunitWrapperProject>true</IsXunitWrapperProject>
<SkipSigning>true</SkipSigning>
<AppDesignerFolder>Properties</AppDesignerFolder>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<SolutionDir Condition="%24(SolutionDir) == '' Or %24(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
<CLRTestKind>BuildOnly</CLRTestKind>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition=" '%24(Configuration)|%24(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '%24(Configuration)|%24(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<ItemGroup>
<Compile Include="$(XunitWrapper).cs" />
</ItemGroup>
<ItemGroup>
<None Include="%24(TestWrappersPackagesConfigFileDirectory)project.json" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SourceDir)Common\Desktop.Coreclr.TestWrapper\Desktop.Coreclr.TestWrapper.csproj">
<Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
<Name>coreclr</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Runtime" />
<Reference Include="mscorlib" />
</ItemGroup>
<PropertyGroup>
<ProjectJson>%24(TestWrappersPackagesConfigFileDirectory)project.json</ProjectJson>
<ProjectLockJson>%24(TestWrappersPackagesConfigFileDirectory)project.lock.json</ProjectLockJson>
</PropertyGroup>
<Import Project="$(SourceDir)dir.targets" />
<Import Project="$(ProjectDir)helix.targets" />
<PropertyGroup>
<OutDir>$(XunitTestBinBase)\$(Category)\</OutDir>
</PropertyGroup>
</Project>
]]>
</XunitWrapperGenCsProj>
</PropertyGroup>
<!-- <Exec Command="md" -->
<MakeDir Directories="$(XunitWrapperGeneratedCSDirBase)$(Category)"/>
<!-- Write the file -->
<WriteLinesToFile
File="$(XunitWrapperSrcDir)\$(XunitWrapper).cs"
Lines="$(_XunitWrapperGen)"
Overwrite="true" />
<!-- Write the file -->
<WriteLinesToFile
File="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj"
Lines="$(XunitWrapperGenCsProj)"
Overwrite="true" />
</Target>
<Target Name="BuildXunitWrapper">
<MSBuild Projects="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj"
Properties="RestorePackages=false"/>
</Target>
<Target Name="CreateXunitFacts">
<!-- NOTE! semicolons must be escaped with %3B boooo -->
<PropertyGroup>
<_CMDDIR_Parent>$([System.IO.Path]::GetDirectoryName($(_CMDDIR)))</_CMDDIR_Parent>
<Category>$([System.String]::Copy('$(_CMDDIR)').Replace($(_CMDDIR_Parent)\,''))</Category>
<XunitWrapper>$(Category).XUnitWrapper</XunitWrapper>
<XunitWrapperSrcDir>$(XunitWrapperGeneratedCSDirBase)$(Category)</XunitWrapperSrcDir>
<XunitWrapperOutputDir>$(XunitWrapperOutputIntermediatedDirBase)$(Category)</XunitWrapperOutputDir>
</PropertyGroup>
<PropertyGroup>
<_XunitProlog Condition=" '$(_XunitProlog)'=='' ">
<![CDATA[
using Xunit%3B
using System%3B
using System.Collections.Generic%3B
using System.Diagnostics%3B
using System.Reflection%3B
using CoreclrTestLib%3B
namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").Replace("-","_"))
{
internal class _Global
{
internal static bool runningInWindows%3B
internal static string reportBase%3B
internal static string testBinaryBase%3B
internal static string coreRoot%3B
static _Global()
{
reportBase = System.Environment.GetEnvironmentVariable(%22XunitTestReportDirBase%22)%3B
testBinaryBase = System.IO.Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath)%3B
coreRoot = System.IO.Path.GetFullPath(System.Environment.GetEnvironmentVariable(%22CORE_ROOT%22))%3B
if (String.IsNullOrEmpty(reportBase)) {
reportBase = System.IO.Path.Combine(testBinaryBase, "Reports")%3B
}
else
{
reportBase = System.IO.Path.GetFullPath(reportBase)%3B
}
if (String.IsNullOrEmpty(coreRoot)) {
throw new ArgumentException("Environment variable CORE_ROOT is not set")%3B
}
runningInWindows = System.Environment.GetEnvironmentVariable("OS").StartsWith("Windows")%3B
}
}
]]>
</_XunitProlog>
<_XunitEpilog Condition=" '$(_XunitEpilog)'=='' ">
<![CDATA[
}
]]>
</_XunitEpilog>
</PropertyGroup>
<ItemGroup>
<CanonicalExcludeList Include="%(ExcludeList.FullPath)" Condition="$(HaveExcludes)"/>
</ItemGroup>
<ItemGroup>
<AllCMDsPresent Include="$(_CMDDIR)\**\*.cmd" />
<AllCMDExcludeFilter Include="@(CanonicalExcludeList)" Condition="$(HaveExcludes)"/>
<AllCMDs Include="@(AllCMDsPresent)" Exclude="@(AllCMDExcludeFilter)"/>
<AllCommands Include="@(AllCMDs)" >
<_FactName>$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_").Replace("\","_").Replace("-","_"))</_FactName>
<_ClassName>$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace("cmd","").Replace(".","_").Replace("\","_").Replace("-","_"))</_ClassName>
<_XunitFact >
<![CDATA[
public class %(AllCommands._ClassName)
{
[Fact]
public void %(AllCommands._FactName)()
{
int ret = -100%3B
string outputFile = null%3B
string errorFile = null%3B
string testExecutable = null%3B
Exception infraEx = null%3B
try
{
CoreclrTestWrapperLib wrapper = new CoreclrTestWrapperLib()%3B
string testSubfolder = @"\$(Category)\$([System.String]::Copy('%(AllCMDs.RelativeDir)').Replace("$(_CMDDIR)\",''))"%3B
outputFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).output.txt")%3B
errorFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).error.txt")%3B
testExecutable = System.IO.Path.GetFullPath(_Global.testBinaryBase + @"$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",''))")%3B
if (!_Global.runningInWindows) {
testExecutable = testExecutable.Replace(".cmd", ".sh")%3B
}
System.IO.Directory.CreateDirectory(_Global.reportBase + testSubfolder)%3B
ret = wrapper.RunTest(testExecutable, outputFile, errorFile)%3B
}
catch (Exception ex)
{
infraEx = ex%3B
}
if (ret != CoreclrTestWrapperLib.EXIT_SUCCESS_CODE)
{
string sErrorText = null%3B
try
{
sErrorText = System.IO.File.ReadAllText(errorFile)%3B
}
catch(Exception ex)
{
sErrorText = "Unable to read error file: " + errorFile%3B
}
string outputText = null%3B
try
{
System.IO.StreamReader outputReader = new System.IO.StreamReader(outputFile)%3B
outputText = outputReader.ReadToEnd()%3B
outputReader.Close()%3B
}
catch(Exception ex)
{
outputText = "Unable to read output file: " + outputFile%3B
}
string msg = infraEx != null ? "Test Infrastructure Failure: " + infraEx.Message
: sErrorText + "\n\n" +
"Return code: " + ret + "\n" +
"Raw output file: " + outputFile + "\n" +
"Raw output:\n" + outputText + "\n" +
"To run the test:\n" +
"> set CORE_ROOT=" + _Global.coreRoot + "\n" +
"> " + testExecutable + "\n"%3B
Assert.True(ret == CoreclrTestWrapperLib.EXIT_SUCCESS_CODE, msg)%3B
}
}
}
]]>
</_XunitFact>
</AllCommands>
<AllXUnitFacts Include= "%(AllCommands._XunitFact)" />
</ItemGroup>
</Target>
<Target Name="CreateAllWrappers" DependsOnTargets="GetListOfTestCmds;FindCmdDirectories">
<MSBuild Projects="$(MSBuildProjectFile)" Targets="CreateXunitWrapper" Properties="_CMDDIR=%(TestDirectories.Identity)" />
<!--
Contents of a project.json that will be restored once with errors turned off. This works
around the package being incompatible with dotnet restore. Only the package contents are
required so the compatibility errors can be ignored.
-->
<PropertyGroup>
<XunitRunnerRestoreGenConfig>{ "dependencies": { "xunit.runner.msbuild": "$(XunitPackageVersion)" }, "frameworks": { "net45": {} } }</XunitRunnerRestoreGenConfig>
<XunitRunnerRestoreProjectDir>$(BaseOutputPath)\tempRestoreProject</XunitRunnerRestoreProjectDir>
<XunitRunnerRestoreProjectJsonPath>$(XunitRunnerRestoreProjectDir)\project.json</XunitRunnerRestoreProjectJsonPath>
</PropertyGroup>
<MakeDir Directories="$(XunitRunnerRestoreProjectDir)" />
<WriteLinesToFile File="$(XunitRunnerRestoreProjectJsonPath)"
Lines="$(XunitRunnerRestoreGenConfig)"
Overwrite="true" />
<Exec Command="$(DnuRestoreCommand) "$(XunitRunnerRestoreProjectJsonPath)""
StandardOutputImportance="Low"
CustomErrorRegularExpression="^Unable to resolve .*"
IgnoreExitCode="true"
IgnoreStandardErrorWarningFormat="true" />
<MSBuild Projects="$(MSBuildProjectFile)" Targets="BuildXunitWrapper" Properties="_CMDDIR=%(TestDirectories.Identity)" />
</Target>
<Target Name="GetListOfTestCmds">
<ItemGroup>
<AllRunnableTestPaths Include="$(XunitTestBinBase)\**\*.cmd" />
</ItemGroup>
</Target>
<Import Project="tests.targets" />
<Import Project="publishdependency.targets" />
<Target Name="CreateTestOverlay">
<MSBuild Projects="$(MSBuildProjectFile)"
Targets="CopyDependecyToCoreRoot"
Properties="Language=C#" />
</Target>
<!-- All the test projects need to add dependency to currently built runtime as they require that to run.
In addition the version number of built runtime can change so all project.json needs to be dynamically generated.
In order to avoid regenerating project.json for all the tests projects...I added a common project for all the tests.
This project is at tests\src\common\test_runtime\test_runtime.csproj. This project is adding common dependencies to
all the tests like dependency on Microsoft.netcore.runtime.coreclr ..etc. Project.json for this project is dynamically
generated via task CreateTestRuntimeJsonFile. -->
<Target Name="CreateTestRuntimeJsonFile">
<ItemGroup>
<CoreclrPackage Include="$(CORE_ROOT)\.nuget\**\Microsoft.NETCore.Runtime.CoreCLR.*.nupkg"/>
</ItemGroup>
<PropertyGroup>
<CoreclrPackageFileName>%(CoreclrPackage.Filename)</CoreclrPackageFileName>
<!-- Get package version number from nuget package filename at core_root -->
<CoreclrPackageVersion>$([System.String]::Copy('$(CoreclrPackageFileName)').Replace('Microsoft.NETCore.Runtime.CoreCLR.',''))</CoreclrPackageVersion>
<TestRuntimeJsonContents>
<![CDATA[
{
"dependencies": {
"Microsoft.NETCore.Runtime.CoreCLR": "$(CoreclrPackageVersion)",
"Microsoft.NETCore.TestHost": "1.0.0-rc3-24117-00"
},
"frameworks": {
"dnxcore50": {}
},
"runtimes": {
"$(TestNugetRuntimeId)":{}
}
}
]]>
</TestRuntimeJsonContents>
</PropertyGroup>
<MakeDir Directories="$(TestRuntimeProjectJsonDir)" Condition="!Exists('$(TestRuntimeProjectJsonDir)')" />
<!-- Write the file -->
<WriteLinesToFile
File="$(TestRuntimeProjectJson)"
Lines="$(TestRuntimeJsonContents)"
Overwrite="true" />
</Target>
<Target Name="RunPerfTests" Condition="'$(Performance)'=='true'">
<Message Text="Executing steps for perf tests" Importance="High"/>
<!-- generate project.json for runtime dependency -->
<MSBuild Projects="$(MSBuildProjectFile)"
Targets="CreateTestRuntimeJsonFile"/>
<!-- generate project.lock.json file corresponding to above json file -->
<MSBuild Projects="src\Common\test_runtime\test_runtime.csproj"/>
<!-- Package each perf test, upload it and trigger event to execute the tests -->
<MSBuild Projects="$(MSBuildProjectFile)" Targets="UploadPerfAssemblies" />
</Target>
<Target Name="Build">
<!-- generate project.json for runtime dependency -->
<MSBuild Projects="$(MSBuildProjectFile)"
Targets="CreateTestRuntimeJsonFile"
Condition=" '$(BuildWrappers)'=='true' " />
<!-- generate project.lock.json file corresponding to above json file -->
<MSBuild Projects="src\Common\test_runtime\test_runtime.csproj"
Condition=" '$(BuildWrappers)'=='true' " />
<!-- Default for building -->
<MSBuild Projects="$(MSBuildProjectFile)"
Targets="CreateAllWrappers"
Properties="_CMDDIR=%(TestDirectories.Identity)"
Condition=" '$(BuildWrappers)'=='true' " />
<!-- Execution -->
<MSBuild Projects="$(MSBuildProjectFile)"
Targets="CreateTestOverlay"
Condition=" '$(GenerateRuntimeLayout)'=='true' "/>
<MSBuild Projects="$(MSBuildProjectFile)" Targets="RunTests"
Condition=" '$(RunTests)'=='true' "/>
</Target>
<Target Name="Clean">
<RemoveDir Condition=" '$(BuildWrappers)'=='true'" Directories="$(XunitWrapperGeneratedCSDirBase);$(XunitWrapperOutputIntermediatedDirBase)" ContinueOnError="WarnAndContinue" />
</Target>
</Project>
|