diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2015-05-18 15:17:53 +0200 |
---|---|---|
committer | Jan Vorlicek <janvorli@microsoft.com> | 2015-08-26 21:06:56 +0200 |
commit | 79c84e436d521f347997245724772693979e9f3e (patch) | |
tree | 13a122ccda7f4321d59d65cb70739a7c639cb9cc /tests/src/readytorun | |
parent | 6f3131364edfe08c6c697a5b65279991e14e4d16 (diff) | |
download | coreclr-79c84e436d521f347997245724772693979e9f3e.tar.gz coreclr-79c84e436d521f347997245724772693979e9f3e.tar.bz2 coreclr-79c84e436d521f347997245724772693979e9f3e.zip |
Add ready to run tests
Add tests to verify ready to run handles versioning correctly.
Diffstat (limited to 'tests/src/readytorun')
-rw-r--r-- | tests/src/readytorun/app.config | 39 | ||||
-rw-r--r-- | tests/src/readytorun/main.cs | 325 | ||||
-rw-r--r-- | tests/src/readytorun/mainv1.csproj | 59 | ||||
-rw-r--r-- | tests/src/readytorun/mainv2.csproj | 59 | ||||
-rw-r--r-- | tests/src/readytorun/packages.config | 13 | ||||
-rw-r--r-- | tests/src/readytorun/test.cs | 363 | ||||
-rw-r--r-- | tests/src/readytorun/testv1.csproj | 41 | ||||
-rw-r--r-- | tests/src/readytorun/testv2.csproj | 41 |
8 files changed, 940 insertions, 0 deletions
diff --git a/tests/src/readytorun/app.config b/tests/src/readytorun/app.config new file mode 100644 index 0000000000..7f13fbce41 --- /dev/null +++ b/tests/src/readytorun/app.config @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <runtime> + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> + <dependentAssembly> + <assemblyIdentity name="System.Collections" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Runtime.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + </assemblyBinding> + </runtime> +</configuration>
\ No newline at end of file diff --git a/tests/src/readytorun/main.cs b/tests/src/readytorun/main.cs new file mode 100644 index 0000000000..8604a3ef96 --- /dev/null +++ b/tests/src/readytorun/main.cs @@ -0,0 +1,325 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; +#if CORECLR +using System.Runtime.Loader; +#endif +using System.Reflection; +using System.IO; + +class InstanceFieldTest : MyClass +{ + public int Value; +} + +class InstanceFieldTest2 : InstanceFieldTest +{ + public int Value2; +} + +[StructLayout(LayoutKind.Sequential)] +class InstanceFieldTestWithLayout : MyClassWithLayout +{ + public int Value; +} + +class GrowingBase +{ + MyGrowingStruct s; +} + +class InheritingFromGrowingBase : GrowingBase +{ + public int x; +} + +class Program +{ + static void TestVirtualMethodCalls() + { + var o = new MyClass(); + Assert.AreEqual(o.VirtualMethod(), "Virtual method result"); + + var iface = (IMyInterface)o; + Assert.AreEqual(iface.InterfaceMethod(" "), "Interface result"); + Assert.AreEqual(MyClass.TestInterfaceMethod(iface, "+"), "Interface+result"); + } + + static void TestMovedVirtualMethods() + { + var o = new MyChildClass(); + + Assert.AreEqual(o.MovedToBaseClass(), "MovedToBaseClass"); + Assert.AreEqual(o.ChangedToVirtual(), "ChangedToVirtual"); + + o = null; + + try + { + o.MovedToBaseClass(); + } + catch (NullReferenceException) + { + try + { + o.ChangedToVirtual(); + } + catch (NullReferenceException) + { + return; + } + } + + Assert.AreEqual("NullReferenceException", "thrown"); + } + + + static void TestConstrainedMethodCalls() + { + using (MyStruct s = new MyStruct()) + { + ((Object)s).ToString(); + } + } + + static void TestConstrainedMethodCalls_Unsupported() + { + MyStruct s = new MyStruct(); + s.ToString(); + } + + static void TestInterop() + { + // Verify both intra-module and inter-module PInvoke interop + MyClass.GetTickCount(); + MyClass.TestInterop(); + } + + static void TestStaticFields() + { + MyClass.StaticObjectField = 894; + MyClass.StaticLongField = 4392854; + MyClass.StaticNullableGuidField = new Guid("0D7E505F-E767-4FEF-AEEC-3243A3005673"); + MyClass.ThreadStaticStringField = "Hello"; + MyClass.ThreadStaticIntField = 735; + MyClass.ThreadStaticDateTimeField = new DateTime(2011, 1, 1); + + MyClass.TestStaticFields(); + +#if false // TODO: Enable once LDFTN is supported + Task.Run(() => { + MyClass.ThreadStaticStringField = "Garbage"; + MyClass.ThreadStaticIntField = 0xBAAD; + MyClass.ThreadStaticDateTimeField = DateTime.Now; + }).Wait(); +#endif + + Assert.AreEqual(MyClass.StaticObjectField, 894 + 12345678 /* + 1234 */); + Assert.AreEqual(MyClass.StaticLongField, (long)(4392854 * 456 /* * 45 */)); + Assert.AreEqual(MyClass.StaticNullableGuidField, null); + Assert.AreEqual(MyClass.ThreadStaticStringField, "HelloWorld"); + Assert.AreEqual(MyClass.ThreadStaticIntField, 735/78); + Assert.AreEqual(MyClass.ThreadStaticDateTimeField, new DateTime(2011, 1, 1) + new TimeSpan(123)); + } + + static void TestPreInitializedArray() + { + var a = new int[] { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }; + + int sum = 0; + foreach (var e in a) sum += e; + Assert.AreEqual(sum, 1023); + } + + static void TestMultiDimmArray() + { + var a = new int[2,3,4]; + a[0,1,2] = a[0,0,0] + a[1,1,1]; + a.ToString(); + } + + static void TestGenericVirtualMethod() + { + var o = new MyGeneric<String, Object>(); + Assert.AreEqual(o.GenericVirtualMethod<Program, IEnumerable<String>>(), + "System.StringSystem.ObjectProgramSystem.Collections.Generic.IEnumerable`1[System.String]"); + } + + static void TestMovedGenericVirtualMethod() + { + var o = new MyChildGeneric<Object>(); + + Assert.AreEqual(o.MovedToBaseClass<WeakReference>(), typeof(List<WeakReference>).ToString()); + Assert.AreEqual(o.ChangedToVirtual<WeakReference>(), typeof(List<WeakReference>).ToString()); + + o = null; + + try + { + o.MovedToBaseClass<WeakReference>(); + } + catch (NullReferenceException) + { + try + { + o.ChangedToVirtual<WeakReference>(); + } + catch (NullReferenceException) + { + return; + } + } + + Assert.AreEqual("NullReferenceException", "thrown"); + } + + static void TestInstanceFields() + { + var t = new InstanceFieldTest2(); + t.Value = 123; + t.Value2 = 234; + t.InstanceField = 345; + + Assert.AreEqual(typeof(InstanceFieldTest).GetRuntimeField("Value").GetValue(t), 123); + Assert.AreEqual(typeof(InstanceFieldTest2).GetRuntimeField("Value2").GetValue(t), 234); + Assert.AreEqual(typeof(MyClass).GetRuntimeField("InstanceField").GetValue(t), 345); + } + + static void TestInstanceFieldsWithLayout() + { + var t = new InstanceFieldTestWithLayout(); + t.Value = 123; + + Assert.AreEqual(typeof(InstanceFieldTestWithLayout).GetRuntimeField("Value").GetValue(t), 123); + } + + static void TestInheritingFromGrowingBase() + { + var o = new InheritingFromGrowingBase(); + o.x = 6780; + Assert.AreEqual(typeof(InheritingFromGrowingBase).GetRuntimeField("x").GetValue(o), 6780); + } + + [MethodImplAttribute(MethodImplOptions.NoInlining)] + static void TestGrowingStruct() + { + MyGrowingStruct s = MyGrowingStruct.Construct(); + MyGrowingStruct.Check(ref s); + } + + [MethodImplAttribute(MethodImplOptions.NoInlining)] + static void TestChangingStruct() + { + MyChangingStruct s = MyChangingStruct.Construct(); + s.x++; + MyChangingStruct.Check(ref s); + } + + [MethodImplAttribute(MethodImplOptions.NoInlining)] + static void TestChangingHFAStruct() + { + MyChangingHFAStruct s = MyChangingHFAStruct.Construct(); + MyChangingHFAStruct.Check(s); + } + +#if CORECLR + class MyLoadContext : AssemblyLoadContext + { + public MyLoadContext() + { + } + + public void TestMultipleLoads() + { +#if V2 + string testVersion = "2"; +#else + string testVersion = "1"; +#endif + Assembly a = LoadFromAssemblyPath(Path.Combine(Directory.GetCurrentDirectory(), "NI", "testv" + testVersion + ".ni.dll")); + Assert.AreEqual(AssemblyLoadContext.GetLoadContext(a), this); + } + + protected override Assembly Load(AssemblyName an) + { + throw new NotImplementedException(); + } + } + + static void TestMultipleLoads() + { + try + { + new MyLoadContext().TestMultipleLoads(); + } + catch (FileLoadException e) + { + Assert.AreEqual(e.ToString().Contains("Native image cannot be loaded multiple times"), true); + return; + } + + Assert.AreEqual("FileLoadException", "thrown"); + } +#endif + + static void TestFieldLayoutNGenMixAndMatch() + { + // This test is verifying consistent field layout when ReadyToRun images are combined with NGen images + // "ngen install /nodependencies main.exe" to exercise the interesting case + var o = new ByteChildClass(67); + Assert.AreEqual(o.ChildByte, (byte)67); + } + + static void RunAllTests() + { + TestVirtualMethodCalls(); + TestMovedVirtualMethods(); + + TestConstrainedMethodCalls(); + + TestConstrainedMethodCalls_Unsupported(); + + TestInterop(); + + TestStaticFields(); + + TestPreInitializedArray(); + + TestMultiDimmArray(); + + TestGenericVirtualMethod(); + TestMovedGenericVirtualMethod(); + + TestInstanceFields(); + + TestInstanceFieldsWithLayout(); + + TestInheritingFromGrowingBase(); + + TestGrowingStruct(); + TestChangingStruct(); + TestChangingHFAStruct(); + +#if CORECLR + TestMultipleLoads(); +#endif + + TestFieldLayoutNGenMixAndMatch(); + } + + static int Main() + { + // Run all tests 3x times to exercise both slow and fast paths work + for (int i = 0; i < 3; i++) + RunAllTests(); + + Console.WriteLine("PASSED"); + return Assert.HasAssertFired ? 1 : 100; + } +} diff --git a/tests/src/readytorun/mainv1.csproj b/tests/src/readytorun/mainv1.csproj new file mode 100644 index 0000000000..cc47339ea2 --- /dev/null +++ b/tests/src/readytorun/mainv1.csproj @@ -0,0 +1,59 @@ +<?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>mainv1</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{7DECC55A-B584-4456-83BA-6C42A5B3B3CB}</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> + <RestorePackages>true</RestorePackages> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <DefineConstants>$(DefineConstants);STATIC;CORECLR</DefineConstants> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="testv1.csproj"> + <Project>{F74F55A1-DFCF-4C7C-B462-E96E1D0BB667}</Project> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <Compile Include="main.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Reference Include="testv1"> + <HintPath>$(TargetDir)\testv1.dll</HintPath> + </Reference> + </ItemGroup> + <PropertyGroup> + <_CLRTestPreCommands><![CDATA[ +$(_CLRTestPreCommands) +IF not exist NI mkdir NI +%Core_Root%\crossgen /readytorun /platform_assemblies_paths %Core_Root%%3B%25CD% /out NI\testv1.ni.dll testv1.dll +%Core_Root%\crossgen /readytorun /platform_assemblies_paths %Core_Root%%3B%25CD% /out NI\mainv1.ni.exe mainv1.exe + ]]></_CLRTestPreCommands> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project> diff --git a/tests/src/readytorun/mainv2.csproj b/tests/src/readytorun/mainv2.csproj new file mode 100644 index 0000000000..d52265385c --- /dev/null +++ b/tests/src/readytorun/mainv2.csproj @@ -0,0 +1,59 @@ +<?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>mainv2</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{840300BB-0DD2-4BD3-A3C1-51C92DD4ADAD}</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> + <RestorePackages>true</RestorePackages> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <DefineConstants>$(DefineConstants);STATIC;CORECLR;V2</DefineConstants> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="testv2.csproj"> + <Project>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</Project> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <Compile Include="main.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Reference Include="testv2"> + <HintPath>$(TargetDir)\testv2.dll</HintPath> + </Reference> + </ItemGroup> + <PropertyGroup> + <_CLRTestPreCommands><![CDATA[ +$(_CLRTestPreCommands) +IF not exist NI mkdir NI +%Core_Root%\crossgen /readytorun /platform_assemblies_paths %Core_Root%%3B%25CD% /out NI\testv2.ni.dll testv2.dll +%Core_Root%\crossgen /readytorun /platform_assemblies_paths %Core_Root%%3B%25CD% /out NI\mainv2.ni.exe mainv2.exe +]]></_CLRTestPreCommands> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project> diff --git a/tests/src/readytorun/packages.config b/tests/src/readytorun/packages.config new file mode 100644 index 0000000000..a1da6980b1 --- /dev/null +++ b/tests/src/readytorun/packages.config @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="System.Collections" version="4.0.10-beta-22512" /> + <package id="System.Console" version="4.0.0-beta-22405" /> + <package id="System.IO" version="4.0.10-beta-22412" /> + <package id="System.IO.FileSystem" version="4.0.0-beta-22412" /> + <package id="System.Reflection" version="4.0.10-beta-22512" /> + <package id="System.Reflection.Extensions" version="4.0.0-beta-22412" /> + <package id="System.Runtime" version="4.0.20-beta-22412" /> + <package id="System.Runtime.Extensions" version="4.0.10-beta-22412" /> + <package id="System.Runtime.InteropServices" version="4.0.20-beta-22412" /> + <package id="System.Runtime.Loader" version="4.0.0-beta-22512" /> +</packages> diff --git a/tests/src/readytorun/test.cs b/tests/src/readytorun/test.cs new file mode 100644 index 0000000000..19347689f4 --- /dev/null +++ b/tests/src/readytorun/test.cs @@ -0,0 +1,363 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Runtime.InteropServices; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +public static class Assert +{ + public static bool HasAssertFired; + + public static void AreEqual(Object actual, Object expected) + { + if (!(actual == null && expected == null) && !actual.Equals(expected)) + { + Console.WriteLine("Not equal!"); + Console.WriteLine("actual = " + actual.ToString()); + Console.WriteLine("expected = " + expected.ToString()); + HasAssertFired = true; + } + } +} + +public interface IMyInterface +{ +#if V2 + // Adding new methods to interfaces is incompatible change, but we will make sure that it works anyway + void NewInterfaceMethod(); +#endif + + string InterfaceMethod(string s); +} + +public class MyClass : IMyInterface +{ +#if V2 + public int _field1; + public int _field2; + public int _field3; +#endif + public int InstanceField; + +#if V2 + public static Object StaticObjectField2; + + [ThreadStatic] public static String ThreadStaticStringField2; + + [ThreadStatic] public static int ThreadStaticIntField; + + public static Nullable<Guid> StaticNullableGuidField; + + public static Object StaticObjectField; + + [ThreadStatic] public static int ThreadStaticIntField2; + + public static long StaticLongField; + + [ThreadStatic] public static DateTime ThreadStaticDateTimeField2; + + public static long StaticLongField2; + + [ThreadStatic] public static DateTime ThreadStaticDateTimeField; + + public static Nullable<Guid> StaticNullableGuidField2; + + [ThreadStatic] public static String ThreadStaticStringField; +#else + public static Object StaticObjectField; + + public static long StaticLongField; + + public static Nullable<Guid> StaticNullableGuidField; + + [ThreadStatic] public static String ThreadStaticStringField; + + [ThreadStatic] public static int ThreadStaticIntField; + + [ThreadStatic] public static DateTime ThreadStaticDateTimeField; +#endif + + public MyClass() + { + } + +#if V2 + public virtual void NewVirtualMethod() + { + } + + public virtual void NewInterfaceMethod() + { + throw new Exception(); + } +#endif + + public virtual string VirtualMethod() + { + return "Virtual method result"; + } + + public virtual string InterfaceMethod(string s) + { + return "Interface" + s + "result"; + } + + public static string TestInterfaceMethod(IMyInterface i, string s) + { + return i.InterfaceMethod(s); + } + + public static void TestStaticFields() + { + StaticObjectField = (int)StaticObjectField + 12345678; + + StaticLongField *= 456; + + Assert.AreEqual(StaticNullableGuidField, new Guid("0D7E505F-E767-4FEF-AEEC-3243A3005673")); + StaticNullableGuidField = null; + + ThreadStaticStringField += "World"; + + ThreadStaticIntField /= 78; + + ThreadStaticDateTimeField = ThreadStaticDateTimeField + new TimeSpan(123); + + MyGeneric<int,int>.ThreadStatic = new Object(); + +#if false // TODO: Enable once LDFTN is supported + // Do some operations on static fields on a different thread to verify that we are not mixing thread-static and non-static + Task.Run(() => { + + StaticObjectField = (int)StaticObjectField + 1234; + + StaticLongField *= 45; + + ThreadStaticStringField = "Garbage"; + + ThreadStaticIntField = 0xBAAD; + + ThreadStaticDateTimeField = DateTime.Now; + + }).Wait(); +#endif + } + + [DllImport("api-ms-win-core-sysinfo-l1-1-0.dll")] + public extern static int GetTickCount(); + + static public void TestInterop() + { + GetTickCount(); + } + +#if V2 + public string MovedToBaseClass() + { + return "MovedToBaseClass"; + } +#endif + +#if V2 + public virtual string ChangedToVirtual() + { + return null; + } +#else + public string ChangedToVirtual() + { + return "ChangedToVirtual"; + } +#endif + +} + +public class MyChildClass : MyClass +{ + public MyChildClass() + { + } + +#if !V2 + public string MovedToBaseClass() + { + return "MovedToBaseClass"; + } +#endif + +#if V2 + public override string ChangedToVirtual() + { + return "ChangedToVirtual"; + } +#endif +} + + +public struct MyStruct : IDisposable +{ + int x; + +#if V2 + void IDisposable.Dispose() + { + } +#else + public void Dispose() + { + } +#endif +} + +public class MyGeneric<T,U> +{ + [ThreadStatic] public static Object ThreadStatic; + + public MyGeneric() + { + } + + public virtual string GenericVirtualMethod<V,W>() + { + return typeof(T).ToString() + typeof(U).ToString() + typeof(V).ToString() + typeof(W).ToString(); + } + +#if V2 + public string MovedToBaseClass<W>() + { + typeof(Dictionary<W,W>).ToString(); + return typeof(List<W>).ToString(); + } +#endif + +#if V2 + public virtual string ChangedToVirtual<W>() + { + return null; + } +#else + public string ChangedToVirtual<W>() + { + return typeof(List<W>).ToString(); + } +#endif +} + +public class MyChildGeneric<T> : MyGeneric<T,T> +{ + public MyChildGeneric() + { + } + +#if !V2 + public string MovedToBaseClass<W>() + { + return typeof(List<W>).ToString(); + } +#endif + +#if V2 + public override string ChangedToVirtual<W>() + { + typeof(Dictionary<Int32, W>).ToString(); + return typeof(List<W>).ToString(); + } +#endif +} + +[StructLayout(LayoutKind.Sequential)] +public class MyClassWithLayout +{ +#if V2 + public int _field1; + public int _field2; + public int _field3; +#endif +} + +public struct MyGrowingStruct +{ + int x; + int y; +#if V2 + Object o1; + Object o2; +#endif + + static public MyGrowingStruct Construct() + { + return new MyGrowingStruct() { x = 111, y = 222 }; + } + + public static void Check(ref MyGrowingStruct s) + { + Assert.AreEqual(s.x, 111); + Assert.AreEqual(s.y, 222); + } +} + +public struct MyChangingStruct +{ +#if V2 + public int y; + public int x; +#else + public int x; + public int y; +#endif + + static public MyChangingStruct Construct() + { + return new MyChangingStruct() { x = 111, y = 222 }; + } + + public static void Check(ref MyChangingStruct s) + { + Assert.AreEqual(s.x, 112); + Assert.AreEqual(s.y, 222); + } +} + +public struct MyChangingHFAStruct +{ +#if V2 + float x; + float y; +#else + int x; + int y; +#endif + static public MyChangingHFAStruct Construct() + { + return new MyChangingHFAStruct() { x = 12, y = 23 }; + } + + public static void Check(MyChangingHFAStruct s) + { +#if V2 + Assert.AreEqual(s.x, 12.0f); + Assert.AreEqual(s.y, 23.0f); +#else + Assert.AreEqual(s.x, 12); + Assert.AreEqual(s.y, 23); +#endif + } +} + +public class ByteBaseClass : List<byte> +{ + public byte BaseByte; +} +public class ByteChildClass : ByteBaseClass +{ + public byte ChildByte; + + [MethodImplAttribute(MethodImplOptions.NoInlining)] + public ByteChildClass(byte value) + { + ChildByte = 67; + } +} diff --git a/tests/src/readytorun/testv1.csproj b/tests/src/readytorun/testv1.csproj new file mode 100644 index 0000000000..041f92e7f8 --- /dev/null +++ b/tests/src/readytorun/testv1.csproj @@ -0,0 +1,41 @@ +<?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>testv1</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{F74F55A1-DFCF-4C7C-B462-E96E1D0BB667}</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> + <RestorePackages>true</RestorePackages> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <DefineConstants>$(DefineConstants);STATIC;CORECLR</DefineConstants> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <ItemGroup> + <Compile Include="test.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project>
\ No newline at end of file diff --git a/tests/src/readytorun/testv2.csproj b/tests/src/readytorun/testv2.csproj new file mode 100644 index 0000000000..8771df06b5 --- /dev/null +++ b/tests/src/readytorun/testv2.csproj @@ -0,0 +1,41 @@ +<?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>testv2</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> + <RestorePackages>true</RestorePackages> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <DefineConstants>$(DefineConstants);STATIC;CORECLR;V2</DefineConstants> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <ItemGroup> + <Compile Include="test.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project> |