Start incorporating "event" support into the Fuse tests. Only supported by the Z80 fuse tests at present.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2019-08-14 22:38:47 +01:00
parent 315bef7229
commit d15d1e0d08
5 changed files with 95 additions and 6 deletions

View File

@ -17,6 +17,8 @@ namespace Fuse
public T RegisterState { get; } = new T();
public TestEvents Events => this.events;
public ReadOnlyCollection<MemoryDatum> MemoryData => this.memoryData.AsReadOnly();
public bool TryParse(Lines lines)

View File

@ -9,6 +9,18 @@ namespace Fuse
{
private int cycles;
public TestEvent()
{
}
public TestEvent(int cycles, string specifier, ushort address, byte value)
{
this.cycles = cycles;
this.Specifier = specifier;
this.Address = address;
this.Value = value;
}
public int Cycles => this.cycles;
public string Specifier { get; private set; }

View File

@ -12,6 +12,8 @@ namespace Fuse
public ReadOnlyCollection<TestEvent> Container => this.container.AsReadOnly();
public void Add(TestEvent testEvent) => this.container.Add(testEvent);
public void Parse(Lines lines)
{
bool success;
@ -21,7 +23,7 @@ namespace Fuse
success = e.TryParse(lines);
if (success)
{
this.container.Add(e);
this.Add(e);
}
}
while (success);

View File

@ -25,6 +25,8 @@ namespace Fuse
{
private readonly Test<RegisterState> test;
private readonly Result<RegisterState> result;
private readonly TestEvents desiredEvents;
private readonly TestEvents actualEvents = new TestEvents();
private readonly EightBit.Ram ram = new EightBit.Ram(0x10000);
private readonly EightBit.InputOutput ports = new EightBit.InputOutput();
private readonly EightBit.Z80 cpu;
@ -34,6 +36,7 @@ namespace Fuse
this.cpu = new EightBit.Z80(this, this.ports);
this.test = test;
this.result = result;
this.desiredEvents = result.Events;
}
public bool Failed { get; private set; } = false;
@ -78,6 +81,20 @@ namespace Fuse
public override void Initialize()
{
this.ports.ReadPort += this.Ports_ReadPort;
this.ports.WrittenPort += this.Ports_WrittenPort;
}
protected override void OnReadByte()
{
this.actualEvents.Add(new TestEvent(this.cpu.Cycles, "MR", this.Address.Word, this.Data));
base.OnReadByte();
}
protected override void OnWrittenByte()
{
this.actualEvents.Add(new TestEvent(this.cpu.Cycles, "MW", this.Address.Word, this.Data));
base.OnWrittenByte();
}
private static void DumpDifference(string description, byte expected, byte actual)
@ -86,6 +103,10 @@ namespace Fuse
System.Console.Error.WriteLine(output);
}
private void Ports_WrittenPort(object sender, EightBit.PortEventArgs e) => this.actualEvents.Add(new TestEvent(this.cpu.Cycles, "PW", this.Address.Word, this.Data));
private void Ports_ReadPort(object sender, EightBit.PortEventArgs e) => this.actualEvents.Add(new TestEvent(this.cpu.Cycles, "PR", this.Address.Word, this.Data));
private static void DumpDifference(string highDescription, string lowDescription, EightBit.Register16 expected, EightBit.Register16 actual)
{
var expectedHigh = expected.High;
@ -150,11 +171,12 @@ namespace Fuse
private void Check()
{
this.Checkregisters();
this.CheckRegisters();
this.CheckMemory();
this.CheckEvents();
}
private void Checkregisters()
private void CheckRegisters()
{
var expectedState = this.result.RegisterState;
var expectedRegisters = expectedState.Registers;
@ -353,6 +375,54 @@ namespace Fuse
}
}
private void CheckEvents()
{
var desires = this.desiredEvents.Container;
var actuals = this.actualEvents.Container;
var j = 0;
for (var i = 0; i < desires.Count; ++i)
{
var desire = desires[i];
if (desire.Specifier.EndsWith("C")) // Not interested in contention events (yet)
{
continue;
}
var actual = actuals[j++];
var equalCycles = desire.Cycles == actual.Cycles;
var equalSpecifier = desire.Specifier == actual.Specifier;
var equalAddress = desire.Address == actual.Address;
var equalValue = desire.Value == actual.Value;
// var equal = equalCycles && equalSpecifier && equalAddress && equalValue;
var equal = equalSpecifier && equalAddress && equalValue;
if (!equal)
{
this.Failed = true;
var expectedOutput = $"**** Event issue (desire index, {i}): {ToString(desire)}";
System.Console.Error.WriteLine(expectedOutput);
var actualOutput = $"**** Event issue (actual index, {j}): {ToString(actual)}";
System.Console.Error.WriteLine(actualOutput);
}
}
}
private static string ToString(TestEvent e)
{
var output = $"Cycles = {e.Cycles}, Specifier = {e.Specifier}, Address = {e.Address:X4}";
if (!e.Specifier.EndsWith("C"))
{
output += $", Value={e.Value:X2}";
}
return output;
}
private void CheckMemory()
{
var first = true;

View File

@ -1791,12 +1791,15 @@ namespace EightBit
private void XHTL()
{
var hl2 = this.HL2();
this.MEMPTR.Low = this.BusRead(this.SP);
this.BusWrite(hl2.Low);
this.Bus.Address.Word = this.SP.Word;
this.MEMPTR.Low = this.BusRead();
this.Bus.Data = hl2.Low;
this.BusWrite();
hl2.Low = this.MEMPTR.Low;
++this.Bus.Address.Word;
this.MEMPTR.High = this.BusRead();
this.BusWrite(hl2.High);
this.Bus.Data = hl2.High;
this.BusWrite();
hl2.High = this.MEMPTR.High;
}