From c903c7b2274efbcb9042dc6acb463852cb3cc103 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Thu, 15 Feb 2018 19:35:50 +0000 Subject: [PATCH] Add tests --- Ryujinx.Tests/Cpu/CpuTest.cs | 67 ++++++++++++++++++++++++ Ryujinx.Tests/Ryujinx.Tests.csproj | 17 ++++++ Ryujinx.sln | 8 ++- Ryujinx/Cpu/AThread.cs | 2 +- Ryujinx.conf => Ryujinx/Ryujinx.conf | 0 Ryujinx.csproj => Ryujinx/Ryujinx.csproj | 0 GLScreen.cs => Ryujinx/Ui/GLScreen.cs | 0 Program.cs => Ryujinx/Ui/Program.cs | 0 8 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 Ryujinx.Tests/Cpu/CpuTest.cs create mode 100644 Ryujinx.Tests/Ryujinx.Tests.csproj rename Ryujinx.conf => Ryujinx/Ryujinx.conf (100%) rename Ryujinx.csproj => Ryujinx/Ryujinx.csproj (100%) rename GLScreen.cs => Ryujinx/Ui/GLScreen.cs (100%) rename Program.cs => Ryujinx/Ui/Program.cs (100%) diff --git a/Ryujinx.Tests/Cpu/CpuTest.cs b/Ryujinx.Tests/Cpu/CpuTest.cs new file mode 100644 index 0000000000..44e0ce878c --- /dev/null +++ b/Ryujinx.Tests/Cpu/CpuTest.cs @@ -0,0 +1,67 @@ +using ChocolArm64; +using ChocolArm64.Memory; +using ChocolArm64.State; +using NUnit.Framework; +using System; +using System.Runtime.InteropServices; +using System.Threading; + +namespace Ryujinx.Tests.Cpu +{ + [TestFixture] + public partial class CpuTest + { + IntPtr Ram; + AMemoryAlloc Allocator; + AMemory Memory; + + [SetUp] + public void Setup() + { + Ram = Marshal.AllocHGlobal((IntPtr)AMemoryMgr.RamSize); + Allocator = new AMemoryAlloc(); + Memory = new AMemory(Ram, Allocator); + Memory.Manager.MapPhys(0x1000, 0x1000, 2, AMemoryPerm.Read | AMemoryPerm.Write | AMemoryPerm.Execute); + } + + private void Execute(AThread Thread) + { + AutoResetEvent Wait = new AutoResetEvent(false); + Thread.Registers.Break += (sender, e) => Thread.StopExecution(); + Thread.WorkFinished += (sender, e) => Wait.Set(); + + Wait.Reset(); + Thread.Execute(); + Wait.WaitOne(); + } + + private ARegisters SingleOpcode(uint Opcode, + ulong X0 = 0, ulong X1 = 0, ulong X2 = 0, + AVec V0 = new AVec(), AVec V1 = new AVec(), AVec V2 = new AVec()) + { + Memory.WriteUInt32(0x1000, Opcode); + Memory.WriteUInt32(0x1004, 0xD4200000); // BRK #0 + Memory.WriteUInt32(0x1008, 0xD65F03C0); // RET + + AThread Thread = new AThread(Memory, ThreadPriority.Normal, 0x1000); + Thread.Registers.X0 = X0; + Thread.Registers.X1 = X1; + Thread.Registers.X2 = X2; + Thread.Registers.V0 = V0; + Thread.Registers.V1 = V1; + Thread.Registers.V2 = V2; + Execute(Thread); + return Thread.Registers; + } + + [Test] + public void SanityCheck() + { + uint Opcode = 0xD503201F; // NOP + Assert.AreEqual(SingleOpcode(Opcode, X0: 0).X0, 0); + Assert.AreEqual(SingleOpcode(Opcode, X0: 1).X0, 1); + Assert.AreEqual(SingleOpcode(Opcode, X0: 2).X0, 2); + Assert.AreEqual(SingleOpcode(Opcode, X0: 42).X0, 42); + } + } +} diff --git a/Ryujinx.Tests/Ryujinx.Tests.csproj b/Ryujinx.Tests/Ryujinx.Tests.csproj new file mode 100644 index 0000000000..f8b430e62f --- /dev/null +++ b/Ryujinx.Tests/Ryujinx.Tests.csproj @@ -0,0 +1,17 @@ + + + netcoreapp2.0 + false + + + false + + + + + + + + + + diff --git a/Ryujinx.sln b/Ryujinx.sln index c75364f712..777539885e 100644 --- a/Ryujinx.sln +++ b/Ryujinx.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26730.8 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx", "Ryujinx.csproj", "{074045D4-3ED2-4711-9169-E385F2BFB5A0}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ryujinx", "Ryujinx\Ryujinx.csproj", "{074045D4-3ED2-4711-9169-E385F2BFB5A0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ryujinx.Tests", "Ryujinx.Tests\Ryujinx.Tests.csproj", "{EBB55AEA-C7D7-4DEB-BF96-FA1789E225E9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {074045D4-3ED2-4711-9169-E385F2BFB5A0}.Debug|Any CPU.Build.0 = Debug|Any CPU {074045D4-3ED2-4711-9169-E385F2BFB5A0}.Release|Any CPU.ActiveCfg = Release|Any CPU {074045D4-3ED2-4711-9169-E385F2BFB5A0}.Release|Any CPU.Build.0 = Release|Any CPU + {EBB55AEA-C7D7-4DEB-BF96-FA1789E225E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EBB55AEA-C7D7-4DEB-BF96-FA1789E225E9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EBB55AEA-C7D7-4DEB-BF96-FA1789E225E9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EBB55AEA-C7D7-4DEB-BF96-FA1789E225E9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Ryujinx/Cpu/AThread.cs b/Ryujinx/Cpu/AThread.cs index 93331825ce..400e700ddb 100644 --- a/Ryujinx/Cpu/AThread.cs +++ b/Ryujinx/Cpu/AThread.cs @@ -5,7 +5,7 @@ using System.Threading; namespace ChocolArm64 { - class AThread + public class AThread { public ARegisters Registers { get; private set; } public AMemory Memory { get; private set; } diff --git a/Ryujinx.conf b/Ryujinx/Ryujinx.conf similarity index 100% rename from Ryujinx.conf rename to Ryujinx/Ryujinx.conf diff --git a/Ryujinx.csproj b/Ryujinx/Ryujinx.csproj similarity index 100% rename from Ryujinx.csproj rename to Ryujinx/Ryujinx.csproj diff --git a/GLScreen.cs b/Ryujinx/Ui/GLScreen.cs similarity index 100% rename from GLScreen.cs rename to Ryujinx/Ui/GLScreen.cs diff --git a/Program.cs b/Ryujinx/Ui/Program.cs similarity index 100% rename from Program.cs rename to Ryujinx/Ui/Program.cs