From f16119c183b47348cff6bf93c4c06add16f642b6 Mon Sep 17 00:00:00 2001 From: TSR Berry <20988865+TSRBerry@users.noreply.github.com> Date: Sat, 8 Jul 2023 23:57:14 +0200 Subject: [PATCH] Convert ALU binary CPU tests to xUnit --- src/Ryujinx.Tests/Cpu/CpuTestAluBinary.cs | 237 ++++++++++---------- src/Ryujinx.Tests/Cpu/CpuTestAluBinary32.cs | 32 ++- 2 files changed, 147 insertions(+), 122 deletions(-) diff --git a/src/Ryujinx.Tests/Cpu/CpuTestAluBinary.cs b/src/Ryujinx.Tests/Cpu/CpuTestAluBinary.cs index f40c621e2..e56531586 100644 --- a/src/Ryujinx.Tests/Cpu/CpuTestAluBinary.cs +++ b/src/Ryujinx.Tests/Cpu/CpuTestAluBinary.cs @@ -1,5 +1,7 @@ -// #define AluBinary +#define AluBinary +using ARMeilleure.State; +using System; using Xunit; namespace Ryujinx.Tests.Cpu @@ -52,12 +54,35 @@ namespace Ryujinx.Tests.Cpu } #endregion - [Test, Combinatorial] - public void Crc32_b_h_w_x([Values(0u)] uint rd, - [Values(1u)] uint rn, - [Values(2u)] uint rm, - [Range(0u, 3u)] uint size, - [ValueSource(nameof(_CRC32_Test_Values_))] CrcTest test) + private static readonly ulong[] _testData_xn = + { + 0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul, + 0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul, + }; + private static readonly uint[] _testData_wn = + { + 0x00000000u, 0x7FFFFFFFu, + 0x80000000u, 0xFFFFFFFFu, + }; + + private static readonly uint[] _testData_Crc32_rd = + { + 0u, + }; + private static readonly uint[] _testData_Crc32_rn = + { + 1u, + }; + private static readonly uint[] _testData_Crc32_rm = + { + 2u, + }; + + public static readonly MatrixTheoryData TestData_Crc32 = new(_testData_Crc32_rd, _testData_Crc32_rn, _testData_Crc32_rm, RangeUtils.RangeData(0u, 3u, 1u), _CRC32_Test_Values_()); + + [Theory] + [MemberData(nameof(TestData_Crc32))] + public void Crc32_b_h_w_x(uint rd, uint rn, uint rm, uint size, CrcTest test) { uint opcode = 0x1AC04000; // CRC32B W0, W0, W0 @@ -69,233 +94,219 @@ namespace Ryujinx.Tests.Cpu opcode |= 0x80000000; } - uint w31 = TestContext.CurrentContext.Random.NextUInt(); + uint w31 = Random.Shared.NextUInt(); SingleOpcode(opcode, x1: test.Crc, x2: test.Value, x31: w31, runUnicorn: false); ExecutionContext context = GetContext(); ulong result = context.GetX((int)rd); - Assert.That(result == test.Results[size]); + Assert.True(result == test.Results[size]); } - [Test, Pairwise, Description("CRC32X , , "), Ignore("Unicorn fails.")] - public void Crc32x([Values(0u, 31u)] uint rd, - [Values(1u, 31u)] uint rn, - [Values(2u, 31u)] uint rm, - [Values(0x00000000u, 0xFFFFFFFFu)] uint wn, - [Values((ulong)0x00_00_00_00_00_00_00_00, - (ulong)0x7F_FF_FF_FF_FF_FF_FF_FF, - 0x80_00_00_00_00_00_00_00, - 0xFF_FF_FF_FF_FF_FF_FF_FF)] ulong xm) + private static readonly uint[] _testData_Crc32x_rd = + { + 0u, 31u, + }; + private static readonly uint[] _testData_Crc32x_rn = + { + 1u, 31u, + }; + private static readonly uint[] _testData_Crc32x_rm = + { + 2u, 31u, + }; + + private static readonly uint[] _testData_Crc32x_wn = + { + 0x00000000u, 0xFFFFFFFFu, + }; + + public static readonly MatrixTheoryData TestData_Crc32x = new(_testData_Crc32x_rd, _testData_Crc32x_rn, _testData_Crc32x_rm, _testData_Crc32x_wn, _testData_xn); + + [Theory(DisplayName = "CRC32X , , ", Skip = "Unicorn fails.")] + [MemberData(nameof(TestData_Crc32x))] + public void Crc32x(uint rd, uint rn, uint rm, uint wn, ulong xm) { uint opcode = 0x9AC04C00; // CRC32X W0, W0, X0 opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0); - uint w31 = TestContext.CurrentContext.Random.NextUInt(); + uint w31 = Random.Shared.NextUInt(); SingleOpcode(opcode, x1: wn, x2: xm, x31: w31); CompareAgainstUnicorn(); } - [Test, Pairwise, Description("CRC32W , , "), Ignore("Unicorn fails.")] - public void Crc32w([Values(0u, 31u)] uint rd, - [Values(1u, 31u)] uint rn, - [Values(2u, 31u)] uint rm, - [Values(0x00000000u, 0xFFFFFFFFu)] uint wn, - [Values((uint)0x00_00_00_00, (uint)0x7F_FF_FF_FF, - 0x80_00_00_00, 0xFF_FF_FF_FF)] uint wm) + public static readonly MatrixTheoryData TestData_Crc32w = new(_testData_Crc32x_rd, _testData_Crc32x_rn, _testData_Crc32x_rm, _testData_Crc32x_wn, _testData_wn); + + [Theory(DisplayName = "CRC32W , , ", Skip = "Unicorn fails.")] + [MemberData(nameof(TestData_Crc32w))] + public void Crc32w(uint rd, uint rn, uint rm, uint wn, uint wm) { uint opcode = 0x1AC04800; // CRC32W W0, W0, W0 opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0); - uint w31 = TestContext.CurrentContext.Random.NextUInt(); + uint w31 = Random.Shared.NextUInt(); SingleOpcode(opcode, x1: wn, x2: wm, x31: w31); CompareAgainstUnicorn(); } - [Test, Pairwise, Description("CRC32H , , "), Ignore("Unicorn fails.")] - public void Crc32h([Values(0u, 31u)] uint rd, - [Values(1u, 31u)] uint rn, - [Values(2u, 31u)] uint rm, - [Values(0x00000000u, 0xFFFFFFFFu)] uint wn, - [Values((ushort)0x00_00, (ushort)0x7F_FF, - (ushort)0x80_00, (ushort)0xFF_FF)] ushort wm) + private static readonly ushort[] _testData_Crc32h_wm = + { + 0x00_00, 0x7F_FF, + 0x80_00, 0xFF_FF, + }; + + public static readonly MatrixTheoryData TestData_Crc32h = new(_testData_Crc32x_rd, _testData_Crc32x_rn, _testData_Crc32x_rm, _testData_Crc32x_wn, _testData_Crc32h_wm); + + [Theory(DisplayName = "CRC32H , , ", Skip = "Unicorn fails.")] + [MemberData(nameof(TestData_Crc32h))] + public void Crc32h(uint rd, uint rn, uint rm, uint wn, ushort wm) { uint opcode = 0x1AC04400; // CRC32H W0, W0, W0 opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0); - uint w31 = TestContext.CurrentContext.Random.NextUInt(); + uint w31 = Random.Shared.NextUInt(); SingleOpcode(opcode, x1: wn, x2: wm, x31: w31); CompareAgainstUnicorn(); } - [Test, Pairwise, Description("CRC32B , , "), Ignore("Unicorn fails.")] - public void Crc32b([Values(0u, 31u)] uint rd, - [Values(1u, 31u)] uint rn, - [Values(2u, 31u)] uint rm, - [Values(0x00000000u, 0xFFFFFFFFu)] uint wn, - [Values((byte)0x00, (byte)0x7F, - (byte)0x80, (byte)0xFF)] byte wm) + private static readonly byte[] _testData_Crc32b_wm = + { + 0x00, 0x7F, + 0x80, 0xFF, + }; + + public static readonly MatrixTheoryData TestData_Crc32b = new(_testData_Crc32x_rd, _testData_Crc32x_rn, _testData_Crc32x_rm, _testData_Crc32x_wn, _testData_Crc32b_wm); + + [Theory(DisplayName = "CRC32B , , ", Skip = "Unicorn fails.")] + [MemberData(nameof(TestData_Crc32b))] + public void Crc32b(uint rd, uint rn, uint rm, uint wn, byte wm) { uint opcode = 0x1AC04000; // CRC32B W0, W0, W0 opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0); - uint w31 = TestContext.CurrentContext.Random.NextUInt(); + uint w31 = Random.Shared.NextUInt(); SingleOpcode(opcode, x1: wn, x2: wm, x31: w31); CompareAgainstUnicorn(); } - [Test, Pairwise, Description("CRC32CX , , ")] - public void Crc32cx([Values(0u, 31u)] uint rd, - [Values(1u, 31u)] uint rn, - [Values(2u, 31u)] uint rm, - [Values(0x00000000u, 0xFFFFFFFFu)] uint wn, - [Values((ulong)0x00_00_00_00_00_00_00_00, - (ulong)0x7F_FF_FF_FF_FF_FF_FF_FF, - 0x80_00_00_00_00_00_00_00, - 0xFF_FF_FF_FF_FF_FF_FF_FF)] ulong xm) + [Theory(DisplayName = "CRC32CX , , ")] + [MemberData(nameof(TestData_Crc32x))] + public void Crc32cx(uint rd, uint rn, uint rm, uint wn, ulong xm) { uint opcode = 0x9AC05C00; // CRC32CX W0, W0, X0 opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0); - uint w31 = TestContext.CurrentContext.Random.NextUInt(); + uint w31 = Random.Shared.NextUInt(); SingleOpcode(opcode, x1: wn, x2: xm, x31: w31); CompareAgainstUnicorn(); } - [Test, Pairwise, Description("CRC32CW , , ")] - public void Crc32cw([Values(0u, 31u)] uint rd, - [Values(1u, 31u)] uint rn, - [Values(2u, 31u)] uint rm, - [Values(0x00000000u, 0xFFFFFFFFu)] uint wn, - [Values((uint)0x00_00_00_00, (uint)0x7F_FF_FF_FF, - 0x80_00_00_00, 0xFF_FF_FF_FF)] uint wm) + [Theory(DisplayName = "CRC32CW , , ")] + [MemberData(nameof(TestData_Crc32w))] + public void Crc32cw(uint rd, uint rn, uint rm, uint wn, uint wm) { uint opcode = 0x1AC05800; // CRC32CW W0, W0, W0 opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0); - uint w31 = TestContext.CurrentContext.Random.NextUInt(); + uint w31 = Random.Shared.NextUInt(); SingleOpcode(opcode, x1: wn, x2: wm, x31: w31); CompareAgainstUnicorn(); } - [Test, Pairwise, Description("CRC32CH , , ")] - public void Crc32ch([Values(0u, 31u)] uint rd, - [Values(1u, 31u)] uint rn, - [Values(2u, 31u)] uint rm, - [Values(0x00000000u, 0xFFFFFFFFu)] uint wn, - [Values((ushort)0x00_00, (ushort)0x7F_FF, - (ushort)0x80_00, (ushort)0xFF_FF)] ushort wm) + [Theory(DisplayName = "CRC32CH , , ")] + [MemberData(nameof(TestData_Crc32h))] + public void Crc32ch(uint rd, uint rn, uint rm, uint wn, ushort wm) { uint opcode = 0x1AC05400; // CRC32CH W0, W0, W0 opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0); - uint w31 = TestContext.CurrentContext.Random.NextUInt(); + uint w31 = Random.Shared.NextUInt(); SingleOpcode(opcode, x1: wn, x2: wm, x31: w31); CompareAgainstUnicorn(); } - [Test, Pairwise, Description("CRC32CB , , ")] - public void Crc32cb([Values(0u, 31u)] uint rd, - [Values(1u, 31u)] uint rn, - [Values(2u, 31u)] uint rm, - [Values(0x00000000u, 0xFFFFFFFFu)] uint wn, - [Values((byte)0x00, (byte)0x7F, - (byte)0x80, (byte)0xFF)] byte wm) + [Theory(DisplayName = "CRC32CB , , ")] + [MemberData(nameof(TestData_Crc32b))] + public void Crc32cb(uint rd, uint rn, uint rm, uint wn, byte wm) { uint opcode = 0x1AC05000; // CRC32CB W0, W0, W0 opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0); - uint w31 = TestContext.CurrentContext.Random.NextUInt(); + uint w31 = Random.Shared.NextUInt(); SingleOpcode(opcode, x1: wn, x2: wm, x31: w31); CompareAgainstUnicorn(); } - [Test, Pairwise, Description("SDIV , , ")] - public void Sdiv_64bit([Values(0u, 31u)] uint rd, - [Values(1u, 31u)] uint rn, - [Values(2u, 31u)] uint rm, - [Values(0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul, - 0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul)] ulong xn, - [Values(0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul, - 0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul)] ulong xm) + public static readonly MatrixTheoryData TestData_Sdiv64 = new(_testData_Crc32x_rd, _testData_Crc32x_rn, _testData_Crc32x_rm, _testData_xn, _testData_xn); + + [Theory(DisplayName = "SDIV , , ")] + [MemberData(nameof(TestData_Sdiv64))] + public void Sdiv_64bit(uint rd, uint rn, uint rm, ulong xn, ulong xm) { uint opcode = 0x9AC00C00; // SDIV X0, X0, X0 opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0); - ulong x31 = TestContext.CurrentContext.Random.NextULong(); + ulong x31 = Random.Shared.NextULong(); SingleOpcode(opcode, x1: xn, x2: xm, x31: x31); CompareAgainstUnicorn(); } - [Test, Pairwise, Description("SDIV , , ")] - public void Sdiv_32bit([Values(0u, 31u)] uint rd, - [Values(1u, 31u)] uint rn, - [Values(2u, 31u)] uint rm, - [Values(0x00000000u, 0x7FFFFFFFu, - 0x80000000u, 0xFFFFFFFFu)] uint wn, - [Values(0x00000000u, 0x7FFFFFFFu, - 0x80000000u, 0xFFFFFFFFu)] uint wm) + public static readonly MatrixTheoryData TestData_Sdiv32 = new(_testData_Crc32x_rd, _testData_Crc32x_rn, _testData_Crc32x_rm, _testData_wn, _testData_wn); + + [Theory(DisplayName = "SDIV , , ")] + [MemberData(nameof(TestData_Sdiv32))] + public void Sdiv_32bit(uint rd, uint rn, uint rm, uint wn, uint wm) { uint opcode = 0x1AC00C00; // SDIV W0, W0, W0 opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0); - uint w31 = TestContext.CurrentContext.Random.NextUInt(); + uint w31 = Random.Shared.NextUInt(); SingleOpcode(opcode, x1: wn, x2: wm, x31: w31); CompareAgainstUnicorn(); } - [Test, Pairwise, Description("UDIV , , ")] - public void Udiv_64bit([Values(0u, 31u)] uint rd, - [Values(1u, 31u)] uint rn, - [Values(2u, 31u)] uint rm, - [Values(0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul, - 0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul)] ulong xn, - [Values(0x0000000000000000ul, 0x7FFFFFFFFFFFFFFFul, - 0x8000000000000000ul, 0xFFFFFFFFFFFFFFFFul)] ulong xm) + [Theory(DisplayName = "UDIV , , ")] + [MemberData(nameof(TestData_Sdiv64))] + public void Udiv_64bit(uint rd, uint rn, uint rm, ulong xn, ulong xm) { uint opcode = 0x9AC00800; // UDIV X0, X0, X0 opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0); - ulong x31 = TestContext.CurrentContext.Random.NextULong(); + ulong x31 = Random.Shared.NextULong(); SingleOpcode(opcode, x1: xn, x2: xm, x31: x31); CompareAgainstUnicorn(); } - [Test, Pairwise, Description("UDIV , , ")] - public void Udiv_32bit([Values(0u, 31u)] uint rd, - [Values(1u, 31u)] uint rn, - [Values(2u, 31u)] uint rm, - [Values(0x00000000u, 0x7FFFFFFFu, - 0x80000000u, 0xFFFFFFFFu)] uint wn, - [Values(0x00000000u, 0x7FFFFFFFu, - 0x80000000u, 0xFFFFFFFFu)] uint wm) + [Theory(DisplayName = "UDIV , , ")] + [MemberData(nameof(TestData_Sdiv32))] + public void Udiv_32bit(uint rd, uint rn, uint rm, uint wn, uint wm) { uint opcode = 0x1AC00800; // UDIV W0, W0, W0 opcode |= ((rm & 31) << 16) | ((rn & 31) << 5) | ((rd & 31) << 0); - uint w31 = TestContext.CurrentContext.Random.NextUInt(); + uint w31 = Random.Shared.NextUInt(); SingleOpcode(opcode, x1: wn, x2: wm, x31: w31); diff --git a/src/Ryujinx.Tests/Cpu/CpuTestAluBinary32.cs b/src/Ryujinx.Tests/Cpu/CpuTestAluBinary32.cs index 9c2700fa3..58aa48a74 100644 --- a/src/Ryujinx.Tests/Cpu/CpuTestAluBinary32.cs +++ b/src/Ryujinx.Tests/Cpu/CpuTestAluBinary32.cs @@ -1,5 +1,7 @@ -// #define AluBinary32 +#define AluBinary32 +using ARMeilleure.State; +using System; using Xunit; namespace Ryujinx.Tests.Cpu @@ -64,12 +66,24 @@ namespace Ryujinx.Tests.Cpu } #endregion - [Test, Combinatorial] - public void Crc32_Crc32c_b_h_w([Values(0u)] uint rd, - [Values(1u)] uint rn, - [Values(2u)] uint rm, - [Range(0u, 2u)] uint size, - [ValueSource(nameof(_CRC32_Test_Values_))] CrcTest32 test) + private static uint[] _testData_rd = + { + 0u, + }; + private static uint[] _testData_rn = + { + 1u, + }; + private static uint[] _testData_rm = + { + 2u, + }; + + public static readonly MatrixTheoryData TestData = new(_testData_rd, _testData_rn, _testData_rm, RangeUtils.RangeData(0u, 2u, 1u), _CRC32_Test_Values_()); + + [Theory] + [MemberData(nameof(TestData))] + public void Crc32_Crc32c_b_h_w(uint rd, uint rn, uint rm, uint size, CrcTest32 test) { // Unicorn does not yet support 32bit crc instructions, so test against a known table of results/values. @@ -81,13 +95,13 @@ namespace Ryujinx.Tests.Cpu opcode |= 1 << 9; } - uint sp = TestContext.CurrentContext.Random.NextUInt(); + uint sp = Random.Shared.NextUInt(); SingleOpcode(opcode, r1: test.Crc, r2: test.Value, sp: sp, runUnicorn: false); ExecutionContext context = GetContext(); ulong result = context.GetX((int)rd); - Assert.That(result == test.Results[size]); + Assert.True(result == test.Results[size]); } #endif }