summaryrefslogtreecommitdiff
path: root/tests/helixprep.proj
blob: ea71dbadae6861cac81b0bc9af3ae513ffe2db77 (plain)
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
<Project ToolsVersion="12.0" DefaultTargets="ArchiveAll" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <UsingTask TaskName="ZipFileCreateFromDirectory" AssemblyFile="$(ToolsDir)\net45\Microsoft.DotNet.Build.Tasks.dll"/>
  
  <Import Project="dir.props" />
  <Import Project="..\dir.props" />

  <PropertyGroup>
    <DiscoveryDirectory>$(TestWorkingDir)</DiscoveryDirectory>
    <CoreRootDir Condition="'$(RuntimeID)' == '' ">$(CORE_ROOT)</CoreRootDir>
    <CoreRootDir Condition="'$(RuntimeID)' != '' ">$(CORE_OVERLAY)</CoreRootDir>
    <CoreRootName Condition="'$(RuntimeID)' == '' ">Core_Root_Windows_NT-$(__BuildArch)</CoreRootName>
    <CoreRootName Condition="'$(RuntimeID)' != '' ">Core_Root_$(RuntimeID)</CoreRootName>
  </PropertyGroup>

  <ItemGroup>
    <TestCmds Include="$(DiscoveryDirectory)\**\*.cmd" ></TestCmds>
    <XunitDlls Include="$(DiscoveryDirectory)\*\*.XUnitWrapper.dll" ></XunitDlls>
    <RequiresSigningFilesToDelete Include="$(DiscoveryDirectory)\**\*.requires_signing" />
  </ItemGroup>

  <!-- Build the platform-specific wrapper to run an individual xunit wrapper -->

  <Target Name="GenerateWrapperExecutables"
    Inputs="@(XunitDlls)"
    Outputs="$(TestWorkingDir)*\runtests.cmd" >

    <MSBuild Projects="helixprep.proj"
             Properties="BuildPath=%(XunitDlls.RootDir)%(XunitDlls.Directory);ProjectName=%(XunitDlls.Filename)%(XunitDlls.Extension)"
             Targets="GenerateWrapperCmd" />

    <MSBuild Projects="helixprep.proj"
             Properties="BuildPath=%(XunitDlls.RootDir)%(XunitDlls.Directory);ProjectName=%(XunitDlls.Filename)%(XunitDlls.Extension)"
             Targets="GenerateWrapperSh" />
  </Target>

  <!-- Zip each top-level test folder to send to Helix -->

  <Target Name="ArchiveTests"
    Inputs="@(XunitDlls)"
    Outputs="$(TestWorkingDir)archive\**" >
    
    <Copy SourceFiles="$(CORE_ROOT)\xunit.console.netcore.exe"
          DestinationFolder="%(XunitDlls.RootDir)%(XunitDlls.Directory)"
    />
    <Message Text="Deleting '.requires_signing' files to avoid file name lengths exceeding MAX_PATH" Importance="Low" />
    <Delete Files="@(RequiresSigningFilesToDelete)" />
    <MSBuild Projects="helixprep.proj"
             Properties="BuildPath=%(XunitDlls.RootDir)%(XunitDlls.Directory);ProjectName=%(XunitDlls.Filename);BuildArchiveDir=$(TestWorkingDir)archive\tests\"
             Targets="ArchiveBuild" />
  </Target>

  <!-- Zip Core_Root & Packages payload to send to Helix -->

  <Target Name="ArchiveCoreRoot"
    Inputs="$(CoreRootDir)"
    Outputs="$(TestWorkingDir)archive\Core_Root" >
    <MSBuild Projects="helixprep.proj"
             Properties="BuildPath=$(CoreRootDir);ProjectName=$(CoreRootName);BuildArchiveDir=$(TestWorkingDir)archive\Core_Root\"
             Targets="ArchiveBuild" />

    <!-- Make dummy packages.zip to upload to Helix -->
    <PropertyGroup>
      <DummyDir>$(TestWorkingDir)\archive\dummy</DummyDir>
      <DummyPackageDir>$(TestWorkingDir)\archive\packages</DummyPackageDir>
    </PropertyGroup>

    <MakeDir Directories="$(DummyDir)" />
    <MakeDir Directories="$(DummyPackageDir)" />
    <ZipFileCreateFromDirectory SourceDirectory="$(DummyDir)" DestinationArchive="$(DummyPackageDir)\Packages.zip" OverwriteDestination="true" />
  </Target>

  <!-- Generate wrapper .cmd file for an Xunit wrapper -->
  <Target Name="GenerateWrapperCmd"
    Condition="'$(RuntimeID)' == '' ">

    <PropertyGroup>
      <WrapperCmdContents>
        <![CDATA[
@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION
pushd %~dp0

set CORE_ROOT=%HELIX_CORRELATION_PAYLOAD%

ECHO BEGIN EXECUTION
ECHO %HELIX_CORRELATION_PAYLOAD%\CoreRun.exe %HELIX_WORKITEM_PAYLOAD%\xunit.console.netcore.exe %HELIX_WORKITEM_PAYLOAD%\$(ProjectName) -noshadow -xml testResults.xml -notrait category=outerloop -notrait category=failing
%HELIX_CORRELATION_PAYLOAD%\CoreRun.exe %HELIX_WORKITEM_PAYLOAD%\xunit.console.netcore.exe %HELIX_WORKITEM_PAYLOAD%\$(ProjectName) -noshadow -xml testResults.xml -notrait category=outerloop -notrait category=failing

echo Finished running tests. Exit code = %ERRORLEVEL%
EXIT /B %ERRORLEVEL%

        ]]>
      </WrapperCmdContents>
    </PropertyGroup>

    <!-- Write the file -->
    <WriteLinesToFile
      File="$(BuildPath)\runtests.cmd"
      Lines="$(WrapperCmdContents)"
      Overwrite="true" />

  </Target>

  <Target Name="GenerateWrapperSh"
    Condition="'$(RuntimeID)' != '' ">

    <!-- Need to force in Unix line endings for Shell script -->
    <PropertyGroup>
      <WrapperShContents>#!/bin/sh%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)%0a</WrapperShContents> 
      <WrapperShContents>$(WrapperShContents)export CORE_ROOT="$HELIX_CORRELATION_PAYLOAD"%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)for scriptFilePath in %24(find . -type f -iname '%2A.sh' ! -iname "runtests.sh" | sort)%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)do%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents) perl -pi -e 's/\r\n|\n|\r/\n/g' "%24scriptFilePath"%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)done%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)echo BEGIN EXECUTION%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)echo "%24{HELIX_CORRELATION_PAYLOAD}/corerun" %24HELIX_WORKITEM_PAYLOAD/xunit.console.netcore.exe %24HELIX_WORKITEM_PAYLOAD/$(ProjectName) -noshadow -xml testResults.xml -notrait category=outerloop -notrait category=failing%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)"%24{HELIX_CORRELATION_PAYLOAD}/corerun" %24HELIX_WORKITEM_PAYLOAD/xunit.console.netcore.exe %24HELIX_WORKITEM_PAYLOAD/$(ProjectName) -noshadow -xml testResults.xml -notrait category=outerloop -notrait category=failing%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)ErrorLevel=%24%3F%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)echo Finished running tests. Exit code = %24ErrorLevel%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)exit %24ErrorLevel%0a</WrapperShContents>

    </PropertyGroup>

    <!-- Write the file -->
    <WriteLinesToFile
      File="$(BuildPath)\runtests.sh"
      Lines="$(WrapperShContents)"
      Overwrite="true" />

  </Target>

  <!-- archive the test binaries along with some supporting files -->
  <Target Name="ArchiveBuild">
    <PropertyGroup Condition="'$(ProjectName)'==''">
      <TestProjectName>$(MSBuildProjectName)</TestProjectName>
    </PropertyGroup>

    <!-- the project json and runner script files need to be included in the archive -->
    <MakeDir Directories="$(BuildArchiveDir)" />
    <ZipFileCreateFromDirectory SourceDirectory="$(BuildPath)" DestinationArchive="$(BuildArchiveDir)$(ProjectName).zip" OverwriteDestination="true" />
  </Target>

  <!-- Default target to run - builds executables & archives everything needed for Helix run -->

  <Target Name="ArchiveAll" >
    <MSBuild Projects="helixprep.proj"
             Targets="GenerateWrapperExecutables;ArchiveTests;ArchiveCoreRoot" />
  </Target>

</Project>