Convert Ryujinx.Tests.Memory to xUnit

This commit is contained in:
TSR Berry 2023-07-16 04:10:30 +02:00
parent 953a770b05
commit 1839e25550
No known key found for this signature in database
GPG key ID: 52353C0A4CCA15E2
3 changed files with 37 additions and 27 deletions

View file

@ -12,9 +12,9 @@ namespace Ryujinx.Tests.Memory
private const ulong MemorySize = 0x8000;
private const int PageSize = 4096;
private MemoryBlock _memoryBlock;
private MemoryTracking _tracking;
private MockVirtualMemoryManager _memoryManager;
private readonly MemoryBlock _memoryBlock;
private readonly MemoryTracking _tracking;
private readonly MockVirtualMemoryManager _memoryManager;
public MultiRegionTrackingTests()
{
@ -26,6 +26,7 @@ namespace Ryujinx.Tests.Memory
public void Dispose()
{
GC.SuppressFinalize(this);
_memoryBlock.Dispose();
}
@ -92,7 +93,7 @@ namespace Ryujinx.Tests.Memory
{
resultAddress = address;
});
Assert.Equal((ulong)i * PageSize + address, resultAddress);
Assert.Equal(resultAddress, (ulong)i * PageSize + address);
});
}

View file

@ -9,7 +9,7 @@ namespace Ryujinx.Tests.Memory
{
private static readonly ulong _memorySize = MemoryBlock.GetPageSize() * 8;
private MemoryBlock _memoryBlock;
private readonly MemoryBlock _memoryBlock;
public Tests()
{
@ -19,6 +19,7 @@ namespace Ryujinx.Tests.Memory
public void Dispose()
{
GC.SuppressFinalize(this);
_memoryBlock.Dispose();
}
@ -38,9 +39,11 @@ namespace Ryujinx.Tests.Memory
Assert.Equal(0xbadc0de, Marshal.ReadInt32(_memoryBlock.Pointer, 0x2040));
}
[Fact]
[SkippableFact]
public void Test_Alias()
{
Skip.If(OperatingSystem.IsMacOS(), "Memory aliasing tests fail on CI at the moment.");
ulong pageSize = MemoryBlock.GetPageSize();
ulong blockSize = MemoryBlock.GetPageSize() * 16;
@ -54,11 +57,10 @@ namespace Ryujinx.Tests.Memory
Assert.Equal(0xbadc0de, Marshal.ReadInt32(backing.Pointer, (int)pageSize));
}
[Fact]
[SkippableFact]
public void Test_AliasRandom()
{
// Memory aliasing tests fail on CI at the moment.
Skip.If(OperatingSystem.IsMacOS());
Skip.If(OperatingSystem.IsMacOS(), "Memory aliasing tests fail on CI at the moment.");
ulong pageSize = MemoryBlock.GetPageSize();
int pageBits = (int)ulong.Log2(pageSize);
@ -91,11 +93,10 @@ namespace Ryujinx.Tests.Memory
}
}
[Fact]
[SkippableFact]
public void Test_AliasMapLeak()
{
// Memory aliasing tests fail on CI at the moment.
Skip.If(OperatingSystem.IsMacOS());
Skip.If(OperatingSystem.IsMacOS(), "Memory aliasing tests fail on CI at the moment.");
ulong pageSize = MemoryBlock.GetPageSize();
ulong size = 100000 * pageSize; // The mappings limit on Linux is usually around 65K, so let's make sure we are above that.

View file

@ -10,14 +10,12 @@ namespace Ryujinx.Tests.Memory
{
public class TrackingTests : IDisposable
{
private const int RndCnt = 3;
private const ulong MemorySize = 0x8000;
private const int PageSize = 4096;
private MemoryBlock _memoryBlock;
private MemoryTracking _tracking;
private MockVirtualMemoryManager _memoryManager;
private readonly MemoryBlock _memoryBlock;
private readonly MemoryTracking _tracking;
private readonly MockVirtualMemoryManager _memoryManager;
public TrackingTests()
{
@ -29,6 +27,7 @@ namespace Ryujinx.Tests.Memory
public void Dispose()
{
GC.SuppressFinalize(this);
_memoryBlock.Dispose();
}
@ -156,16 +155,25 @@ namespace Ryujinx.Tests.Memory
}
}
public static readonly RandomRangeUL2TheoryData TestDataPageAlignment = new(1ul, 65536ul, RndCnt);
public static readonly ulong[] RandomAddresses =
{
Random.Shared.NextULong(1ul, 65536ul),
Random.Shared.NextULong(1ul, 65536ul),
Random.Shared.NextULong(1ul, 65536ul),
};
public static readonly ulong[] RandomSizes =
{
Random.Shared.NextULong(1ul, 65536ul),
Random.Shared.NextULong(1ul, 65536ul),
Random.Shared.NextULong(1ul, 65536ul),
};
[Theory]
[InlineData(1ul, 1ul)]
[InlineData(512ul, 4ul)]
[InlineData(2048ul, 1024ul)]
[InlineData(4096ul, 4096ul)]
[InlineData(65536ul, 65536ul)]
[MemberData(nameof(TestDataPageAlignment))]
public void PageAlignment(ulong address, ulong size)
[CombinatorialData]
public void PageAlignment(
[CombinatorialValues(1ul, 512ul, 2048ul, 4096ul, 65536ul)][CombinatorialMemberData(nameof(RandomAddresses))] ulong address,
[CombinatorialValues(1ul, 4ul, 1024ul, 4096ul, 65536ul)][CombinatorialMemberData(nameof(RandomSizes))] ulong size)
{
ulong alignedStart = (address / PageSize) * PageSize;
ulong alignedEnd = ((address + size + PageSize - 1) / PageSize) * PageSize;
@ -294,8 +302,8 @@ namespace Ryujinx.Tests.Memory
}
Assert.True(dirtyFlagReprotects > 10);
Assert.True(writeTriggers >= 10);
Assert.True(handleLifecycles >= 10);
Assert.True(writeTriggers > 10);
Assert.True(handleLifecycles > 10);
}
[Fact]