Add support for testing via ILLINK
authorSwaroop Sridhar <Swaroop.Sridhar@microsoft.com>
Wed, 15 Mar 2017 17:40:25 +0000 (10:40 -0700)
committerGitHub <noreply@github.com>
Wed, 15 Mar 2017 17:40:25 +0000 (10:40 -0700)
Add support for testing via ILLINK

This commit has the following changes:
1) Setup the testing infrastructure to run the CoreCLR tests after linking through ILLinker
    `runtest.cmd /link <path-to-illink.exe>`
2) The linker is taken as an argument for runtest.cmd, typically the corebuild of
    https://github.com/mono/linker
3) Tests are run by linking the test binaries and all libraries except `System.Private.Corelib.dll`
4) For tests that use reflection, setup Reflection roots in source directories as `<test>.reflect.xml`

Commit migrated from https://github.com/dotnet/coreclr/commit/7f8ba1a8bd20ce2330b8d733f1e51959470fdd8f

19 files changed:
src/coreclr/tests/runtest.cmd
src/coreclr/tests/src/CLRTest.Execute.Batch.targets
src/coreclr/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.csproj
src/coreclr/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.reflect.xml [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/ReflectObj/reflectobj.csproj
src/coreclr/tests/src/GC/Scenarios/ReflectObj/reflectobj.reflect.xml [new file with mode: 0644]
src/coreclr/tests/src/JIT/Regression/Dev11/External/dev11_13748/ReflectOnField.ilproj
src/coreclr/tests/src/JIT/Regression/Dev11/External/dev11_13748/ReflectOnField.reflect.xml [new file with mode: 0644]
src/coreclr/tests/src/Loader/classloader/MethodImpl/self_override1.ilproj
src/coreclr/tests/src/Loader/classloader/MethodImpl/self_override1.reflect.xml [new file with mode: 0644]
src/coreclr/tests/src/Loader/classloader/MethodImpl/self_override2.ilproj
src/coreclr/tests/src/Loader/classloader/MethodImpl/self_override2.reflect.xml [new file with mode: 0644]
src/coreclr/tests/src/Loader/classloader/MethodImpl/self_override3.ilproj
src/coreclr/tests/src/Loader/classloader/MethodImpl/self_override3.reflect.xml [new file with mode: 0644]
src/coreclr/tests/src/Loader/classloader/regressions/14610/TestObjectGetTypeVirtual.csproj
src/coreclr/tests/src/Loader/classloader/regressions/14610/TestObjectGetTypeVirtual.reflect.xml [new file with mode: 0644]
src/coreclr/tests/src/Loader/classloader/regressions/dev11_95728/dev11_95728.csproj
src/coreclr/tests/src/Loader/classloader/regressions/dev11_95728/dev11_95728.reflect.xml [new file with mode: 0644]
src/coreclr/tests/src/dir.targets

index 9d54289..89e2571 100644 (file)
@@ -80,6 +80,8 @@ if /i "%1" == "jitdisasm"             (set __JitDisasm=1&shift&goto Arg_Loop)
 if /i "%1" == "GenerateLayoutOnly"    (set __GenerateLayoutOnly=1&shift&goto Arg_Loop)
 if /i "%1" == "PerfTests"             (set __PerfTests=true&shift&goto Arg_Loop)
 if /i "%1" == "runcrossgentests"      (set RunCrossGen=true&shift&goto Arg_Loop)
+if /i "%1" == "link"                  (set DoLink=true&set ILLINK=%2&shift&shift&goto Arg_Loop)
+
 REM change it to COMPlus_GCStress when we stop using xunit harness
 if /i "%1" == "gcstresslevel"         (set __GCSTRESSLEVEL=%2&set __TestTimeout=1800000&shift&shift&goto Arg_Loop)
 
@@ -399,6 +401,7 @@ echo TestEnv- Optional parameter - this will run a custom script to set custom t
 echo VSVersion- Optional parameter - VS2015 or VS2017 ^(default: VS2017^)
 echo AgainstPackages - Optional parameter - this indicates that we are running tests that were built against packages
 echo GenerateLayoutOnly - If specified will not run the tests and will only create the Runtime Dependency Layout
+echo link "ILlink"      - Runs the tests after linking via ILlink
 echo RunCrossgenTests   - Runs ReadytoRun tests
 echo jitstress n        - Runs the tests with COMPlus_JitStress=n
 echo jitstressregs n    - Runs the tests with COMPlus_JitStressRegs=n
index 5de78b4..fa6d458 100644 (file)
@@ -33,17 +33,21 @@ WARNING:   When setting properties based on their current state (for example:
        <!-- https://github.com/dotnet/coreclr/issues/2481. Delete /raweh to ildasm once it is resolved.-->
       <IlasmRoundTripBatchScript Condition="'$(IlasmRoundTrip)'=='true'">
       <![CDATA[
-ECHO %CORE_ROOT%\ildasm.exe /raweh /out=$(DisassemblyName) $(InputAssemblyName)
-%CORE_ROOT%\ildasm.exe /raweh /out=$(DisassemblyName) $(InputAssemblyName)
-IF NOT "!ERRORLEVEL!"=="0" (
-  ECHO EXECUTION OF ILDASM - FAILED !ERRORLEVEL!
-  Exit /b 1
-)
-ECHO %CORE_ROOT%\ilasm.exe /output=$(TargetAssemblyName) $(_IlasmSwitches) $(DisassemblyName)
-%CORE_ROOT%\ilasm.exe /output=$(TargetAssemblyName) $(_IlasmSwitches) $(DisassemblyName)
-IF NOT "!ERRORLEVEL!"=="0" (
-  ECHO EXECUTION OF ILASM - FAILED !ERRORLEVEL!
-  Exit /b 1
+REM Disable Ilasm round-tripping for Linker tests.
+REM Todo: Ilasm round-trip on linked binaries.
+IF NOT DEFINED DoLink ( 
+  ECHO %CORE_ROOT%\ildasm.exe /raweh /out=$(DisassemblyName) $(InputAssemblyName)
+  %CORE_ROOT%\ildasm.exe /raweh /out=$(DisassemblyName) $(InputAssemblyName)
+  IF NOT "!ERRORLEVEL!"=="0" (
+    ECHO EXECUTION OF ILDASM - FAILED !ERRORLEVEL!
+    Exit /b 1
+  )
+  ECHO %CORE_ROOT%\ilasm.exe /output=$(TargetAssemblyName) $(_IlasmSwitches) $(DisassemblyName)
+  %CORE_ROOT%\ilasm.exe /output=$(TargetAssemblyName) $(_IlasmSwitches) $(DisassemblyName)
+  IF NOT "!ERRORLEVEL!"=="0" (
+    ECHO EXECUTION OF ILASM - FAILED !ERRORLEVEL!
+    Exit /b 1
+  )
 )
       ]]>
       </IlasmRoundTripBatchScript>
@@ -203,7 +207,72 @@ Exit /b 0
       </BatchCLRTestExecutionScriptArgument>
     </ItemGroup>
 
-    <PropertyGroup> 
+      <PropertyGroup>
+          <ReflectionRootsXml>$(MSBuildProjectName).reflect.xml</ReflectionRootsXml>
+          <BatchLinkerTestLaunchCmds><![CDATA[
+REM Linker commands
+
+set LinkBin=__Link
+set Assemblies=-a System.Private.CoreLib
+
+IF defined DoLink ( 
+    IF NOT EXIST !ILLINK! (
+      ECHO ILLink [%ILLINK%] Not Found
+      Exit /b 1
+    )
+    
+    REM Clean up old Linked binaries, if any
+    IF EXIST %LinkBin% rmdir /s /q %LinkBin%
+    
+    REM Remove Native images, since the goal is to run from Linked binaries
+    del /q /f *.ni.* 2> nul
+
+    REM Use hints for reflection roots, if provided in $(ReflectionRootsXml)
+    IF EXIST $(ReflectionRootsXml) set ReflectionRoots=-x $(ReflectionRootsXml)
+
+    REM Include all .exe files in this directory as entry points (some tests had multiple .exe file modules)
+    FOR /F "delims=" %%E IN ('dir /b *.exe *.dll') DO SET Assemblies=!Assemblies! -a %%~nE
+
+    REM Run dotnet-linker
+    REM Run the Linker such that all assemblies except System.Private.Corlib.dll are linked
+    REM Debug symbol generation needs some fixes, and is currently omitted.
+    REM Once this is fixed, add -b true option.
+    ECHO %ILLINK% -out %LinkBin% -d %CORE_ROOT% -c link -l none -t !Assemblies! !ReflectionRoots!
+    %ILLINK% -out %LinkBin% -d %CORE_ROOT% -c link -l none -t !Assemblies! !ReflectionRoots!
+    IF NOT "!ERRORLEVEL!"=="0" (
+      ECHO EXECUTION OF %DOTNETLINK% - FAILED !ERRORLEVEL!
+      IF EXIST %LinkBin% rmdir /s /q %LinkBin%
+      Exit /b 1
+    )
+
+    REM Copy CORECLR native binaries to %LinkBin%, so that we can run the test based on that directory
+    copy %CORE_ROOT%\clrjit.dll %LinkBin% > nul 2> nul
+    copy %CORE_ROOT%\coreclr.dll %LinkBin% > nul 2> nul
+    copy %CORE_ROOT%\mscorrc.dll %LinkBin% > nul 2> nul
+    copy %CORE_ROOT%\CoreRun.exe %LinkBin% > nul 2> nul
+
+    REM Copy some files that may be arguments
+    copy *.txt %LinkBin% > nul 2> nul
+
+    set ExePath=%LinkBin%\$(InputAssemblyName)
+    set CORE_ROOT=%~dp0%LinkBin%
+)
+]]>
+          </BatchLinkerTestLaunchCmds>
+          <BatchLinkerTestCleanupCmds>
+              <![CDATA[
+REM Clean up the LinkBin directories after test execution.
+REM Otherwise, RunTests may run out of disk space.
+
+if defined DoLink (
+    if not defined KeepLinkedBinaries (
+        IF EXIST %LinkBin% rmdir /s /q %LinkBin%
+    )
+)              
+]]>
+          </BatchLinkerTestCleanupCmds>
+      </PropertyGroup>      
+      <PropertyGroup>      
       <_CLRTestRunFile Condition="'$(CLRTestIsHosted)'=='true'">"%CORE_ROOT%\corerun.exe"</_CLRTestRunFile>
       <BatchCLRTestLaunchCmds><![CDATA[
 IF NOT "%CLRCustomTestLauncher%"=="" (
@@ -213,21 +282,28 @@ IF NOT "%CLRCustomTestLauncher%"=="" (
 )
       ]]></BatchCLRTestLaunchCmds>
       <BatchCLRTestLaunchCmds Condition=" '$(IlasmRoundTrip)'=='true' "><![CDATA[
-$(BatchCLRTestLaunchCmds)
-ECHO %LAUNCHER% $(TargetAssemblyName) %CLRTestExecutionArguments% %Host_Args%
-%LAUNCHER% $(TargetAssemblyName) %CLRTestExecutionArguments% %Host_Args%
-
-IF NOT "!ERRORLEVEL!"=="%CLRTestExpectedExitCode%" (
-  ECHO END EXECUTION OF IL{D}ASM BINARY - FAILED !ERRORLEVEL! vs %CLRTestExpectedExitCode%
-  ECHO FAILED
-  Exit /b 1
+  $(BatchCLRTestLaunchCmds)
+IF NOT DEFINED DoLink ( 
+  ECHO %LAUNCHER% $(TargetAssemblyName) %CLRTestExecutionArguments% %Host_Args%
+  %LAUNCHER% $(TargetAssemblyName) %CLRTestExecutionArguments% %Host_Args%
+
+  IF NOT "!ERRORLEVEL!"=="%CLRTestExpectedExitCode%" (
+    ECHO END EXECUTION OF IL{D}ASM BINARY - FAILED !ERRORLEVEL! vs %CLRTestExpectedExitCode%
+    ECHO FAILED
+    Exit /b 1
+  )
 )
       ]]></BatchCLRTestLaunchCmds>
-      <BatchCLRTestLaunchCmds Condition="'$(CLRTestKind)' == 'BuildAndRun'"><![CDATA[
+      <BatchCLRTestLaunchCmds Condition="'$(CLRTestKind)' == 'BuildAndRun'">
+    <![CDATA[
+set ExePath=$(InputAssemblyName)
+$(BatchLinkerTestLaunchCmds)
 $(BatchCLRTestLaunchCmds)
-ECHO %LAUNCHER% $(InputAssemblyName) %CLRTestExecutionArguments%
-%LAUNCHER% $(InputAssemblyName) %CLRTestExecutionArguments%
+
+ECHO %LAUNCHER% %ExePath% %CLRTestExecutionArguments%
+%LAUNCHER% %ExePath% %CLRTestExecutionArguments%
 set CLRTestExitCode=!ERRORLEVEL!
+$(BatchLinkerTestCleanupCmds)
       ]]></BatchCLRTestLaunchCmds>
 
       <BatchCLRTestLaunchCmds Condition="'$(CLRTestKind)' == 'RunOnly'"><![CDATA[
index bc95b07..7f64437 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="12.0" DefaultTargets="Build;CopyReflectionRoots" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
diff --git a/src/coreclr/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.reflect.xml b/src/coreclr/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.reflect.xml
new file mode 100644 (file)
index 0000000..c7c5a30
--- /dev/null
@@ -0,0 +1,5 @@
+<linker>
+    <assembly fullname="ClosedStatic">
+        <type fullname="*" required="true" />
+    </assembly>
+</linker>
index 9890c83..c2a22b8 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="12.0" DefaultTargets="Build;CopyReflectionRoots" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/ReflectObj/reflectobj.reflect.xml b/src/coreclr/tests/src/GC/Scenarios/ReflectObj/reflectobj.reflect.xml
new file mode 100644 (file)
index 0000000..2754139
--- /dev/null
@@ -0,0 +1,5 @@
+<linker>
+    <assembly fullname="reflectobj">
+        <type fullname="*" required="true" />
+    </assembly>
+</linker>
index fc143e2..78baf3b 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="12.0" DefaultTargets="Build;CopyReflectionRoots" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
diff --git a/src/coreclr/tests/src/JIT/Regression/Dev11/External/dev11_13748/ReflectOnField.reflect.xml b/src/coreclr/tests/src/JIT/Regression/Dev11/External/dev11_13748/ReflectOnField.reflect.xml
new file mode 100644 (file)
index 0000000..9b45130
--- /dev/null
@@ -0,0 +1,5 @@
+<linker>
+    <assembly fullname="reflectOnField">
+        <type fullname="*" required="true" />
+    </assembly>
+</linker>
index a383c04..f3b5392 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="12.0" DefaultTargets="Build;CopyReflectionRoots" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
   <PropertyGroup>
     <AssemblyName>self_override1</AssemblyName>
diff --git a/src/coreclr/tests/src/Loader/classloader/MethodImpl/self_override1.reflect.xml b/src/coreclr/tests/src/Loader/classloader/MethodImpl/self_override1.reflect.xml
new file mode 100644 (file)
index 0000000..4d01f1a
--- /dev/null
@@ -0,0 +1,5 @@
+<linker>
+    <assembly fullname="self_override1">
+        <type fullname="*" required="true" />
+    </assembly>
+</linker>
index 32c420b..fbd9b90 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="12.0" DefaultTargets="Build;CopyReflectionRoots" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
   <PropertyGroup>
     <AssemblyName>self_override2</AssemblyName>
diff --git a/src/coreclr/tests/src/Loader/classloader/MethodImpl/self_override2.reflect.xml b/src/coreclr/tests/src/Loader/classloader/MethodImpl/self_override2.reflect.xml
new file mode 100644 (file)
index 0000000..90d85f5
--- /dev/null
@@ -0,0 +1,5 @@
+<linker>
+    <assembly fullname="self_override2">
+        <type fullname="*" required="true" />
+    </assembly>
+</linker>
index c1b9eec..82a9be3 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="12.0" DefaultTargets="Build;CopyReflectionRoots" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
   <PropertyGroup>
     <AssemblyName>self_override3</AssemblyName>
diff --git a/src/coreclr/tests/src/Loader/classloader/MethodImpl/self_override3.reflect.xml b/src/coreclr/tests/src/Loader/classloader/MethodImpl/self_override3.reflect.xml
new file mode 100644 (file)
index 0000000..0836d93
--- /dev/null
@@ -0,0 +1,5 @@
+<linker>
+    <assembly fullname="self_override3">
+        <type fullname="*" required="true" />
+    </assembly>
+</linker>
index 64b24ce..be180bb 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="12.0" DefaultTargets="Build;CopyReflectionRoots" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
   <PropertyGroup>
     <AssemblyName>TestObjectGetTypeVirtual</AssemblyName>
diff --git a/src/coreclr/tests/src/Loader/classloader/regressions/14610/TestObjectGetTypeVirtual.reflect.xml b/src/coreclr/tests/src/Loader/classloader/regressions/14610/TestObjectGetTypeVirtual.reflect.xml
new file mode 100644 (file)
index 0000000..b052d52
--- /dev/null
@@ -0,0 +1,5 @@
+<linker>
+    <assembly fullname="TestObjectGetTypeVirtual">
+        <type fullname="*" required="true" />
+    </assembly>
+</linker>
index 893005c..8231c2a 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="12.0" DefaultTargets="Build;CopyReflectionRoots" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
   <PropertyGroup>
     <AssemblyName>dev11_95728</AssemblyName>
diff --git a/src/coreclr/tests/src/Loader/classloader/regressions/dev11_95728/dev11_95728.reflect.xml b/src/coreclr/tests/src/Loader/classloader/regressions/dev11_95728/dev11_95728.reflect.xml
new file mode 100644 (file)
index 0000000..b74972a
--- /dev/null
@@ -0,0 +1,9 @@
+<linker>
+    <assembly fullname="dev11_95728">
+        <type fullname="*" required="true" />
+    </assembly>
+    <assembly fullname="System.Linq.Expressions">
+     <!-- - Called by System.Linq.Expressions.Expression:CreateLambda --> 
+     <type fullname="System.Linq.Expressions.Expression`1" required="true" /> 
+    </assembly>
+</linker>
index 2cc051d..5c2b077 100644 (file)
 
   </Target>
 
+  <Target Name="CopyReflectionRoots">  
+    <Copy SourceFiles="$(AssemblyName).reflect.xml" 
+          DestinationFolder="$(OutputPath)"
+         Condition="Exists('$(AssemblyName).reflect.xml')"/>  
+  </Target>  
 </Project>