fix-tests (#140)

- downgrade unicorn to last working version
- update to new cp reg struct system
- remove nonexistent register (used to silently continue)
- fix partial unmap tests
    - InitializeSignalHandler() was moved out of the translator (almost 2.5 years ago), but the test code was never updated to manually call the function as it was changed to do in the real cpu context, so the tests just started failing.
    - by manually initializing the handler we no longer cause tests to fail.

Reviewed-on: https://git.ryujinx.app/projects/Ryubing/pulls/140
This commit is contained in:
LotP
2026-06-15 02:25:18 +00:00
committed by LotP
parent 7b19e041cb
commit e777e3f93b
4 changed files with 53 additions and 5 deletions

View File

@@ -63,6 +63,6 @@
<PackageVersion Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.9" /> <PackageVersion Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.9" />
<PackageVersion Include="SPB" Version="0.0.4-build32" /> <PackageVersion Include="SPB" Version="0.0.4-build32" />
<PackageVersion Include="System.IO.Hashing" Version="9.0.15" /> <PackageVersion Include="System.IO.Hashing" Version="9.0.15" />
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.1.3" /> <PackageVersion Include="UnicornEngine.Unicorn" Version="2.1.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -53,7 +53,7 @@ namespace Ryujinx.Cpu.Signal
public SignalHandlerRangeArray Ranges; public SignalHandlerRangeArray Ranges;
} }
static class NativeSignalHandler public static class NativeSignalHandler
{ {
private static readonly nint _handlerConfig; private static readonly nint _handlerConfig;
private static nint _signalHandlerPtr; private static nint _signalHandlerPtr;

View File

@@ -1,10 +1,23 @@
using System; using System;
using System.Runtime.InteropServices;
using UnicornEngine.Const; using UnicornEngine.Const;
namespace Ryujinx.Tests.Unicorn namespace Ryujinx.Tests.Unicorn
{ {
public class UnicornAArch32 : IDisposable public class UnicornAArch32 : IDisposable
{ {
struct UcArmCpReg
{
public uint Cp;
public uint Is64;
public uint Sec;
public uint CRn;
public uint CRm;
public uint Opc1;
public uint Opc2;
public uint Val;
}
internal readonly UnicornEngine.Unicorn Uc; internal readonly UnicornEngine.Unicorn Uc;
private bool _isDisposed; private bool _isDisposed;
@@ -38,7 +51,7 @@ namespace Ryujinx.Tests.Unicorn
public int Fpscr public int Fpscr
{ {
get => (int)GetRegister(Arm.UC_ARM_REG_FPSCR) | ((int)GetRegister(Arm.UC_ARM_REG_FPSCR_NZCV)); get => (int)GetRegister(Arm.UC_ARM_REG_FPSCR);
set => SetRegister(Arm.UC_ARM_REG_FPSCR, (uint)value); set => SetRegister(Arm.UC_ARM_REG_FPSCR, (uint)value);
} }
@@ -86,7 +99,21 @@ namespace Ryujinx.Tests.Unicorn
{ {
Uc = new UnicornEngine.Unicorn(Common.UC_ARCH_ARM, Common.UC_MODE_LITTLE_ENDIAN); Uc = new UnicornEngine.Unicorn(Common.UC_ARCH_ARM, Common.UC_MODE_LITTLE_ENDIAN);
SetRegister(Arm.UC_ARM_REG_C1_C0_2, GetRegister(Arm.UC_ARM_REG_C1_C0_2) | 0xf00000); UcArmCpReg reg = new()
{
Cp = 15,
Is64 = 0,
Sec = 0,
CRn = 13,
Opc1 = 0,
CRm = 0,
Opc2 = 2
};
GetRegister(Arm.UC_ARM_REG_CP_REG, ref reg);
reg.Val |= 0xf00000;
SetRegister(Arm.UC_ARM_REG_CP_REG, reg);
SetRegister(Arm.UC_ARM_REG_FPEXC, 0x40000000); SetRegister(Arm.UC_ARM_REG_FPEXC, 0x40000000);
} }
@@ -204,6 +231,17 @@ namespace Ryujinx.Tests.Unicorn
SetVector(Arm.UC_ARM_REG_D0 + index * 2, value); SetVector(Arm.UC_ARM_REG_D0 + index * 2, value);
} }
public void GetRegister<T>(int register, ref T obj) where T : unmanaged
{
Span<T> span = new(ref obj);
Span<byte> dataSpan = MemoryMarshal.Cast<T, byte>(span);
byte[] data = dataSpan.ToArray();
Uc.RegRead(register, data);
data.AsSpan().CopyTo(dataSpan);
}
public uint GetRegister(int register) public uint GetRegister(int register)
{ {
byte[] data = new byte[4]; byte[] data = new byte[4];
@@ -213,6 +251,13 @@ namespace Ryujinx.Tests.Unicorn
return BitConverter.ToUInt32(data, 0); return BitConverter.ToUInt32(data, 0);
} }
public void SetRegister<T>(int register, T obj) where T : unmanaged
{
byte[] data = MemoryMarshal.Cast<T, byte>(new Span<T>(ref obj)).ToArray();
Uc.RegWrite(register, data);
}
public void SetRegister(int register, uint value) public void SetRegister(int register, uint value)
{ {
byte[] data = BitConverter.GetBytes(value); byte[] data = BitConverter.GetBytes(value);

View File

@@ -7,6 +7,7 @@ using Ryujinx.Common.Memory;
using Ryujinx.Common.Memory.PartialUnmaps; using Ryujinx.Common.Memory.PartialUnmaps;
using Ryujinx.Cpu; using Ryujinx.Cpu;
using Ryujinx.Cpu.Jit; using Ryujinx.Cpu.Jit;
using Ryujinx.Cpu.Signal;
using Ryujinx.Memory; using Ryujinx.Memory;
using Ryujinx.Memory.Tracking; using Ryujinx.Memory.Tracking;
using System; using System;
@@ -60,6 +61,8 @@ namespace Ryujinx.Tests.Memory
new JitMemoryAllocator(), new JitMemoryAllocator(),
new MockMemoryManager(), new MockMemoryManager(),
AddressTable<ulong>.CreateForArm(true, MemoryManagerType.SoftwarePageTable)); AddressTable<ulong>.CreateForArm(true, MemoryManagerType.SoftwarePageTable));
NativeSignalHandler.InitializeSignalHandler();
} }
[Test] [Test]