From db20f3f1bb8595633a7e16c8900fd401a453a6b5 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Tue, 27 Dec 2016 16:46:08 +0900 Subject: Imported Upstream version 1.0.0.9127 --- .../FixedAddressValueType/FixedAddressValueType.cs | 60 +++++++++++ .../FixedAddressValueType.csproj | 44 +++++++++ .../ExecuteCodeWithGuaranteedCleanup.cs | 62 ++++++++++++ .../ExecuteCodeWithGuaranteedCleanup.csproj | 42 ++++++++ .../RuntimeWrappedException.cs | 63 ++++++++++++ .../RuntimeWrappedException.csproj | 45 +++++++++ .../RuntimeWrappedException/StringThrower.il | 40 ++++++++ .../RuntimeWrappedException/StringThrower.ilproj | 40 ++++++++ .../compilerservices/modulector/moduleCctor.il | 110 +++++++++++++++++++++ .../compilerservices/modulector/moduleCctor.ilproj | 40 ++++++++ .../modulector/runmoduleconstructor.cs | 38 +++++++ .../modulector/runmoduleconstructor.csproj | 45 +++++++++ 12 files changed, 629 insertions(+) create mode 100644 tests/src/baseservices/compilerservices/FixedAddressValueType/FixedAddressValueType.cs create mode 100644 tests/src/baseservices/compilerservices/FixedAddressValueType/FixedAddressValueType.csproj create mode 100644 tests/src/baseservices/compilerservices/RuntimeHelpers/ExecuteCodeWithGuaranteedCleanup.cs create mode 100644 tests/src/baseservices/compilerservices/RuntimeHelpers/ExecuteCodeWithGuaranteedCleanup.csproj create mode 100644 tests/src/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException.cs create mode 100644 tests/src/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException.csproj create mode 100644 tests/src/baseservices/compilerservices/RuntimeWrappedException/StringThrower.il create mode 100644 tests/src/baseservices/compilerservices/RuntimeWrappedException/StringThrower.ilproj create mode 100644 tests/src/baseservices/compilerservices/modulector/moduleCctor.il create mode 100644 tests/src/baseservices/compilerservices/modulector/moduleCctor.ilproj create mode 100644 tests/src/baseservices/compilerservices/modulector/runmoduleconstructor.cs create mode 100644 tests/src/baseservices/compilerservices/modulector/runmoduleconstructor.csproj (limited to 'tests/src/baseservices/compilerservices') diff --git a/tests/src/baseservices/compilerservices/FixedAddressValueType/FixedAddressValueType.cs b/tests/src/baseservices/compilerservices/FixedAddressValueType/FixedAddressValueType.cs new file mode 100644 index 0000000000..bf10d817e5 --- /dev/null +++ b/tests/src/baseservices/compilerservices/FixedAddressValueType/FixedAddressValueType.cs @@ -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/tests/src/baseservices/compilerservices/FixedAddressValueType/FixedAddressValueType.csproj b/tests/src/baseservices/compilerservices/FixedAddressValueType/FixedAddressValueType.csproj new file mode 100644 index 0000000000..19a779194f --- /dev/null +++ b/tests/src/baseservices/compilerservices/FixedAddressValueType/FixedAddressValueType.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + true + BuildAndRun + true + true + + + + + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/baseservices/compilerservices/RuntimeHelpers/ExecuteCodeWithGuaranteedCleanup.cs b/tests/src/baseservices/compilerservices/RuntimeHelpers/ExecuteCodeWithGuaranteedCleanup.cs new file mode 100644 index 0000000000..58cee3ca36 --- /dev/null +++ b/tests/src/baseservices/compilerservices/RuntimeHelpers/ExecuteCodeWithGuaranteedCleanup.cs @@ -0,0 +1,62 @@ +// 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; + +namespace GCD +{ + /// + /// Summary description for Class1. + /// + class GCD + { + private int _val = -2; + private int _exitcode = -1; + public GCD() {} + public int GetExitCode(){ return _exitcode;} + public void g () + { + throw new System.Exception("TryCode test"); + } + public void TryCode0 (object obj) + { + _val = (int)obj; + g(); + } + public void CleanupCode0 (object obj, bool excpThrown) + { + if(excpThrown && ((int)obj == _val)) + { + _exitcode = 100; + } + } + } + + + class GCDTest + { + /// + /// The main entry point for the application. + /// + [STAThread] + static int Main(string[] args) + { + GCD gcd = new GCD(); + RuntimeHelpers.TryCode t = new RuntimeHelpers.TryCode(gcd.TryCode0); + RuntimeHelpers.CleanupCode c = new RuntimeHelpers.CleanupCode(gcd.CleanupCode0); + int val = 21; + try + { + RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(t, c, val); + } + catch (Exception Ex) + { + + } + + return gcd.GetExitCode(); + } + } +} diff --git a/tests/src/baseservices/compilerservices/RuntimeHelpers/ExecuteCodeWithGuaranteedCleanup.csproj b/tests/src/baseservices/compilerservices/RuntimeHelpers/ExecuteCodeWithGuaranteedCleanup.csproj new file mode 100644 index 0000000000..605d11b1f1 --- /dev/null +++ b/tests/src/baseservices/compilerservices/RuntimeHelpers/ExecuteCodeWithGuaranteedCleanup.csproj @@ -0,0 +1,42 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + true + BuildAndRun + + + + + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException.cs b/tests/src/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException.cs new file mode 100644 index 0000000000..29fb347ae1 --- /dev/null +++ b/tests/src/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException.cs @@ -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/tests/src/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException.csproj b/tests/src/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException.csproj new file mode 100644 index 0000000000..4b0c5cf68d --- /dev/null +++ b/tests/src/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException.csproj @@ -0,0 +1,45 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + true + BuildAndRun + + + + + + + + + False + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/baseservices/compilerservices/RuntimeWrappedException/StringThrower.il b/tests/src/baseservices/compilerservices/RuntimeWrappedException/StringThrower.il new file mode 100644 index 0000000000..92c9139f7c --- /dev/null +++ b/tests/src/baseservices/compilerservices/RuntimeWrappedException/StringThrower.il @@ -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/tests/src/baseservices/compilerservices/RuntimeWrappedException/StringThrower.ilproj b/tests/src/baseservices/compilerservices/RuntimeWrappedException/StringThrower.ilproj new file mode 100644 index 0000000000..79667cc7c6 --- /dev/null +++ b/tests/src/baseservices/compilerservices/RuntimeWrappedException/StringThrower.ilproj @@ -0,0 +1,40 @@ + + + + + Debug + AnyCPU + $(MSBuildProjectName) + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Library + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + diff --git a/tests/src/baseservices/compilerservices/modulector/moduleCctor.il b/tests/src/baseservices/compilerservices/modulector/moduleCctor.il new file mode 100644 index 0000000000..06bf6ac12c --- /dev/null +++ b/tests/src/baseservices/compilerservices/modulector/moduleCctor.il @@ -0,0 +1,110 @@ +// 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 moduleCctor {} +.assembly extern FieldTypes +{ + .publickeytoken = (C0 30 5C 36 38 0B A4 29 ) // .0\68..) + .ver 0:0:0:0 +} + + .method private hidebysig specialname rtspecialname static + void .cctor() cil managed + { + .maxstack 8 + nop + ldsfld int32 IntHolder::val + ldc.i4.1 + add + stsfld int32 IntHolder::val +// ldstr "modCctor.txt" +// ldstr "inside .cctor" +// call void [mscorlib]System.IO.File::WriteAllText(string, +// string) + ret + } // end of method Foo::.cctor + + +// =============== CLASS MEMBERS DECLARATION =================== +.class public auto ansi beforefieldinit IntHolder + extends [mscorlib]System.Object +{ + // Fields + .field public static int32 val + + // Methods + .method public hidebysig specialname rtspecialname + instance void .ctor () cil managed + { + // Method begins at RVA 0x2050 + // Code size 8 (0x8) + .maxstack 8 + + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method IntHolder::.ctor + + .method private hidebysig specialname rtspecialname static + void .cctor () cil managed + { + // Method begins at RVA 0x2059 + // Code size 7 (0x7) + .maxstack 8 + + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 IntHolder::val + IL_0006: ret + } // end of method IntHolder::.cctor + + .method public hidebysig static + void Assign ( + int32 arg + ) cil managed + { + // Method begins at RVA 0x2078 + // Code size 8 (0x8) + .maxstack 8 + + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stsfld int32 IntHolder::val + IL_0007: ret + } // end of method IntHolder::Assign + .method public hidebysig static + void Check ( + int32 arg + ) cil managed + { + // Method begins at RVA 0x2050 + // Code size 28 (0x1c) + .maxstack 2 + .locals init ( + [0] bool + ) + + IL_0000: nop + IL_0001: ldsfld int32 IntHolder::val + IL_0006: ldarg.0 + IL_0007: ceq + IL_0009: ldc.i4.0 + IL_000a: ceq + IL_000c: stloc.0 + IL_000d: ldloc.0 + IL_000e: brfalse.s IL_001b + + IL_0010: ldstr "Mod Ctor did not functon correctly" + IL_0015: newobj instance void [mscorlib]System.Exception::.ctor(string) + IL_001a: throw + + IL_001b: ret + } // end of method IntHolder::Check +} // end of class IntHolder diff --git a/tests/src/baseservices/compilerservices/modulector/moduleCctor.ilproj b/tests/src/baseservices/compilerservices/modulector/moduleCctor.ilproj new file mode 100644 index 0000000000..c846e02edb --- /dev/null +++ b/tests/src/baseservices/compilerservices/modulector/moduleCctor.ilproj @@ -0,0 +1,40 @@ + + + + + Debug + AnyCPU + $(MSBuildProjectName) + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Library + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + diff --git a/tests/src/baseservices/compilerservices/modulector/runmoduleconstructor.cs b/tests/src/baseservices/compilerservices/modulector/runmoduleconstructor.cs new file mode 100644 index 0000000000..d1192f167a --- /dev/null +++ b/tests/src/baseservices/compilerservices/modulector/runmoduleconstructor.cs @@ -0,0 +1,38 @@ +// 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.Reflection; +using System.IO; +using System.Runtime.Loader; +using System.Runtime.CompilerServices; +using System.Globalization; + +class RuntimeHelperTest +{ + public static int Main(string[] args) + { + AssemblyLoadContext resolver0 = AssemblyLoadContext.Default; + Assembly asm0 = resolver0.LoadFromAssemblyName(new AssemblyName("moduleCctor")); + Module mod = asm0.ManifestModule; + + RuntimeHelpers.RunModuleConstructor(mod.ModuleHandle); + var oType = asm0.GetType("IntHolder",true); + MethodInfo check = oType.GetMethod("Check"); + MethodInfo assign = oType.GetMethod("Assign"); + + object[] initial = {1}; + object[] final = {100}; + + check.Invoke(null, initial); + assign.Invoke(null, final); + check.Invoke(null, final); + RuntimeHelpers.RunModuleConstructor(mod.ModuleHandle); + check.Invoke(null, final); + + + return 100; + + } +} diff --git a/tests/src/baseservices/compilerservices/modulector/runmoduleconstructor.csproj b/tests/src/baseservices/compilerservices/modulector/runmoduleconstructor.csproj new file mode 100644 index 0000000000..fff05ea610 --- /dev/null +++ b/tests/src/baseservices/compilerservices/modulector/runmoduleconstructor.csproj @@ -0,0 +1,45 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + true + BuildAndRun + + + + + + + + + False + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3