Tweak ObjectStackAllocationTests so that they work correctly under crossgen2 (#40096)
authorDavid Wrighton <davidwr@microsoft.com>
Wed, 29 Jul 2020 20:25:00 +0000 (13:25 -0700)
committerGitHub <noreply@github.com>
Wed, 29 Jul 2020 20:25:00 +0000 (13:25 -0700)
- Add a mechanism for passing arbitrary arguments to the crossgen2 process while running crossgen2 tests
- Pass the `--codegenopt JitObjectStackAllocation=1` when compiling this test with Crossgen2. This will result in enabling the object stack allocation feature during compilation
- As Crossgen2 currently disregards the debuggable attribute when deciding codegen mode, detect the presence running crossgen2 and expect allocation to occur on the stack even if S.P.C is debuggable

src/coreclr/tests/issues.targets
src/coreclr/tests/src/CLRTest.CrossGen.targets
src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs
src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.csproj

index 2438937..dc65eef 100644 (file)
         <ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/tailcall_v4/hijacking/*">
             <Issue>https://github.com/dotnet/runtime/issues/7597</Issue>
         </ExcludeList>
-        <ExcludeList Include="$(XunitTestBinBase)/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests/*">
-            <Issue>Not compatible with crossgen2</Issue>
-        </ExcludeList>
         <ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/clr-x64-JIT/v4.0/devdiv374539/DevDiv_374539/*">
             <Issue>https://github.com/dotnet/runtime/issues/32732</Issue>
         </ExcludeList>
index 926f6ec..3460ed5 100644 (file)
@@ -72,6 +72,8 @@ if [ ! -z ${RunCrossGen2+x} ]%3B then
       fi
     fi
 
+    ExtraCrossGen2Args+=" $(CrossGen2TestExtraArguments)"
+
     if [ ! -z ${LargeVersionBubble+x} ]%3B then
         ExtraCrossGen2Args+=" --inputbubble"
     fi
@@ -186,6 +188,8 @@ if defined RunCrossGen (
 )
 REM CrossGen2 Script
 if defined RunCrossGen2 (
+    set ExtraCrossGen2Args=!ExtraCrossGen2Args! $(CrossGen2TestExtraArguments)
+
     if defined LargeVersionBubble ( set ExtraCrossGen2Args=!ExtraCrossGen2Args! --inputbubble)
     call :TakeLock
     set CrossGen2Status=0
index 1c06863..639c44a 100644 (file)
@@ -110,7 +110,7 @@ namespace ObjectStackAllocation
                 Console.WriteLine("GCStress is enabled");
                 expectedAllocationKind = AllocationKind.Undefined;
             }
-            else if (!SPCOptimizationsEnabled()) {
+            else if (!SPCOptimizationsEnabled() && !Crossgen2Test()) {
                 Console.WriteLine("System.Private.CoreLib.dll optimizations are disabled");
                 expectedAllocationKind = AllocationKind.Heap;
             }
@@ -181,6 +181,12 @@ namespace ObjectStackAllocation
             return Environment.GetEnvironmentVariable("COMPlus_GCStress") != null;
         }
 
+        static bool Crossgen2Test()
+        {
+            // CrossGen2 doesn't respect the debuggable attribute
+            return Environment.GetEnvironmentVariable("RunCrossGen2") != null;
+        }
+
         static void CallTestAndVerifyAllocation(Test test, int expectedResult, AllocationKind expectedAllocationsKind)
         {
             long allocatedBytesBefore = GC.GetAllocatedBytesForCurrentThread();
index 655a42c..bfd9e53 100644 (file)
@@ -10,6 +10,7 @@
     <Compile Include="$(MSBuildProjectName).cs" />
   </ItemGroup>
   <PropertyGroup>
+    <CrossGen2TestExtraArguments>--codegenopt JitObjectStackAllocation=1</CrossGen2TestExtraArguments>
     <CLRTestBatchPreCommands><![CDATA[
 $(CLRTestBatchPreCommands)
 set COMPlus_TieredCompilation=0