Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 4fd8620

Browse files
authored
Reduce test run time to help avoid timeouts in CI for outerloop tests (#26751)
* Add XunitShowProgress to help debug the hang in S.M outerloop tests * Reduce TwoGiBOverflowInt32TestData and use AllocationHelper in Base64 test. * Improve the runtime of Large Clear test and remove XunitShowProgress
1 parent e9be24d commit 4fd8620

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

src/System.Memory/tests/Base64/Base64EncoderUnitTests.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.SpanTests;
56
using System.Text;
67
using Xunit;
78

@@ -75,20 +76,44 @@ public void EncodeEmptySpan()
7576
[OuterLoop]
7677
public void EncodeTooLargeSpan()
7778
{
79+
80+
if (IntPtr.Size < 8)
81+
return;
82+
83+
bool allocatedFirst = false;
84+
bool allocatedSecond = false;
85+
IntPtr memBlockFirst = IntPtr.Zero;
86+
IntPtr memBlockSecond = IntPtr.Zero;
87+
7888
// int.MaxValue - (int.MaxValue % 4) => 2147483644, largest multiple of 4 less than int.MaxValue
7989
// CLR default limit of 2 gigabytes (GB).
90+
// 1610612734, larger than MaximumEncodeLength, requires output buffer of size 2147483648 (which is > int.MaxValue)
91+
const int sourceCount = (int.MaxValue >> 2) * 3 + 1;
92+
const int encodedCount = 2000000000;
93+
8094
try
8195
{
82-
// 1610612734, larger than MaximumEncodeLength, requires output buffer of size 2147483648 (which is > int.MaxValue)
83-
Span<byte> source = new byte[(int.MaxValue >> 2) * 3 + 1];
84-
Span<byte> encodedBytes = new byte[2000000000];
85-
Assert.Equal(OperationStatus.DestinationTooSmall, Base64.EncodeToUtf8(source, encodedBytes, out int consumed, out int encodedBytesCount));
86-
Assert.Equal((encodedBytes.Length >> 2) * 3, consumed); // encoding 1500000000 bytes fits into buffer of 2000000000 bytes
87-
Assert.Equal(encodedBytes.Length, encodedBytesCount);
96+
allocatedFirst = AllocationHelper.TryAllocNative((IntPtr)sourceCount, out memBlockFirst);
97+
allocatedSecond = AllocationHelper.TryAllocNative((IntPtr)encodedCount, out memBlockSecond);
98+
if (allocatedFirst && allocatedSecond)
99+
{
100+
unsafe
101+
{
102+
var source = new Span<byte>(memBlockFirst.ToPointer(), sourceCount);
103+
var encodedBytes = new Span<byte>(memBlockSecond.ToPointer(), encodedCount);
104+
105+
Assert.Equal(OperationStatus.DestinationTooSmall, Base64.EncodeToUtf8(source, encodedBytes, out int consumed, out int encodedBytesCount));
106+
Assert.Equal((encodedBytes.Length >> 2) * 3, consumed); // encoding 1500000000 bytes fits into buffer of 2000000000 bytes
107+
Assert.Equal(encodedBytes.Length, encodedBytesCount);
108+
}
109+
}
88110
}
89-
catch (OutOfMemoryException)
111+
finally
90112
{
91-
// do nothing
113+
if (allocatedFirst)
114+
AllocationHelper.ReleaseNative(ref memBlockFirst);
115+
if (allocatedSecond)
116+
AllocationHelper.ReleaseNative(ref memBlockSecond);
92117
}
93118
}
94119

src/System.Memory/tests/ParsersAndFormatters/Parser/ParserTests.2gbOverflow.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,11 @@ private static IEnumerable<ParserTestData<int>> TwoGiBOverflowInt32TestData
9393
{
9494
get
9595
{
96-
yield return new ParserTestData<int>("0", 0, 'D', expectedSuccess: true) { ExpectedBytesConsumed = TwoGiB };
97-
yield return new ParserTestData<int>("2", 2, 'D', expectedSuccess: true) { ExpectedBytesConsumed = TwoGiB };
98-
yield return new ParserTestData<int>("21", 21, 'D', expectedSuccess: true) { ExpectedBytesConsumed = TwoGiB };
99-
yield return new ParserTestData<int>("+2", 2, 'D', expectedSuccess: true) { ExpectedBytesConsumed = TwoGiB };
10096
yield return new ParserTestData<int>("-2", -2, 'D', expectedSuccess: true) { ExpectedBytesConsumed = TwoGiB };
10197
yield return new ParserTestData<int>("2147483647", 2147483647, 'D', expectedSuccess: true) { ExpectedBytesConsumed = TwoGiB };
102-
yield return new ParserTestData<int>("-2147483648", -2147483648, 'D', expectedSuccess: true) { ExpectedBytesConsumed = TwoGiB };
10398
yield return new ParserTestData<int>("2147483648", default, 'D', expectedSuccess: false);
104-
yield return new ParserTestData<int>("-2147483649", default, 'D', expectedSuccess: false);
10599
yield return new ParserTestData<int>("12345abcdefg1", 12345, 'D', expectedSuccess: true) { ExpectedBytesConsumed = TwoGiB - 8 };
106-
yield return new ParserTestData<int>("1234145abcdefg1", 1234145, 'D', expectedSuccess: true) { ExpectedBytesConsumed = TwoGiB - 8 };
107100
yield return new ParserTestData<int>("abcdefghijklmnop1", 0, 'D', expectedSuccess: true) { ExpectedBytesConsumed = TwoGiB - 17 };
108-
yield return new ParserTestData<int>("1147483648", 1147483648, 'D', expectedSuccess: true) { ExpectedBytesConsumed = TwoGiB };
109-
yield return new ParserTestData<int>("-1147483649", -1147483649, 'D', expectedSuccess: true) { ExpectedBytesConsumed = TwoGiB };
110101
}
111102
}
112103
}

src/System.Memory/tests/Span/Clear.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,20 +249,14 @@ unsafe static void ClearLongerThanUintMaxValueBytes()
249249

250250
try
251251
{
252-
ref int data = ref Unsafe.AsRef<int>(memory.ToPointer());
253-
254-
int initial = 5;
255-
for (int i = 0; i < length; i++)
256-
{
257-
Unsafe.Add(ref data, i) = initial;
258-
}
259-
260252
Span<int> span = new Span<int>(memory.ToPointer(), length);
253+
span.Fill(5);
261254

262255
// Act
263256
span.Clear();
264257

265258
// Assert using custom code for perf and to avoid allocating extra memory
259+
ref int data = ref Unsafe.AsRef<int>(memory.ToPointer());
266260
for (int i = 0; i < length; i++)
267261
{
268262
var actual = Unsafe.Add(ref data, i);

0 commit comments

Comments
 (0)