1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-06-07 12:29:27 +00:00

Clean up binary test execution framework

This commit is contained in:
kris 2019-08-20 21:17:13 +01:00
parent e0f56e48e0
commit 3d30544b95

View File

@ -1,11 +1,15 @@
import unittest
import sys
import py65.devices.mpu6502
import py65.devices.mpu65c02
class BinaryObjectTests(unittest.TestCase):
"""Test cases based on executing 65x02 object code."""
# If test fails, rerun with execution tracing enabled
TRACE_TEST_FAILURE = False
def binaryObjectTestCase(self, filename, load_addr, pc, success_addr, should_trace=None):
mpu = self._make_mpu()
mpu.pc = pc
@ -31,21 +35,24 @@ class BinaryObjectTests(unittest.TestCase):
memory[start_address:start_address + len(bytes)] = bytes
def _make_mpu(self, *args, **kargs):
klass = self._get_target_class()
mpu = klass(*args, **kargs)
mpu = self.MPU(*args, **kargs)
if 'memory' not in kargs:
mpu.memory = 0x10000 * [0xAA]
return mpu
# XXX common test case
def decimalTest(self, filename):
def runBinaryTest(self, executor, filename):
try:
return self._decimalTest(filename)
return executor(filename)
except AssertionError:
# Rerun with tracing
return self._decimalTest(filename, trace=True)
if self.TRACE_TEST_FAILURE:
return executor(filename, trace=True)
else:
raise
def _decimalTest(self, filename, trace=False):
class FunctionalBCDTests(BinaryObjectTests):
def bcd_test_case(self, filename, trace=False):
mpu = self._make_mpu()
mpu.pc = 0x1000
@ -55,45 +62,45 @@ class BinaryObjectTests(unittest.TestCase):
# $1000: JSR $0200
self._write(mpu.memory, 0x1000, [0x20, 0x00, 0x02])
should_trace = None
if not should_trace:
should_trace = lambda pc: trace
# Set up BRK vector pointing to $2000 so we can trap PC
self._write(mpu.memory, 0xfffe, [0x00, 0x20])
def should_trace(pc):
return trace
while True:
old_pc = mpu.pc
mpu.step(trace=should_trace(mpu.pc))
# If we are looping at the same PC, or we return
# from the JSR, then we are done.
if mpu.pc == old_pc or mpu.pc == 0x1003:
# from the JSR, or we hit the BRK vector, then we are done.
if mpu.pc == old_pc or mpu.pc == 0x1003 or mpu.pc == 0x2000:
break
if mpu.memory[0x0b] != 0:
if mpu.memory[0x0b] != 0: # Tests did not complete successfully
assert False, ("N1={:02x} N2={:02x} HA={:02x} HNVZC={:08b} DA={"
":02x} DNVZC={:08b} AR={:02x} NF={:08b} VF={:08b} "
"ZF={:08b} CF={:08b}".format(
mpu.memory[0x00], mpu.memory[0x01], mpu.memory[0x02],
mpu.memory[0x03], mpu.memory[0x04],mpu.memory[0x05], mpu.memory[0x06],
mpu.memory[0x07],mpu.memory[0x08], mpu.memory[0x09],
mpu.memory[0x0a]
mpu.memory[0x03], mpu.memory[0x04], mpu.memory[0x05],
mpu.memory[0x06], mpu.memory[0x07], mpu.memory[0x08],
mpu.memory[0x09], mpu.memory[0x0a]
))
class Functional6502Tests(BinaryObjectTests):
class Functional6502Tests(FunctionalBCDTests):
MPU = py65.devices.mpu6502.MPU
def Xtest6502DecimalTest(self):
self.decimalTest("devices/bcd/6502_decimal_test.bin")
def _get_target_class(self):
return py65.devices.mpu6502.MPU
def test6502DecimalTest(self):
self.runBinaryTest(
self.bcd_test_case, "devices/bcd/6502_decimal_test.bin")
class Functional65C02Tests(BinaryObjectTests):
class Functional65C02Tests(FunctionalBCDTests):
MPU = py65.devices.mpu65c02.MPU
def test65C02DecimalTest(self):
self.decimalTest("devices/bcd/65C02_decimal_test.bin")
def _get_target_class(self):
return py65.devices.mpu65c02.MPU
self.runBinaryTest(
self.bcd_test_case, "devices/bcd/65C02_decimal_test.bin")
def test_suite():