Refactor LR35902 test runner. Better, but still not working.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2019-07-20 19:17:08 +01:00
parent ed92ce33f6
commit a9a03d946a
14 changed files with 192 additions and 139 deletions

View File

@ -1,58 +0,0 @@
namespace Fuse
{
using System;
using System.Collections.Generic;
using System.IO;
public class ExpectedTestResult
{
private readonly TestEvents events = new TestEvents();
public bool Finish { get; private set; } = false;
public string Description { get; private set; }
public RegisterState RegisterState { get; } = new RegisterState();
public List<MemoryDatum> MemoryData { get; } = new List<MemoryDatum>();
public void Read(StreamReader file)
{
this.Finish = false;
do
{
this.Description = file.ReadLine();
this.Finish = file.EndOfStream;
}
while (string.IsNullOrEmpty(this.Description) && !this.Finish);
if (this.Finish)
{
return;
}
this.events.Read(file);
this.RegisterState.Read(file);
var line = file.ReadLine();
if (line.Length > 0)
{
throw new InvalidOperationException("EOL swallow failure!!");
}
var finished = false;
do
{
line = file.ReadLine();
finished = string.IsNullOrEmpty(line);
if (!finished)
{
var datum = new MemoryDatum();
datum.Parse(line);
this.MemoryData.Add(datum);
}
}
while (!finished);
}
}
}

View File

@ -1,33 +0,0 @@
namespace Fuse
{
using System.Collections.Generic;
using System.IO;
public class ExpectedTestResults
{
public Dictionary<string, ExpectedTestResult> Results { get; } = new Dictionary<string, ExpectedTestResult>();
public void Read(string path)
{
using (var file = new StreamReader(path))
{
this.Read(file);
}
}
private void Read(StreamReader file)
{
var finished = false;
while (!file.EndOfStream)
{
var result = new ExpectedTestResult();
result.Read(file);
finished = result.Finish;
if (!finished)
{
this.Results[result.Description] = result;
}
}
}
}
}

View File

@ -43,8 +43,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ExpectedTestResult.cs" />
<Compile Include="ExpectedTestResults.cs" />
<Compile Include="Result.cs" />
<Compile Include="Results.cs" />
<Compile Include="Lines.cs" />
<Compile Include="MemoryDatum.cs" />
<Compile Include="RegisterState.cs" />
<Compile Include="Test.cs" />

View File

@ -0,0 +1,56 @@
namespace Fuse
{
using System.Collections.Generic;
using System.IO;
public class Lines
{
private readonly string path;
private readonly List<string> lines = new List<string>();
private int position = -1;
public Lines(string path) => this.path = path;
public bool EndOfFile => this.position == this.lines.Count;
public void Read()
{
using (var reader = new StreamReader(this.path))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var ignored = line.StartsWith(";");
if (!ignored)
{
this.lines.Add(line);
}
}
}
if (this.lines.Count > 0)
{
this.position = 0;
}
}
public string ReadLine()
{
try
{
return this.PeekLine();
}
finally
{
this.Increment();
}
}
public void UnreadLine() => this.Decrement();
public string PeekLine() => this.lines[this.position];
private void Increment() => ++this.position;
private void Decrement() => --this.position;
}
}

View File

@ -4,8 +4,10 @@
{
public static void Main(string[] args)
{
TestSuite testSuite = new TestSuite("fuse-tests\\tests");
testSuite.Run();
var suite = new TestSuite("fuse-tests\\tests");
suite.Read();
suite.Parse();
suite.Run();
}
}
}

View File

@ -2,7 +2,6 @@
{
using System;
using System.Collections.Generic;
using System.IO;
using EightBit;
@ -17,24 +16,29 @@
public bool Halted { get; private set; } = false;
public int TStates { get; private set; } = -1;
public void Read(StreamReader file)
public void Parse(Lines lines)
{
this.ReadExternalState(file);
this.ReadInternalState(file);
this.ParseExternalState(lines);
this.ParseInternalState(lines);
}
private void ReadInternalState(StreamReader file)
{
var line = file.ReadLine();
var tokens = line.Split(new char[] { ' ', '\t' });
private void ParseInternalState(Lines lines) => this.ParseInternalState(lines.ReadLine());
private void ParseInternalState(string line)
{
var tokens = line.Split(new char[] { ' ', '\t' });
this.ParseInternalState(tokens);
}
private void ParseInternalState(string[] tokens)
{
this.Halted = Convert.ToInt32(tokens[0]) == 1;
this.TStates = Convert.ToInt32(tokens[1]);
}
private void ReadExternalState(StreamReader file)
private void ParseExternalState(Lines lines)
{
var line = file.ReadLine();
var line = lines.ReadLine();
foreach (var token in line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries))
{
this.Registers.Add(new Register16(Convert.ToUInt16(token, 16)));

View File

@ -0,0 +1,47 @@
namespace Fuse
{
using System.Collections.Generic;
public class Result
{
private readonly TestEvents events = new TestEvents();
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 void Parse(Lines lines)
{
while (!lines.EndOfFile && !this.Valid)
{
this.Description = lines.ReadLine();
}
if (!this.Valid)
{
return;
}
this.events.Parse(lines);
this.RegisterState.Parse(lines);
var finished = false;
do
{
var line = lines.ReadLine();
finished = string.IsNullOrWhiteSpace(line);
if (!finished)
{
var datum = new MemoryDatum();
datum.Parse(line);
this.MemoryData.Add(datum);
}
}
while (!finished);
}
}
}

View File

@ -0,0 +1,28 @@
namespace Fuse
{
using System.Collections.Generic;
public class Results
{
private readonly Lines lines;
public Dictionary<string, Result> Container { get; } = new Dictionary<string, Result>();
public Results(string path) => this.lines = new Lines(path);
public void Read() => this.lines.Read();
public void Parse()
{
while (!this.lines.EndOfFile)
{
var result = new Result();
result.Parse(this.lines);
if (result.Valid)
{
this.Container.Add(result.Description, result);
}
}
}
}
}

View File

@ -1,7 +1,6 @@
namespace Fuse
{
using System.Collections.Generic;
using System.IO;
public class Test
{
@ -13,11 +12,11 @@
public List<MemoryDatum> MemoryData { get; } = new List<MemoryDatum>();
public void Read(StreamReader file)
public void Parse(Lines lines)
{
while ((string.IsNullOrWhiteSpace(this.Description) || this.Description.StartsWith(";")) && !file.EndOfStream)
while (!lines.EndOfFile && !this.Valid)
{
this.Description = file.ReadLine();
this.Description = lines.ReadLine();
}
if (!this.Valid)
@ -25,12 +24,12 @@
return;
}
this.RegisterState.Read(file);
this.RegisterState.Parse(lines);
var finished = false;
do
{
var line = file.ReadLine();
var line = lines.ReadLine();
finished = line == "-1";
if (!finished)
{

View File

@ -13,15 +13,14 @@
public ushort Address { get; private set; } = (ushort)EightBit.Mask.Mask16;
public ushort Value { get; private set; } = (byte)EightBit.Mask.Mask8;
public byte Value { get; private set; } = (byte)EightBit.Mask.Mask8;
public void Read(StreamReader file)
public void Parse(Lines lines)
{
var prior = file.BaseStream.Position;
this.ParseLine(file.ReadLine());
this.ParseLine(lines.ReadLine());
if (!this.Valid)
{
file.BaseStream.Seek(prior, SeekOrigin.Begin);
lines.UnreadLine();
}
}

View File

@ -1,23 +1,22 @@
namespace Fuse
{
using System.Collections.Generic;
using System.IO;
public class TestEvents
{
public List<TestEvent> Events { get; } = new List<TestEvent>();
public List<TestEvent> Container { get; } = new List<TestEvent>();
public void Read(StreamReader file)
public void Parse(Lines lines)
{
var complete = false;
do
{
var e = new TestEvent();
e.Read(file);
e.Parse(lines);
complete = !e.Valid;
if (!complete)
{
this.Events.Add(e);
this.Container.Add(e);
}
}
while (!complete);

View File

@ -3,10 +3,10 @@
public class TestRunner : EightBit.GameBoy.Bus
{
private readonly Test test;
private readonly ExpectedTestResult expected;
private readonly Result expected;
private readonly EightBit.Ram ram = new EightBit.Ram(0x10000);
public TestRunner(Test test, ExpectedTestResult expected)
public TestRunner(Test test, Result expected)
{
this.test = test;
this.expected = expected;

View File

@ -2,13 +2,25 @@
{
public class TestSuite
{
private readonly Tests tests = new Tests();
private readonly ExpectedTestResults results = new ExpectedTestResults();
private readonly Tests tests;
private readonly Results results;
public TestSuite(string path)
{
this.tests.Read(path + ".in");
this.results.Read(path + ".expected");
this.tests = new Tests(path + ".in");
this.results = new Results(path + ".expected");
}
public void Read()
{
this.tests.Read();
this.results.Read();
}
public void Parse()
{
this.tests.Parse();
this.results.Parse();
}
public void Run()
@ -21,7 +33,7 @@
System.Console.Out.WriteLine($"** Checking: {key}");
var input = test.Value;
var result = this.results.Results[key];
var result = this.results.Container[key];
var runner = new TestRunner(input, result);
runner.Run();

View File

@ -1,26 +1,23 @@
namespace Fuse
{
using System.Collections.Generic;
using System.IO;
public class Tests
{
public void Read(string path)
{
using (var file = new StreamReader(path))
{
this.Read(file);
}
}
private readonly Lines lines;
public Dictionary<string, Test> Container { get; } = new Dictionary<string, Test>();
public void Read(StreamReader file)
public Tests(string path) => this.lines = new Lines(path);
public void Read() => this.lines.Read();
public void Parse()
{
while (!file.EndOfStream)
while (!this.lines.EndOfFile)
{
var test = new Test();
test.Read(file);
test.Parse(this.lines);
if (test.Valid)
{
this.Container.Add(test.Description, test);