From d5f2137f54edfdd1385b2ec542cfefc07430f288 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Wed, 20 May 2026 14:15:10 +0100 Subject: [PATCH] Cover WDC65C02 tests as well --- M6502/M6502.HarteTest/SingleStepTests.cs | 64 ++++++++++++++++-------- M6502/M6502.HarteTest/TestRunner.cs | 9 ++-- 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/M6502/M6502.HarteTest/SingleStepTests.cs b/M6502/M6502.HarteTest/SingleStepTests.cs index 587b95d..fb3a13f 100644 --- a/M6502/M6502.HarteTest/SingleStepTests.cs +++ b/M6502/M6502.HarteTest/SingleStepTests.cs @@ -5,42 +5,32 @@ namespace M6502.HarteTest { using System.Reflection; - [TestClass] - public class SingleStepTests + internal static class HarteTestHelper { - private const string TestDataDirectory = @"C:\github\spectrum\libraries\EightBit\modules\65x02\6502\v1"; - //private const string TestDataDirectory = @"C:\github\spectrum\libraries\EightBit\modules\65x02\wdc65c02\v1"; - - public static IEnumerable OpcodeFiles + internal static IEnumerable GetOpcodeFiles(string directory) { - get + if (!Directory.Exists(directory)) { - if (!Directory.Exists(TestDataDirectory)) - { - yield break; - } + yield break; + } - foreach (var file in Directory.EnumerateFiles(TestDataDirectory, "*.json").OrderBy(f => f)) + foreach (var file in Directory.EnumerateFiles(directory, "*.json").OrderBy(f => f)) + { + if (new FileInfo(file).Length > 0) { - if (new FileInfo(file).Length > 0) - { - yield return [file]; - } + yield return [file]; } } } - public static string GetDisplayName(MethodInfo _, object[] data) + internal static string GetDisplayName(MethodInfo _, object[] data) { ArgumentNullException.ThrowIfNull(data); return System.IO.Path.GetFileNameWithoutExtension((string)data[0]); } - [TestMethod] - [DynamicData(nameof(OpcodeFiles), DynamicDataSourceType.Property, DynamicDataDisplayName = nameof(GetDisplayName))] - public async Task Opcode_SingleStep(string filePath) + internal static async Task RunOpcodeAsync(string filePath, TestRunner runner) { - var runner = new TestRunner(); runner.Initialize(); var checker = new Checker(runner); checker.Initialise(); @@ -69,4 +59,36 @@ namespace M6502.HarteTest } } } + + [TestClass] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Maintainability", "CA1515:Consider making public types internal", Justification = "Test class needs to be externally visible")] + public class Mos6502SingleStepTests + { + private const string TestDataDirectory = @"C:\github\spectrum\libraries\EightBit\modules\65x02\6502\v1"; + + public static IEnumerable OpcodeFiles => HarteTestHelper.GetOpcodeFiles(TestDataDirectory); + + public static string GetDisplayName(MethodInfo m, object[] data) => HarteTestHelper.GetDisplayName(m, data); + + [TestMethod] + [DynamicData(nameof(OpcodeFiles), DynamicDataSourceType.Property, DynamicDataDisplayName = nameof(GetDisplayName))] + public async Task OpcodeSingleStep(string filePath) + => await HarteTestHelper.RunOpcodeAsync(filePath, new TestRunner(r => new MOS6502(r))).ConfigureAwait(false); + } + + [TestClass] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Maintainability", "CA1515:Consider making public types internal", Justification = "Test class needs to be externally visible")] + public class Wdc65c02SingleStepTests + { + private const string TestDataDirectory = @"C:\github\spectrum\libraries\EightBit\modules\65x02\wdc65c02\v1"; + + public static IEnumerable OpcodeFiles => HarteTestHelper.GetOpcodeFiles(TestDataDirectory); + + public static string GetDisplayName(MethodInfo m, object[] data) => HarteTestHelper.GetDisplayName(m, data); + + [TestMethod] + [DynamicData(nameof(OpcodeFiles), DynamicDataSourceType.Property, DynamicDataDisplayName = nameof(GetDisplayName))] + public async Task OpcodeSingleStep(string filePath) + => await HarteTestHelper.RunOpcodeAsync(filePath, new TestRunner(r => new WDC65C02(r))).ConfigureAwait(false); + } } diff --git a/M6502/M6502.HarteTest/TestRunner.cs b/M6502/M6502.HarteTest/TestRunner.cs index b55e263..03b014e 100644 --- a/M6502/M6502.HarteTest/TestRunner.cs +++ b/M6502/M6502.HarteTest/TestRunner.cs @@ -1,4 +1,4 @@ -namespace M6502.HarteTest +namespace M6502.HarteTest { using EightBit; @@ -6,14 +6,13 @@ { public Ram RAM { get; } = new(0x10000); - public MOS6502 CPU { get; } - //public WDC65C02 CPU { get; } + public Core CPU { get; } private readonly MemoryMapping _mapping; - public TestRunner() + public TestRunner(Func cpuFactory) { - this.CPU = new(this); + this.CPU = cpuFactory(this); this._mapping = new(this.RAM, 0x0000, (ushort)Mask.Sixteen, AccessLevel.ReadWrite); }