From 4c9bd6db472c043e53f518a057b0959a2fd2ca90 Mon Sep 17 00:00:00 2001 From: Rob Hague Date: Sun, 26 Jan 2025 17:42:08 +0100 Subject: [PATCH 1/4] Fix BigInteger outerloop test This has presumably been failing since capping BigInteger to a maximum length --- .../tests/BigInteger/GetBitLengthTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs index ab02a31ad5b17f..b385765da2989b 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs @@ -44,8 +44,8 @@ public static void RunGetBitLengthTests() public static void RunGetBitLengthTestsLarge() { // Very large cases - VerifyGetBitLength(BigInteger.One << 32 << int.MaxValue, int.MaxValue + 32L + 1, 1); - VerifyGetBitLength(BigInteger.One << 64 << int.MaxValue, int.MaxValue + 64L + 1, 1); + VerifyGetBitLength(BigInteger.One << 32 << (int.MaxValue / 2), (int.MaxValue / 2) + 32L + 1, 1); + VerifyGetBitLength(BigInteger.One << 64 << (int.MaxValue / 2), (int.MaxValue / 2) + 64L + 1, 1); } private static void VerifyLoopGetBitLength(Random random, bool isSmall) From 11c43e91db54942e21be68824514e4cd5d4f36ef Mon Sep 17 00:00:00 2001 From: Rob Hague Date: Tue, 28 Jan 2025 07:25:05 +0100 Subject: [PATCH 2/4] Update src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs --- .../tests/BigInteger/GetBitLengthTests.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs index b385765da2989b..147efc0d4a44dd 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs @@ -44,8 +44,10 @@ public static void RunGetBitLengthTests() public static void RunGetBitLengthTestsLarge() { // Very large cases - VerifyGetBitLength(BigInteger.One << 32 << (int.MaxValue / 2), (int.MaxValue / 2) + 32L + 1, 1); - VerifyGetBitLength(BigInteger.One << 64 << (int.MaxValue / 2), (int.MaxValue / 2) + 64L + 1, 1); + // Values which are large but beneath the upper bound of + // (2^31) - 1 bits and which should not cause OOM in CI. + VerifyGetBitLength(BigInteger.One << 32 << (1 << 27), (1 << 27) + 32L + 1, 1); + VerifyGetBitLength(BigInteger.One << 64 << (1 << 27), (1 << 27) + 64L + 1, 1); } private static void VerifyLoopGetBitLength(Random random, bool isSmall) From b004c419683aadedc142c81a68e42b54065d703f Mon Sep 17 00:00:00 2001 From: Rob Hague Date: Tue, 28 Jan 2025 16:52:21 +0100 Subject: [PATCH 3/4] 2MB --- .../tests/BigInteger/GetBitLengthTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs index 147efc0d4a44dd..f8422070565db3 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs @@ -46,8 +46,8 @@ public static void RunGetBitLengthTestsLarge() // Very large cases // Values which are large but beneath the upper bound of // (2^31) - 1 bits and which should not cause OOM in CI. - VerifyGetBitLength(BigInteger.One << 32 << (1 << 27), (1 << 27) + 32L + 1, 1); - VerifyGetBitLength(BigInteger.One << 64 << (1 << 27), (1 << 27) + 64L + 1, 1); + VerifyGetBitLength(BigInteger.One << 32 << (1 << 24), (1 << 24) + 32L + 1, 1); + VerifyGetBitLength(BigInteger.One << 64 << (1 << 24), (1 << 24) + 64L + 1, 1); } private static void VerifyLoopGetBitLength(Random random, bool isSmall) From fd66d48c36956400291f7eb1043a4beb35881a30 Mon Sep 17 00:00:00 2001 From: Rob Hague Date: Wed, 29 Jan 2025 23:56:01 +0100 Subject: [PATCH 4/4] convert ToString_ValidLargeFormat to inner loop --- .../tests/BigInteger/BigIntegerToStringTests.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs index f0219a252787a6..8aec40e50d4e13 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs @@ -521,22 +521,23 @@ public static void ToString_InvalidFormat_ThrowsFormatException() Assert.Throws(() => b.ToString("G000001000000000")); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.Is64BitProcess))] // Requires a lot of memory - [OuterLoop("Takes a long time, allocates a lot of memory")] - [SkipOnMono("Frequently throws OOM on Mono")] + [Fact] public static void ToString_ValidLargeFormat() { BigInteger b = new BigInteger(123456789000m); // Format precision limit is 999_999_999 (9 digits). Anything larger should throw. + // We use TryFormat rather than ToString to avoid excessive memory usage. - // Check ParseFormatSpecifier in FormatProvider.Number.cs with `E` format - b.ToString("E999999999"); // Should not throw - b.ToString("E00000999999999"); // Should not throw + // Check ParseFormatSpecifier in FormatProvider.Number.cs with `E` format. + // Currently disabled since these would still allocate a 2GB buffer before + // returning, leading to OOM in CI. + //Assert.False(b.TryFormat(Span.Empty, out _, format: "E999999999")); // Should not throw + //Assert.False(b.TryFormat(Span.Empty, out _, format: "E00000999999999")); // Should not throw // Check ParseFormatSpecifier in Number.BigInteger.cs with `G` format - b.ToString("G999999999"); // Should not throw - b.ToString("G00000999999999"); // Should not throw + Assert.False(b.TryFormat(Span.Empty, out _, format: "G999999999")); // Should not throw + Assert.False(b.TryFormat(Span.Empty, out _, format: "G00000999999999")); // Should not throw } private static void RunSimpleProviderToStringTests(Random random, string format, NumberFormatInfo provider, int precision, StringFormatter formatter)