using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
+using Microsoft.DotNet.XUnitExtensions;
using Xunit;
+using Xunit.Abstractions;
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()
{
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");
+ }
+ }
+ }
}