From a76c402d16499ab2f05953edbdb92abfa68357b9 Mon Sep 17 00:00:00 2001 From: Tomas Weinfurt Date: Tue, 3 Dec 2019 12:07:58 -0800 Subject: [PATCH] stabilize Copy_LargeMultiDimensionalArray test (#484) --- src/libraries/System.Runtime/tests/Helpers.cs | 5 +++ .../System.Runtime/tests/System/ArrayTests.cs | 51 ++++++++++++++-------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/libraries/System.Runtime/tests/Helpers.cs b/src/libraries/System.Runtime/tests/Helpers.cs index a092d70..76851b8 100644 --- a/src/libraries/System.Runtime/tests/Helpers.cs +++ b/src/libraries/System.Runtime/tests/Helpers.cs @@ -6,9 +6,14 @@ using System.Collections.Generic; using System.Globalization; using System.Reflection; using System.Reflection.Emit; +using Xunit; +using Xunit.Abstractions; namespace System.Tests { + [CollectionDefinition("NoParallelTests", DisableParallelization = true)] + public partial class NoParallelTests { } + public static class Helpers { private static Type s_refEmitType; diff --git a/src/libraries/System.Runtime/tests/System/ArrayTests.cs b/src/libraries/System.Runtime/tests/System/ArrayTests.cs index 57ac706..9d0a8ef 100644 --- a/src/libraries/System.Runtime/tests/System/ArrayTests.cs +++ b/src/libraries/System.Runtime/tests/System/ArrayTests.cs @@ -8,7 +8,9 @@ using System.Collections.ObjectModel; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; +using Microsoft.DotNet.XUnitExtensions; using Xunit; +using Xunit.Abstractions; namespace System.Tests { @@ -1319,25 +1321,6 @@ namespace System.Tests Assert.Equal(expected, destinationArrayClone); } - [OuterLoop] // Allocates large array - [Fact] - public static void Copy_LargeMultiDimensionalArray() - { - // If this test is run in a 32-bit process, the large allocation will fail. - if (IntPtr.Size != sizeof(long)) - { - return; - } - - short[,] a = new short[2, 2_000_000_000]; - a[0, 1] = 42; - Array.Copy(a, 1, a, Int32.MaxValue, 2); - Assert.Equal(42, a[1, Int32.MaxValue - 2_000_000_000]); - - Array.Clear(a, Int32.MaxValue - 1, 3); - Assert.Equal(0, a[1, Int32.MaxValue - 2_000_000_000]); - } - [Fact] public static void Copy_NullSourceArray_ThrowsArgumentNullException() { @@ -4579,4 +4562,34 @@ namespace System.Tests public enum Int64Enum : long { } } + + [Collection("NoParallelTests")] + public class DangerousArrayTests + { + [OuterLoop] // Allocates large array + [ConditionalFact] + public static void Copy_LargeMultiDimensionalArray() + { + // If this test is run in a 32-bit process, the large allocation will fail. + if (IntPtr.Size != sizeof(long)) + { + return; + } + + try + { + short[,] a = new short[2, 2_000_000_000]; + a[0, 1] = 42; + Array.Copy(a, 1, a, Int32.MaxValue, 2); + Assert.Equal(42, a[1, Int32.MaxValue - 2_000_000_000]); + + Array.Clear(a, Int32.MaxValue - 1, 3); + Assert.Equal(0, a[1, Int32.MaxValue - 2_000_000_000]); + } + catch (OutOfMemoryException) + { + throw new SkipTestException("Unable to allocate enough memory"); + } + } + } } -- 2.7.4