diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
commit | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch) | |
tree | 98110734c91668dfdbb126fcc0e15ddbd93738ca /tests/src/GC/Scenarios/SingLinkList | |
parent | fa45f57ed55137c75ac870356a1b8f76c84b229c (diff) | |
download | coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2 coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip |
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'tests/src/GC/Scenarios/SingLinkList')
-rw-r--r-- | tests/src/GC/Scenarios/SingLinkList/singlinkgen.cs | 160 | ||||
-rw-r--r-- | tests/src/GC/Scenarios/SingLinkList/singlinkgen.csproj | 38 | ||||
-rw-r--r-- | tests/src/GC/Scenarios/SingLinkList/singlinkstay.cs | 150 | ||||
-rw-r--r-- | tests/src/GC/Scenarios/SingLinkList/singlinkstay.csproj | 38 |
4 files changed, 386 insertions, 0 deletions
diff --git a/tests/src/GC/Scenarios/SingLinkList/singlinkgen.cs b/tests/src/GC/Scenarios/SingLinkList/singlinkgen.cs new file mode 100644 index 0000000000..db68ab7a4a --- /dev/null +++ b/tests/src/GC/Scenarios/SingLinkList/singlinkgen.cs @@ -0,0 +1,160 @@ +// 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. + +/************************************************************** +/* a basic test case for GC with cyclic single linked list leaks. +/* Creat a SingLink object which is a cyclic single linked list +/* object with iObj number node. then deletes its reference when +/* the next object is created. Do this loop iRep times. +/**************************************************************/ + + +namespace SingLink { + using System; + using System.Runtime.CompilerServices; + + public class SingLinkGen + { +// disabling unused variable warning +#pragma warning disable 0414 + internal SingLink Mv_Sing; +#pragma warning restore 0414 + + public static int Main(System.String [] Args) + { + int iRep = 0; + int iObj = 0; + Console.WriteLine("Test should return with ExitCode 100 ..."); + switch( Args.Length ) + { + case 1: + if (!Int32.TryParse( Args[0], out iRep )) + { + iRep = 100; + } + break; + case 2: + if (!Int32.TryParse( Args[0], out iRep )) + { + iRep = 100; + } + if (!Int32.TryParse( Args[1], out iObj )) + { + iObj = 10; + } + break; + default: + iRep = 100; + iObj = 10; + break; + } + + SingLinkGen Mv_Leak = new SingLinkGen(); + + if(Mv_Leak.runTest(iRep, iObj )) + { + Console.WriteLine( "Test Passed" ); + return 100; + } + else + { + Console.WriteLine( "Test Failed" ); + return 1; + } + } + + + public bool runTest(int iRep, int iObj) + { + int retVal = SetLink(iRep, iObj); + + Console.Write("Times ~LinkNode() was called: "); + Console.WriteLine(retVal); + return ( retVal == iRep*iObj); + } + + [MethodImplAttribute(MethodImplOptions.NoInlining)] + void Create(int iObj) { + Mv_Sing = new SingLink(iObj); + } + + [MethodImplAttribute(MethodImplOptions.NoInlining)] + void Delete() { + Mv_Sing = null; + GC.Collect(); + } + + public int SetLink(int iRep, int iObj) + { + for(int i=0; i<iRep; i++) + { + Create(iObj); + //Console.WriteLine("after number {0} singlink is set: {1}", i, GC.GetTotalMemory(false) ); + + Delete(); + GC.WaitForPendingFinalizers(); + + } + //Console.WriteLine("total allocated memory: {0}", GC.GetTotalMemory(false)); + + return LinkNode.FinalCount; + + } + + } + + public class LinkNode + { + // disabling unused variable warning +#pragma warning disable 0414 + internal LinkNode Last; + internal int[] Size; +#pragma warning restore 0414 + + public static int FinalCount = 0; + + ~LinkNode() + { + FinalCount++; + } + + public LinkNode(int SizeNum, LinkNode LastObject) + { + Last = LastObject; + Size = new int[SizeNum * 1024]; + } + } + + public class SingLink + { + internal LinkNode[] Mv_SLink; + + public SingLink(int Num) + { + Mv_SLink = new LinkNode[Num]; + + if (Num == 0) + { + return; + } + + if (Num == 1) + { + Mv_SLink[0] = new LinkNode(1, Mv_SLink[0]); + } + else + { + Mv_SLink[0] = new LinkNode(1, Mv_SLink[Num - 1]); + } + + for (int i = 1; i < Num - 1; i++) + { + Mv_SLink[i] = new LinkNode((i + 1), Mv_SLink[i - 1]); + } + + Mv_SLink[Num - 1] = new LinkNode(Num, Mv_SLink[0]); + } + } +} + diff --git a/tests/src/GC/Scenarios/SingLinkList/singlinkgen.csproj b/tests/src/GC/Scenarios/SingLinkList/singlinkgen.csproj new file mode 100644 index 0000000000..9b18cd738f --- /dev/null +++ b/tests/src/GC/Scenarios/SingLinkList/singlinkgen.csproj @@ -0,0 +1,38 @@ +<?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> + <GCStressIncompatible>true</GCStressIncompatible> + </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="singlinkgen.cs" /> + </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/GC/Scenarios/SingLinkList/singlinkstay.cs b/tests/src/GC/Scenarios/SingLinkList/singlinkstay.cs new file mode 100644 index 0000000000..e624af97cf --- /dev/null +++ b/tests/src/GC/Scenarios/SingLinkList/singlinkstay.cs @@ -0,0 +1,150 @@ +// 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. + +/****************************************************************** +/*Test case for testing GC with cyclic single linked list leaks +/*In every loop. SetLink() to create a SingLink object array whose size +/*is iRep, each SingLink Object is a iObj node cyclic single +/*linked list. MakeLeak() deletes all the object reference in the array +/*to make all the cyclic single linked lists become memory leaks. +/******************************************************************/ + +namespace SingLink { + using System; + + public class SingLinkStay + { + + internal SingLink []Mv_Sing; + + public static int Main(System.String [] Args) + { + int iRep = 0; + int iObj = 0; + + Console.WriteLine("Test should return with ExitCode 100 ..."); + switch( Args.Length ) + { + case 1: + if (!Int32.TryParse( Args[0], out iRep )) + { + iRep = 100; + } + break; + case 2: + if (!Int32.TryParse( Args[0], out iRep )) + { + iRep = 100; + } + if (!Int32.TryParse( Args[1], out iObj )) + { + iObj = 10; + } + break; + default: + iRep = 100; + iObj = 10; + break; + } + + SingLinkStay Mv_Leak = new SingLinkStay(); + if(Mv_Leak.runTest(iRep, iObj )) + { + Console.WriteLine( "Test Passed" ); + return 100; + } + else + { + Console.WriteLine( "Test Failed" ); + return 1; + } + + } + + + public bool runTest(int iRep, int iObj) + { + for(int i=0; i<20; i++) + { + SetLink(iRep, iObj); + MakeLeak(iRep); + } + return true; + } + + + public void SetLink(int iRep, int iObj) + { + + Mv_Sing = new SingLink[iRep]; + for(int i=0; i<iRep; i++) + { + Mv_Sing[i] = new SingLink(iObj); + } + } + + + public void MakeLeak(int iRep) + { + for(int i=0; i<iRep; i++) + { + Mv_Sing[i] = null; + } + } + + } + + public class LinkNode + { + // disabling unused variable warning +#pragma warning disable 0414 + internal LinkNode Last; + internal int[] Size; +#pragma warning restore 0414 + + public static int FinalCount = 0; + + ~LinkNode() + { + FinalCount++; + } + + public LinkNode(int SizeNum, LinkNode LastObject) + { + Last = LastObject; + Size = new int[SizeNum * 1024]; + } + } + + public class SingLink + { + internal LinkNode[] Mv_SLink; + + public SingLink(int Num) + { + Mv_SLink = new LinkNode[Num]; + + if (Num == 0) + { + return; + } + + if (Num == 1) + { + Mv_SLink[0] = new LinkNode(1, Mv_SLink[0]); + } + else + { + Mv_SLink[0] = new LinkNode(1, Mv_SLink[Num - 1]); + } + + for (int i = 1; i < Num - 1; i++) + { + Mv_SLink[i] = new LinkNode((i + 1), Mv_SLink[i - 1]); + } + + Mv_SLink[Num - 1] = new LinkNode(Num, Mv_SLink[0]); + } + } +} diff --git a/tests/src/GC/Scenarios/SingLinkList/singlinkstay.csproj b/tests/src/GC/Scenarios/SingLinkList/singlinkstay.csproj new file mode 100644 index 0000000000..b91a0b3897 --- /dev/null +++ b/tests/src/GC/Scenarios/SingLinkList/singlinkstay.csproj @@ -0,0 +1,38 @@ +<?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> + <GCStressIncompatible>true</GCStressIncompatible> + </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="singlinkstay.cs" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> |