diff options
Diffstat (limited to 'tests/src/JIT/Directed/lifetime')
-rw-r--r-- | tests/src/JIT/Directed/lifetime/app.config | 27 | ||||
-rw-r--r-- | tests/src/JIT/Directed/lifetime/cs_template.proj | 42 | ||||
-rw-r--r-- | tests/src/JIT/Directed/lifetime/lifetime.csproj | 19 | ||||
-rw-r--r-- | tests/src/JIT/Directed/lifetime/lifetime1.cs | 159 | ||||
-rw-r--r-- | tests/src/JIT/Directed/lifetime/lifetime2.cs | 210 | ||||
-rw-r--r-- | tests/src/JIT/Directed/lifetime/packages.config | 6 |
6 files changed, 463 insertions, 0 deletions
diff --git a/tests/src/JIT/Directed/lifetime/app.config b/tests/src/JIT/Directed/lifetime/app.config new file mode 100644 index 0000000000..62803f5972 --- /dev/null +++ b/tests/src/JIT/Directed/lifetime/app.config @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <runtime> + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> + <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.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/JIT/Directed/lifetime/cs_template.proj b/tests/src/JIT/Directed/lifetime/cs_template.proj new file mode 100644 index 0000000000..adc2f21e14 --- /dev/null +++ b/tests/src/JIT/Directed/lifetime/cs_template.proj @@ -0,0 +1,42 @@ +<?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>$(AssemblyName1)</AssemblyName> + <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> + <RestorePackages>true</RestorePackages> + <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> + <ItemGroup> + <Compile Include="$(AssemblyName1).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" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/Directed/lifetime/lifetime.csproj b/tests/src/JIT/Directed/lifetime/lifetime.csproj new file mode 100644 index 0000000000..33b2928ebc --- /dev/null +++ b/tests/src/JIT/Directed/lifetime/lifetime.csproj @@ -0,0 +1,19 @@ +<?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" /> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> + </PropertyGroup> + <Target Name="Build"> + <ItemGroup> + <AllSourceFiles Include="$(MSBuildProjectDirectory)\*.cs" /> + </ItemGroup> + <PropertyGroup> + <GenerateRunScript>false</GenerateRunScript> + </PropertyGroup> + <MSBuild Projects="cs_template.proj" Properties="AssemblyName1=%(AllSourceFiles.FileName);AllowUnsafeBlocks=True;IntermediateOutputPath=$(IntermediateOutputPath)\%(AllSourceFiles.FileName)\" /> + </Target> +</Project> diff --git a/tests/src/JIT/Directed/lifetime/lifetime1.cs b/tests/src/JIT/Directed/lifetime/lifetime1.cs new file mode 100644 index 0000000000..46d428098d --- /dev/null +++ b/tests/src/JIT/Directed/lifetime/lifetime1.cs @@ -0,0 +1,159 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +// testing the JIT handling and GC reporting of "liveness" of GC variable + +using System; + +internal class Test +{ + private class A + { + public A() + { + Console.WriteLine("A"); + _iMember = 123; + Test.aExists = true; + } + ~A() + { + Console.WriteLine("~A"); + Test.aExists = false; + } + public bool F() + { + Console.WriteLine("A.F(): iMember = {0}", _iMember); + return true; + } + private volatile int _iMember; + } + + public static volatile bool aExists = false; + + public static int f1() + { + A a = new A(); + a.F(); + + // Testcase 1 + Console.WriteLine(); + Console.WriteLine("Testcase 1"); + if (!Test.aExists) + { + Console.WriteLine("Testcase 1 FAILED"); + return -1; + } + a.F(); + a = null; + return 100; + } + + public static int f2() + { + A a = new A(); + a.F(); + a = null; + + // Testcase 3 + Console.WriteLine(); + Console.WriteLine("Testcase 3"); + if (!Test.aExists) + { + Console.WriteLine("Testcase 3 FAILED"); + return -1; + } + return 100; + } + + + public static int f3() + { + A a = new A(); + a.F(); + a = null; + GC.Collect(); + GC.WaitForPendingFinalizers(); + + A b = new A(); + a = b; + GC.Collect(); + GC.WaitForPendingFinalizers(); + Console.WriteLine(); + Console.WriteLine("Testcase 5"); + if (!Test.aExists) + { + Console.WriteLine("Testcase 5 FAILED"); + return -1; + } + GC.KeepAlive(b); + // Testcase 6 + Console.WriteLine(); + Console.WriteLine("Testcase 6"); + if (b == null) + { + Console.WriteLine("Testcase 6 FAILED"); + return -1; + } + + b = null; + + return 100; + } + + + private static int Main() + { + if (f1() != 100) return -1; + CleanGC(); + + // Testcase 2 + Console.WriteLine(); + Console.WriteLine("Testcase 2"); + // here JIT should know a is not live anymore + if (Test.aExists) + { + Console.WriteLine("Testcase 2 FAILED"); + return -1; + } + + if (f2() != 100) return -1; + CleanGC(); + + // here JIT should know object a is not live anymore + // Testcase 4 + Console.WriteLine(); + Console.WriteLine("Testcase 4"); + if (Test.aExists) + { + Console.WriteLine("Testcase 4 FAILED"); + return -1; + } + + if (f3() != 100) return -1; + CleanGC(); + + // here JIT should know object a is not live anymore + // Testcase 7 + Console.WriteLine(); + Console.WriteLine("Testcase 7"); + if (Test.aExists) + { + Console.WriteLine("Testcase 7 FAILED"); + return -1; + } + + CleanGC(); + + + + Console.WriteLine("Test SUCCESS"); + return 100; + } + + private static void CleanGC() + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + } +} diff --git a/tests/src/JIT/Directed/lifetime/lifetime2.cs b/tests/src/JIT/Directed/lifetime/lifetime2.cs new file mode 100644 index 0000000000..e6d5685893 --- /dev/null +++ b/tests/src/JIT/Directed/lifetime/lifetime2.cs @@ -0,0 +1,210 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +// Testing JIT handling and GC reporting of liveness of GC variable + +using System; +using System.Collections.Generic; + +internal class Test +{ + public static int aExists; + public static int bExists; + private abstract class A + { + } + private class B : A + { + public B() + { + aExists++; + } + ~B() + { + aExists--; + Console.WriteLine("~B"); + } + + public void F() + { + Console.WriteLine("B.F"); + } + } + private class C : B + { + public C() + { + bExists++; + } + ~C() + { + bExists--; + Console.WriteLine("~C"); + } + + public void G() + { + Console.WriteLine("C.G"); + } + } + private static int f1() + { + B a = new B(); + a.F(); + + Console.WriteLine(); + Console.WriteLine("testcase f1-1"); + if (aExists != 1) + { + Console.WriteLine("f1-1 failed"); + return -1; + } + + GC.KeepAlive(a); + a = null; + GC.Collect(); + GC.WaitForPendingFinalizers(); + + Console.WriteLine(); + Console.WriteLine("testcase f1-2"); + if (aExists != 0) + { + Console.WriteLine("f1-2 failed"); + return -1; + } + + C b = new C(); + b.G(); + + Console.WriteLine(); + Console.WriteLine("testcase f1-3"); + if ((aExists != 1) || (bExists != 1)) + { + Console.WriteLine("f1-3 failed"); + return -1; + } + + GC.KeepAlive(b); + b = null; + GC.Collect(); + GC.WaitForPendingFinalizers(); + + Console.WriteLine(); + Console.WriteLine("testcase f1-4"); + if ((aExists != 0) || (bExists != 0)) + { + Console.WriteLine("f1-4 failed"); + return -1; + } + return 100; + } + private static int f2() + { + B a = new B(); + { + C b = new C(); + b.G(); + b = null; + } + GC.Collect(); + GC.WaitForPendingFinalizers(); + + a.F(); + Console.WriteLine(); + Console.WriteLine("testcase f2-1"); + if ((aExists != 1) || (bExists != 0)) + { + Console.WriteLine("f2-1 failed"); + return -1; + } + + GC.KeepAlive(a); + a = null; + GC.Collect(); + GC.WaitForPendingFinalizers(); + Console.WriteLine(); + Console.WriteLine("testcase f2-2"); + if (aExists != 0) + { + Console.WriteLine("f2-2 failed"); + return -1; + } + return 100; + } + private static int f3() + { + C b = new C(); + b = null; + GC.Collect(); + GC.WaitForPendingFinalizers(); + Console.WriteLine(); + Console.WriteLine("testcase f3"); + if (aExists != 0) + { + Console.WriteLine("f3 failed"); + return -1; + } + b = null; + return 100; + } + private static int f4() + { + B a = new B(); + a.F(); + C b = new C(); + b.G(); + + Console.WriteLine(); + Console.WriteLine("testcase f4"); + if ((aExists != 2) || (bExists != 1)) + { + Console.WriteLine("f4 failed"); + return -1; + } + + GC.KeepAlive(a); + GC.KeepAlive(b); + return 100; + } + + private static int f5() + { + Console.WriteLine(); + Console.WriteLine("testcase f5"); + if ((aExists != 0) || (bExists != 0)) + { + Console.WriteLine("f5 failed"); + return -1; + } + return 100; + } + + private static int Main() + { + if (f1() != 100) + return -1; + CleanGC(); + if (f2() != 100) + return -1; + CleanGC(); + if (f3() != 100) + return -1; + CleanGC(); + if (f4() != 100) + return -1; + CleanGC(); + if (f5() != 100) + return -1; + CleanGC(); + + Console.WriteLine("PASSED"); + return 100; + } + + private static void CleanGC() + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + } +} diff --git a/tests/src/JIT/Directed/lifetime/packages.config b/tests/src/JIT/Directed/lifetime/packages.config new file mode 100644 index 0000000000..06d3d11ead --- /dev/null +++ b/tests/src/JIT/Directed/lifetime/packages.config @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="System.Console" version="4.0.0-beta-22405" /> + <package id="System.Runtime" version="4.0.20-beta-22405" /> + <package id="System.Runtime.Extensions" version="4.0.10-beta-22412" /> +</packages> |