add a regression test for Linux GC segfault. (#19820)
authorSergey Andreenko <seandree@microsoft.com>
Thu, 6 Sep 2018 20:25:52 +0000 (13:25 -0700)
committerGitHub <noreply@github.com>
Thu, 6 Sep 2018 20:25:52 +0000 (13:25 -0700)
* add test

* move the test to pri1 and reduce number of iterations

tests/src/JIT/Regression/JitBlue/GitHub_19361/GitHub_19361.cs [new file with mode: 0644]
tests/src/JIT/Regression/JitBlue/GitHub_19361/GitHub_19361.csproj [new file with mode: 0644]

diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_19361/GitHub_19361.cs b/tests/src/JIT/Regression/JitBlue/GitHub_19361/GitHub_19361.cs
new file mode 100644 (file)
index 0000000..64fc0d3
--- /dev/null
@@ -0,0 +1,107 @@
+// 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.
+
+// The test exposed a bug in CORINFO_HELP_ASSIGN_BYREF GC kill set on Unix x64.
+// that caused segfault.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Security.Cryptography.X509Certificates;
+using System.Threading.Tasks;
+
+namespace Repro
+{
+    [Serializable]
+    public struct CompositeSource
+    {
+        public double? Modifier { get; set; }
+        public int InstrumentId { get; set; }
+        public string Section { get; set; }
+
+        public bool IsCash { get; set; }
+        public bool IsHedge { get; set; }
+
+    }
+
+    public class Test
+    {
+        private static readonly DateTime BaseDate = new DateTime(2012, 1, 1);
+
+        private readonly Random rng;
+
+        public int Count { get; }
+
+        public Test(Random rng, List<CompositeSource> sources)
+        {
+            this.rng = rng;
+            var holdingsAttribution = this.GetNumbers(sources);
+            var hedgeAttribution = this.GetNumbers(sources).Where(x => x.Date >= holdingsAttribution.Min(y => y.Date)).ToList();
+            this.Count = hedgeAttribution.Count;
+        }
+
+        private List<(DateTime Date, CompositeSource Key, decimal Attribution)> GetNumbers(List<CompositeSource> sources)
+        {
+            var items = new List<(DateTime Date, CompositeSource Key, decimal Attribution)>();
+
+            foreach (var _ in Enumerable.Range(0, rng.Next(1000, 10000)))
+            {
+                items.Add((
+                    BaseDate.AddDays(rng.Next(1, 100)),
+                    sources[rng.Next(0, sources.Count - 1)],
+                    Convert.ToDecimal(rng.NextDouble() * rng.Next(1, 10))));
+            }
+
+            return items;
+        }
+    }
+
+    class Program
+    {
+        static readonly Random Rng = new Random(38237);
+
+        public static List<CompositeSource> GetCompositeSources()
+        {
+
+            var list = new List<CompositeSource>();
+            foreach (var _ in Enumerable.Range(0, 100))
+            {
+                lock (Rng)
+                {
+                    list.Add(new CompositeSource
+                    {
+                        InstrumentId = 1,
+                        IsCash = true,
+                        IsHedge = true,
+                        Modifier = 0.5,
+                        Section = "hello"
+                    });
+                }
+
+            }
+
+            return list;
+        }
+
+        static int Main()
+        {
+            Console.WriteLine("Starting stress loop");
+            var compositeSources = GetCompositeSources();
+            var res = Parallel.For(0, 10, i =>
+            {
+                int seed;
+                lock (Rng)
+                {
+                    seed = Rng.Next();
+                }
+                Console.WriteLine(new Test(new Random(seed), compositeSources).Count);
+            });
+
+            Console.WriteLine("Result: {0}", res.IsCompleted ? "Completed Normally" :
+                $"Completed to {res.LowestBreakIteration}");
+            return res.IsCompleted ? 100 : -1;
+        }
+    }
+}
diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_19361/GitHub_19361.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_19361/GitHub_19361.csproj
new file mode 100644 (file)
index 0000000..44c8fc3
--- /dev/null
@@ -0,0 +1,35 @@
+<?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>{ADEEA3D1-B67B-456E-8F2B-6DCCACC2D34C}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <CLRTestPriority>1</CLRTestPriority>
+  </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>
+    <DebugType>None</DebugType>
+    <Optimize>False</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="$(MSBuildProjectName).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>