test FixedAddressValueType and RuntimeWrappedException
authorRama Krishnan Raghupathy <ramarag@microsoft.com>
Thu, 15 Sep 2016 00:03:11 +0000 (17:03 -0700)
committerRama Krishnan Raghupathy <ramarag@microsoft.com>
Tue, 20 Sep 2016 01:06:53 +0000 (18:06 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/a3d93afa96c7bf488347d139c5f0affb0517674c

src/coreclr/tests/src/CLRTest.Execute.targets
src/coreclr/tests/src/CLRTest.Jit.targets [new file with mode: 0644]
src/coreclr/tests/src/baseservices/compilerservices/FixedAddressValueType/FixedAddressValueType.cs [new file with mode: 0644]
src/coreclr/tests/src/baseservices/compilerservices/FixedAddressValueType/FixedAddressValueType.csproj [new file with mode: 0644]
src/coreclr/tests/src/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException.cs [new file with mode: 0644]
src/coreclr/tests/src/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException.csproj [new file with mode: 0644]
src/coreclr/tests/src/baseservices/compilerservices/RuntimeWrappedException/StringThrower.il [new file with mode: 0644]
src/coreclr/tests/src/baseservices/compilerservices/RuntimeWrappedException/StringThrower.ilproj [new file with mode: 0644]

index 17cb69f..b49785b 100644 (file)
@@ -105,6 +105,7 @@ This file contains the logic for providing Execution Script generation.
     <BatchScriptSnippetGen></BatchScriptSnippetGen>
   </PropertyGroup>
  
+  <Import Project="CLRTest.Jit.targets" />
   <Import Project="CLRTest.CrossGen.targets" />
   <Import Project="CLRTest.GC.targets" />
   <Import Project="CLRTest.Execute.*.targets" />
diff --git a/src/coreclr/tests/src/CLRTest.Jit.targets b/src/coreclr/tests/src/CLRTest.Jit.targets
new file mode 100644 (file)
index 0000000..c295634
--- /dev/null
@@ -0,0 +1,35 @@
+
+<!--
+***********************************************************************************************
+CLRTest.Jit.targets
+
+WARNING:  DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
+          created a backup copy.  Incorrect changes to this file will make it
+          impossible to load or build your projects from the command-line or the IDE.
+
+This file contains the logic for generating command scripts for special GC tests.
+
+WARNING:   When setting properties based on their current state (for example:
+           <Foo Condition="'$(Foo)'==''>Bar</Foo>).  Be very careful.  Another script generation
+           target might be trying to do the same thing.  It's better to avoid this by instead setting a new property.
+           
+           Additionally, be careful with itemgroups.  Include will propagate outside of the target too!
+
+***********************************************************************************************
+-->
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+   <PropertyGroup Condition="$(RunWithGcStress) != ''" >
+      <CLRTestBatchPreCommands>
+<![CDATA[
+      $(CLRTestBatchPreCommands)
+set COMPlus_GCStress=$(RunWithGcStress)
+    ]]>
+      </CLRTestBatchPreCommands>
+      <BashCLRTestPreCommands>
+<![CDATA[
+      $(BashCLRTestPreCommands)
+export COMPlus_GCStress=$(RunWithGcStress)
+    ]]>
+     </BashCLRTestPreCommands>
+   </PropertyGroup>
+</Project> 
diff --git a/src/coreclr/tests/src/baseservices/compilerservices/FixedAddressValueType/FixedAddressValueType.cs b/src/coreclr/tests/src/baseservices/compilerservices/FixedAddressValueType/FixedAddressValueType.cs
new file mode 100644 (file)
index 0000000..bf10d81
--- /dev/null
@@ -0,0 +1,60 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+using System;
+using System.Runtime.CompilerServices;
+
+public struct Age {
+   public int years;
+   public int months;
+}
+
+public class FreeClass
+{
+   public static Age FreeAge;
+
+   public static unsafe IntPtr AddressOfFreeAge()
+   { 
+      fixed (Age* pointer = &FreeAge) 
+      { return (IntPtr) pointer; } 
+   }
+}
+
+public class FixedClass
+{
+   [FixedAddressValueType]
+   public static Age FixedAge;
+
+   public static unsafe IntPtr AddressOfFixedAge()
+   { 
+      fixed (Age* pointer = &FixedAge) 
+      { return (IntPtr) pointer; } 
+   }   
+}
+
+public class Example
+{
+   public static int Main()
+   {
+      // Get addresses of static Age fields.
+      IntPtr freePtr1 = FreeClass.AddressOfFreeAge();
+
+      IntPtr fixedPtr1 = FixedClass.AddressOfFixedAge();
+
+      // Garbage collection.
+      GC.Collect(3, GCCollectionMode.Forced, true, true);
+      GC.WaitForPendingFinalizers();
+      
+      // Get addresses of static Age fields after garbage collection.
+      IntPtr freePtr2 = FreeClass.AddressOfFreeAge();
+      IntPtr fixedPtr2 = FixedClass.AddressOfFixedAge();
+
+      if(freePtr1 != freePtr2 && fixedPtr1 == fixedPtr2)
+      {
+          return 100;
+      }
+
+      return -1;
+   }
+}
diff --git a/src/coreclr/tests/src/baseservices/compilerservices/FixedAddressValueType/FixedAddressValueType.csproj b/src/coreclr/tests/src/baseservices/compilerservices/FixedAddressValueType/FixedAddressValueType.csproj
new file mode 100644 (file)
index 0000000..72ba0b9
--- /dev/null
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <ReferenceLocalMscorlib>true</ReferenceLocalMscorlib>
+    <CLRTestKind>BuildAndRun</CLRTestKind>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="FixedAddressValueType.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <NoWarn Include="42016,42020,42025,42024" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
diff --git a/src/coreclr/tests/src/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException.cs b/src/coreclr/tests/src/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException.cs
new file mode 100644 (file)
index 0000000..29fb347
--- /dev/null
@@ -0,0 +1,63 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+using System;
+using System.IO;
+using System.Runtime.CompilerServices;
+using System.Runtime.Serialization;
+
+class Test 
+{
+    public static int Main(string[] args)
+    {
+        int retVal = 0;
+        var thrower = new StringThrowerClass();
+        try
+        {
+            thrower.InstanceMethod();
+        }
+
+        catch (RuntimeWrappedException ex)
+        {
+
+           if ( !ex.WrappedException.ToString().Contains("Inside StringThrower") )
+           {
+//             Console.WriteLine("Incorrect exception and/or message. Expected RuntimeWrappedException: An object that does not derive "+
+//                               "from System.Exception has been wrapped in a RuntimeWrappedException.\n But actually got: " + ex.InnerException);
+               retVal = -1;
+           }
+            
+            StreamingContext ctx;
+
+//            TODO: Expose once we have access to FormatterConverter
+//            var info = new SerializationInfo(typeof(RuntimeWrappedException), new FormatterConverter());
+//            ex.GetObjectData(info,ctx);
+//
+            try
+            {
+                ex.GetObjectData(null,ctx);
+            }
+           catch (ArgumentNullException ex1)
+            {
+                retVal = 100;
+            }
+            catch (Exception ex1)
+            {
+               retVal = -1;
+            }
+
+
+        }
+       catch (Exception ex)
+       {
+//        Console.WriteLine("Incorrect exception thrown. Expected RuntimeWrappedException, but actually got: " + ex);
+          retVal = -2;
+       }
+
+
+        return retVal;
+
+
+    }
+}
diff --git a/src/coreclr/tests/src/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException.csproj b/src/coreclr/tests/src/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException.csproj
new file mode 100644 (file)
index 0000000..4b0c5cf
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <ReferenceLocalMscorlib>true</ReferenceLocalMscorlib>
+    <CLRTestKind>BuildAndRun</CLRTestKind>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="RuntimeWrappedException.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+      <ProjectReference Include="StringThrower.ilproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <NoWarn Include="42016,42020,42025,42024" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
diff --git a/src/coreclr/tests/src/baseservices/compilerservices/RuntimeWrappedException/StringThrower.il b/src/coreclr/tests/src/baseservices/compilerservices/RuntimeWrappedException/StringThrower.il
new file mode 100644 (file)
index 0000000..92c9139
--- /dev/null
@@ -0,0 +1,40 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+.assembly extern mscorlib
+{
+  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
+  .ver 2:0:0:0
+}
+
+.assembly StringThrower {}
+
+.class public auto ansi StringThrowerClass
+       extends [mscorlib]System.Object
+{
+   .field public static int32 intStatic
+
+
+  .method public hidebysig instance void 
+          InstanceMethod() cil managed noinlining
+  {
+    .maxstack  8
+
+    ldstr      "Inside StringThrower"
+    throw
+    ret
+  } // end of method A::methodA
+
+
+   .method public hidebysig specialname rtspecialname 
+        instance void  .ctor() cil managed
+   {
+     .maxstack  8
+     ldarg.0
+     call       instance void class [mscorlib]System.Object::.ctor()
+     ret
+   } // end of method Test1::.ctor
+       
+}
diff --git a/src/coreclr/tests/src/baseservices/compilerservices/RuntimeWrappedException/StringThrower.ilproj b/src/coreclr/tests/src/baseservices/compilerservices/RuntimeWrappedException/StringThrower.ilproj
new file mode 100644 (file)
index 0000000..79667cc
--- /dev/null
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="StringThrower.il" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>