/ src / Ryujinx.Tests / Cpu / CpuTestSystem.cs
CpuTestSystem.cs
 1  #define System
 2  
 3  using ARMeilleure.State;
 4  using NUnit.Framework;
 5  using System.Collections.Generic;
 6  
 7  namespace Ryujinx.Tests.Cpu
 8  {
 9      [Category("System")]
10      public sealed class CpuTestSystem : CpuTest
11      {
12  #if System
13  
14          #region "ValueSource (Types)"
15          private static IEnumerable<ulong> _GenNzcv_()
16          {
17              yield return 0x0000000000000000ul;
18              yield return 0x7FFFFFFFFFFFFFFFul;
19              yield return 0x8000000000000000ul;
20              yield return 0xFFFFFFFFFFFFFFFFul;
21  
22              bool v = TestContext.CurrentContext.Random.NextBool();
23              bool c = TestContext.CurrentContext.Random.NextBool();
24              bool z = TestContext.CurrentContext.Random.NextBool();
25              bool n = TestContext.CurrentContext.Random.NextBool();
26  
27              ulong rnd = 0UL;
28  
29              rnd |= (v ? 1UL : 0UL) << (int)PState.VFlag;
30              rnd |= (c ? 1UL : 0UL) << (int)PState.CFlag;
31              rnd |= (z ? 1UL : 0UL) << (int)PState.ZFlag;
32              rnd |= (n ? 1UL : 0UL) << (int)PState.NFlag;
33  
34              yield return rnd;
35          }
36          #endregion
37  
38          #region "ValueSource (Opcodes)"
39          private static uint[] _MrsMsr_Nzcv_()
40          {
41              return new[]
42              {
43                  0xD53B4200u, // MRS X0, NZCV
44                  0xD51B4200u, // MSR NZCV, X0
45              };
46          }
47          #endregion
48  
49          [Test, Pairwise]
50          public void MrsMsr_Nzcv([ValueSource(nameof(_MrsMsr_Nzcv_))] uint opcodes,
51                                  [Values(0u, 1u, 31u)] uint rt,
52                                  [ValueSource(nameof(_GenNzcv_))] ulong xt)
53          {
54              opcodes |= (rt & 31) << 0;
55  
56              bool v = TestContext.CurrentContext.Random.NextBool();
57              bool c = TestContext.CurrentContext.Random.NextBool();
58              bool z = TestContext.CurrentContext.Random.NextBool();
59              bool n = TestContext.CurrentContext.Random.NextBool();
60  
61              ulong x31 = TestContext.CurrentContext.Random.NextULong();
62  
63              SingleOpcode(opcodes, x0: xt, x1: xt, x31: x31, overflow: v, carry: c, zero: z, negative: n);
64  
65              CompareAgainstUnicorn();
66          }
67  #endif
68      }
69  }