From 2b2ce68f07041189977515aa5b6ff6f04477d386 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Sun, 25 Jun 2023 18:37:53 +0200 Subject: [PATCH] [Ryujinx.Tests.Memory] Address dotnet-format issues (#5390) * dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Address dotnet format CA1822 warnings * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Add comments to disabled warnings * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Silence IDE0060 in .editorconfig * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * Final dotnet format pass and fix naming rule violations * Apply suggestions from code review Co-authored-by: Ac_K * Remove unused constant --------- Co-authored-by: Ac_K --- .../MultiRegionTrackingTests.cs | 21 ++++++------ src/Ryujinx.Tests.Memory/Tests.cs | 20 ++++++------ src/Ryujinx.Tests.Memory/TrackingTests.cs | 32 ++++++++++--------- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/Ryujinx.Tests.Memory/MultiRegionTrackingTests.cs b/src/Ryujinx.Tests.Memory/MultiRegionTrackingTests.cs index 674d23565..dffbe74d8 100644 --- a/src/Ryujinx.Tests.Memory/MultiRegionTrackingTests.cs +++ b/src/Ryujinx.Tests.Memory/MultiRegionTrackingTests.cs @@ -9,8 +9,6 @@ namespace Ryujinx.Tests.Memory { public class MultiRegionTrackingTests { - private const int RndCnt = 3; - private const ulong MemorySize = 0x8000; private const int PageSize = 4096; @@ -39,7 +37,7 @@ namespace Ryujinx.Tests.Memory (IMultiRegionHandle)_tracking.BeginGranularTracking(address, size, null, granularity, 0); } - private void RandomOrder(Random random, List indices, Action action) + private static void RandomOrder(Random random, List indices, Action action) { List choices = indices.ToList(); @@ -51,7 +49,7 @@ namespace Ryujinx.Tests.Memory } } - private int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func addressPredicate) + private static int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func addressPredicate) { int regionCount = 0; ulong lastAddress = startAddress; @@ -67,7 +65,7 @@ namespace Ryujinx.Tests.Memory return regionCount; } - private int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func addressPredicate, int sequenceNumber) + private static int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func addressPredicate, int sequenceNumber) { int regionCount = 0; ulong lastAddress = startAddress; @@ -83,9 +81,9 @@ namespace Ryujinx.Tests.Memory return regionCount; } - private void PreparePages(IMultiRegionHandle handle, int pageCount, ulong address = 0) + private static void PreparePages(IMultiRegionHandle handle, int pageCount, ulong address = 0) { - Random random = new Random(); + Random random = new(); // Make sure the list has minimum granularity (smart region changes granularity based on requested ranges) RandomOrder(random, Enumerable.Range(0, pageCount).ToList(), (i) => @@ -105,7 +103,7 @@ namespace Ryujinx.Tests.Memory const int pageCount = 32; IMultiRegionHandle handle = GetGranular(smart, 0, PageSize * pageCount, PageSize); - Random random = new Random(); + Random random = new(); PreparePages(handle, pageCount); @@ -149,7 +147,7 @@ namespace Ryujinx.Tests.Memory PreparePages(handle, pageCount); - Random random = new Random(); + Random random = new(); IEnumerable halfRange = Enumerable.Range(0, pageCount / 2); List odd = halfRange.Select(x => x * 2 + 1).ToList(); @@ -240,7 +238,8 @@ namespace Ryujinx.Tests.Memory ulong expectedAddress = 0; // Expect each region to trigger in its entirety, in address ascending order. - handle.QueryModified((address, size) => { + handle.QueryModified((address, size) => + { int region = regionSizes[regionInd++]; Assert.AreEqual(address, expectedAddress); @@ -437,4 +436,4 @@ namespace Ryujinx.Tests.Memory Assert.AreEqual(pagesModified, new bool[] { true, false, false }); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Tests.Memory/Tests.cs b/src/Ryujinx.Tests.Memory/Tests.cs index 5ab01d5a5..bfc6344b7 100644 --- a/src/Ryujinx.Tests.Memory/Tests.cs +++ b/src/Ryujinx.Tests.Memory/Tests.cs @@ -7,14 +7,14 @@ namespace Ryujinx.Tests.Memory { public class Tests { - private static readonly ulong MemorySize = MemoryBlock.GetPageSize() * 8; + private static readonly ulong _memorySize = MemoryBlock.GetPageSize() * 8; private MemoryBlock _memoryBlock; [SetUp] public void Setup() { - _memoryBlock = new MemoryBlock(MemorySize); + _memoryBlock = new MemoryBlock(_memorySize); } [TearDown] @@ -47,8 +47,8 @@ namespace Ryujinx.Tests.Memory ulong pageSize = MemoryBlock.GetPageSize(); ulong blockSize = MemoryBlock.GetPageSize() * 16; - using MemoryBlock backing = new MemoryBlock(blockSize, MemoryAllocationFlags.Mirrorable); - using MemoryBlock toAlias = new MemoryBlock(blockSize, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible); + using MemoryBlock backing = new(blockSize, MemoryAllocationFlags.Mirrorable); + using MemoryBlock toAlias = new(blockSize, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible); toAlias.MapView(backing, pageSize, 0, pageSize * 4); toAlias.UnmapView(backing, pageSize * 3, pageSize); @@ -66,10 +66,10 @@ namespace Ryujinx.Tests.Memory int pageBits = (int)ulong.Log2(pageSize); ulong blockSize = MemoryBlock.GetPageSize() * 128; - using MemoryBlock backing = new MemoryBlock(blockSize, MemoryAllocationFlags.Mirrorable); - using MemoryBlock toAlias = new MemoryBlock(blockSize, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible); + using MemoryBlock backing = new(blockSize, MemoryAllocationFlags.Mirrorable); + using MemoryBlock toAlias = new(blockSize, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible); - Random rng = new Random(123); + Random rng = new(123); for (int i = 0; i < 20000; i++) { @@ -101,8 +101,8 @@ namespace Ryujinx.Tests.Memory 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. - using MemoryBlock backing = new MemoryBlock(pageSize, MemoryAllocationFlags.Mirrorable); - using MemoryBlock toAlias = new MemoryBlock(size, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible); + using MemoryBlock backing = new(pageSize, MemoryAllocationFlags.Mirrorable); + using MemoryBlock toAlias = new(size, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible); for (ulong offset = 0; offset < size; offset += pageSize) { @@ -115,4 +115,4 @@ namespace Ryujinx.Tests.Memory } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Tests.Memory/TrackingTests.cs b/src/Ryujinx.Tests.Memory/TrackingTests.cs index faf295575..dce73cf4f 100644 --- a/src/Ryujinx.Tests.Memory/TrackingTests.cs +++ b/src/Ryujinx.Tests.Memory/TrackingTests.cs @@ -102,15 +102,17 @@ namespace Ryujinx.Tests.Memory allHandle.Reprotect(); (ulong address, ulong size)? readTrackingTriggeredAll = null; - Action registerReadAction = () => + + void RegisterReadAction() { readTrackingTriggeredAll = null; allHandle.RegisterAction((address, size) => { readTrackingTriggeredAll = (address, size); }); - }; - registerReadAction(); + } + + RegisterReadAction(); // Create 16 page sized handles contained within the allHandle. RegionHandle[] containedHandles = new RegionHandle[16]; @@ -149,7 +151,7 @@ namespace Ryujinx.Tests.Memory } // Clear flags and reset read action. - registerReadAction(); + RegisterReadAction(); allHandle.Reprotect(); containedHandles[i].Reprotect(); } @@ -157,8 +159,8 @@ namespace Ryujinx.Tests.Memory [Test] public void PageAlignment( - [Values(1ul, 512ul, 2048ul, 4096ul, 65536ul)] [Random(1ul, 65536ul, RndCnt)] ulong address, - [Values(1ul, 4ul, 1024ul, 4096ul, 65536ul)] [Random(1ul, 65536ul, RndCnt)] ulong size) + [Values(1ul, 512ul, 2048ul, 4096ul, 65536ul)][Random(1ul, 65536ul, RndCnt)] ulong address, + [Values(1ul, 4ul, 1024ul, 4096ul, 65536ul)][Random(1ul, 65536ul, RndCnt)] ulong size) { ulong alignedStart = (address / PageSize) * PageSize; ulong alignedEnd = ((address + size + PageSize - 1) / PageSize) * PageSize; @@ -204,7 +206,7 @@ namespace Ryujinx.Tests.Memory long finishedTime = 0; RegionHandle[] handles = new RegionHandle[threadCount * handlesPerThread]; - Random globalRand = new Random(); + Random globalRand = new(); for (int i = 0; i < handles.Length; i++) { @@ -212,7 +214,7 @@ namespace Ryujinx.Tests.Memory handles[i].Reprotect(); } - List testThreads = new List(); + List testThreads = new(); // Dirty flag consumer threads int dirtyFlagReprotects = 0; @@ -224,7 +226,7 @@ namespace Ryujinx.Tests.Memory int handleBase = randSeed * handlesPerThread; while (Stopwatch.GetTimestamp() < finishedTime) { - Random random = new Random(randSeed); + Random random = new(randSeed); RegionHandle handle = handles[handleBase + random.Next(handlesPerThread)]; if (handle.Dirty) @@ -243,7 +245,7 @@ namespace Ryujinx.Tests.Memory int randSeed = i; testThreads.Add(new Thread(() => { - Random random = new Random(randSeed); + Random random = new(randSeed); ulong handleBase = (ulong)(randSeed * handlesPerThread * PageSize); while (Stopwatch.GetTimestamp() < finishedTime) { @@ -261,7 +263,7 @@ namespace Ryujinx.Tests.Memory testThreads.Add(new Thread(() => { int maxAddress = threadCount * handlesPerThread * PageSize; - Random random = new Random(randSeed + 512); + Random random = new(randSeed + 512); while (Stopwatch.GetTimestamp() < finishedTime) { RegionHandle handle = _tracking.BeginTracking((ulong)random.Next(maxAddress), (ulong)random.Next(65536), 0); @@ -303,7 +305,7 @@ namespace Ryujinx.Tests.Memory int signalThreadsDone = 0; bool isRegistered = false; - Action registerReadAction = () => + void RegisterReadAction() { registeredCount++; handle.RegisterAction((address, size) => @@ -311,7 +313,7 @@ namespace Ryujinx.Tests.Memory isRegistered = false; Interlocked.Increment(ref triggeredCount); }); - }; + } const int threadCount = 16; const int iterationCount = 10000; @@ -322,7 +324,7 @@ namespace Ryujinx.Tests.Memory int randSeed = i; signalThreads[i] = new Thread(() => { - Random random = new Random(randSeed); + Random random = new(randSeed); for (int j = 0; j < iterationCount; j++) { _tracking.VirtualMemoryEvent((ulong)random.Next(PageSize), 4, false); @@ -346,7 +348,7 @@ namespace Ryujinx.Tests.Memory if (!isRegistered) { isRegistered = true; - registerReadAction(); + RegisterReadAction(); } }