First pass at LR35902 fuse test runner code analysis

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon
2019-07-21 09:10:45 +01:00
parent 5c911674a4
commit 6a883a6252
10 changed files with 87 additions and 24 deletions

View File

@@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -59,6 +60,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\EightBit\EightBit.csproj">

View File

@@ -1,5 +1,6 @@
namespace Fuse
{
using System;
using System.Collections.Generic;
using System.IO;
@@ -15,22 +16,21 @@
public void Read()
{
using (var reader = new StreamReader(this.path))
using (var reader = File.OpenText(this.path))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var ignored = line.StartsWith(";");
var ignored = line.StartsWith(";", StringComparison.OrdinalIgnoreCase);
if (!ignored)
{
this.lines.Add(line);
}
}
}
if (this.lines.Count > 0)
{
this.position = 0;
}
// Users should check EndOfFile before using a bad position...
this.position = 0;
}
public string ReadLine()

View File

@@ -2,21 +2,34 @@
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
public class MemoryDatum
{
private readonly List<byte> bytes = new List<byte>();
public ushort Address { get; private set; } = (ushort)EightBit.Mask.Mask16;
public List<byte> Bytes { get; } = new List<byte>();
public ReadOnlyCollection<byte> Bytes => this.bytes.AsReadOnly();
public void Parse(string line)
{
if (string.IsNullOrWhiteSpace(line))
{
throw new ArgumentNullException(nameof(line));
}
var tokens = line.Split(new char[] { ' ', '\t' });
this.Parse(tokens);
}
public void Parse(string[] tokens)
{
if (tokens == null)
{
throw new ArgumentNullException(nameof(tokens));
}
this.Address = Convert.ToUInt16(tokens[0], 16);
var finished = false;
@@ -26,7 +39,7 @@
finished = token == "-1";
if (!finished)
{
this.Bytes.Add(Convert.ToByte(token, 16));
this.bytes.Add(Convert.ToByte(token, 16));
}
}
}

View File

@@ -2,7 +2,8 @@
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using EightBit;
public class RegisterState
@@ -12,8 +13,12 @@
AF, BC, DE, HL, SP, PC
};
public List<Register16> Registers { get; } = new List<Register16>();
private readonly List<Register16> registers = new List<Register16>();
public ReadOnlyCollection<Register16> Registers => this.registers.AsReadOnly();
public bool Halted { get; private set; } = false;
public int TStates { get; private set; } = -1;
public void Parse(Lines lines)
@@ -32,8 +37,8 @@
private void ParseInternalState(string[] tokens)
{
this.Halted = Convert.ToInt32(tokens[0]) == 1;
this.TStates = Convert.ToInt32(tokens[1]);
this.Halted = Convert.ToInt32(tokens[0], CultureInfo.InvariantCulture) == 1;
this.TStates = Convert.ToInt32(tokens[1], CultureInfo.InvariantCulture);
}
private void ParseExternalState(Lines lines)
@@ -41,7 +46,7 @@
var line = lines.ReadLine();
foreach (var token in line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries))
{
this.Registers.Add(new Register16(Convert.ToUInt16(token, 16)));
this.registers.Add(new Register16(Convert.ToUInt16(token, 16)));
}
}
}

View File

@@ -1,10 +1,13 @@
namespace Fuse
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
public class Result
{
private readonly TestEvents events = new TestEvents();
private readonly List<MemoryDatum> memoryData = new List<MemoryDatum>();
public bool Valid => !string.IsNullOrEmpty(this.Description);
@@ -12,10 +15,15 @@
public RegisterState RegisterState { get; } = new RegisterState();
public List<MemoryDatum> MemoryData { get; } = new List<MemoryDatum>();
public ReadOnlyCollection<MemoryDatum> MemoryData => this.memoryData.AsReadOnly();
public void Parse(Lines lines)
{
if (lines == null)
{
throw new ArgumentNullException(nameof(lines));
}
while (!lines.EndOfFile && !this.Valid)
{
this.Description = lines.ReadLine();
@@ -38,7 +46,7 @@
{
var datum = new MemoryDatum();
datum.Parse(line);
this.MemoryData.Add(datum);
this.memoryData.Add(datum);
}
}
while (!finished);

View File

@@ -1,19 +1,27 @@
namespace Fuse
{
using System;
using System.Collections.Generic;
public class Test
{
private List<MemoryDatum> memoryData = new List<MemoryDatum>();
public bool Valid => !string.IsNullOrEmpty(this.Description);
public string Description { get; private set; }
public RegisterState RegisterState { get; } = new RegisterState();
public List<MemoryDatum> MemoryData { get; } = new List<MemoryDatum>();
public IReadOnlyCollection<MemoryDatum> MemoryData => this.memoryData.AsReadOnly();
public void Parse(Lines lines)
{
if (lines == null)
{
throw new ArgumentNullException(nameof(lines));
}
while (!lines.EndOfFile && !this.Valid)
{
this.Description = lines.ReadLine();
@@ -35,7 +43,7 @@
{
var datum = new MemoryDatum();
datum.Parse(line);
this.MemoryData.Add(datum);
this.memoryData.Add(datum);
}
}
while (!finished);

View File

@@ -19,6 +19,11 @@
public void Parse(Lines lines)
{
if (lines == null)
{
throw new ArgumentNullException(nameof(lines));
}
this.ParseLine(lines.ReadLine());
if (!this.Valid)
{

View File

@@ -1,10 +1,13 @@
namespace Fuse
{
using System.Collections.Generic;
using System.Collections.ObjectModel;
public class TestEvents
{
public List<TestEvent> Container { get; } = new List<TestEvent>();
private readonly List<TestEvent> container = new List<TestEvent>();
public ReadOnlyCollection<TestEvent> Container => this.container.AsReadOnly();
public void Parse(Lines lines)
{
@@ -16,7 +19,7 @@
complete = !e.Valid;
if (!complete)
{
this.Container.Add(e);
this.container.Add(e);
}
}
while (!complete);

View File

@@ -3,13 +3,13 @@
public class TestRunner : EightBit.GameBoy.Bus
{
private readonly Test test;
private readonly Result expected;
private readonly Result result;
private readonly EightBit.Ram ram = new EightBit.Ram(0x10000);
public TestRunner(Test test, Result expected)
public TestRunner(Test test, Result result)
{
this.test = test;
this.expected = expected;
this.result = result;
}
public bool Failed { get; private set; } = false;
@@ -87,7 +87,7 @@
private void Checkregisters()
{
var expectedState = this.expected.RegisterState;
var expectedState = this.result.RegisterState;
var expectedRegisters = expectedState.Registers;
var af = this.CPU.AF.Word == expectedRegisters[(int)RegisterState.Register.AF].Word;
@@ -152,7 +152,7 @@
{
var first = true;
foreach (var memoryDatum in this.expected.MemoryData)
foreach (var memoryDatum in this.result.MemoryData)
{
var address = memoryDatum.Address;
foreach (var expected in memoryDatum.Bytes)

View File

@@ -0,0 +1,19 @@
{
// ACTION REQUIRED: This file was automatically added to your project, but it
// will not take effect until additional steps are taken to enable it. See the
// following page for additional information:
//
// https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"documentInterfaces": false,
"documentExposedElements": false,
"documentInternalElements": false,
"documentPrivateElements": false,
"documentPrivateFields": false,
"companyName": "Adrian Conlon"
}
}
}