mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-07 05:30:30 +00:00
Attempts to bring a little more consistency to my use of Swift in test code.
This commit is contained in:
parent
c3187fdbe1
commit
69509f6502
@ -14,38 +14,38 @@ class MOS6502InterruptTests: XCTestCase {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
// create a machine full of NOPs
|
||||
// Create a machine full of NOPs.
|
||||
machine = CSTestMachine6502(processor: .processor6502)
|
||||
for c in 0...65535 {
|
||||
machine.setValue(0xea, forAddress: UInt32(c))
|
||||
}
|
||||
|
||||
// set the IRQ vector to be 0x1234
|
||||
// Set the IRQ vector to 0x1234.
|
||||
machine.setValue(0x34, forAddress: 0xfffe)
|
||||
machine.setValue(0x12, forAddress: 0xffff)
|
||||
|
||||
// add a CLI
|
||||
// Add a CLI.
|
||||
machine.setValue(0x58, forAddress: 0x4000)
|
||||
|
||||
// pick things off at 0x4000
|
||||
machine.setValue(0x4000, for: CSTestMachine6502Register.programCounter)
|
||||
// Begin at 0x4000.
|
||||
machine.setValue(0x4000, for: .programCounter)
|
||||
}
|
||||
|
||||
func testIRQLine() {
|
||||
// run for six cycles; check that no interrupt has occurred
|
||||
// Run for six cycles; check that no interrupt has occurred.
|
||||
machine.runForNumber(ofCycles: 6)
|
||||
XCTAssert(machine.value(for: .programCounter) == 0x4003, "No interrupt should have occurred with line low")
|
||||
XCTAssertEqual(machine.value(for: .programCounter), 0x4003, "No interrupt should have occurred with line low")
|
||||
|
||||
// enable the interrupt line, check that it was too late
|
||||
machine.irqLine = true
|
||||
machine.runForNumber(ofCycles: 2)
|
||||
XCTAssert(machine.value(for: .programCounter) == 0x4004, "No interrupt should have occurred from interrupt raised between instructions")
|
||||
XCTAssertEqual(machine.value(for: .programCounter), 0x4004, "No interrupt should have occurred from interrupt raised between instructions")
|
||||
|
||||
// run for a further 7 cycles, confirm that the IRQ vector was jumped to
|
||||
machine.runForNumber(ofCycles: 6)
|
||||
XCTAssert(machine.value(for: .programCounter) != 0x1234, "Interrupt routine should not yet have begun")
|
||||
XCTAssertNotEqual(machine.value(for: .programCounter), 0x1234, "Interrupt routine should not yet have begun")
|
||||
machine.runForNumber(ofCycles: 1)
|
||||
XCTAssert(machine.value(for: .programCounter) == 0x1234, "Interrupt routine should just have begun")
|
||||
XCTAssertEqual(machine.value(for: .programCounter), 0x1234, "Interrupt routine should just have begun")
|
||||
}
|
||||
|
||||
func testIFlagSet() {
|
||||
@ -53,8 +53,8 @@ class MOS6502InterruptTests: XCTestCase {
|
||||
machine.irqLine = true
|
||||
machine.runForNumber(ofCycles: 11)
|
||||
|
||||
XCTAssert(machine.value(for: .programCounter) == 0x1234, "Interrupt routine should just have begun")
|
||||
XCTAssert(machine.value(for: .flags) & 0x04 == 0x04, "Interrupt status flag should be set")
|
||||
XCTAssertEqual(machine.value(for: .programCounter), 0x1234, "Interrupt routine should just have begun")
|
||||
XCTAssertEqual(machine.value(for: .flags) & 0x04, 0x04, "Interrupt status flag should be set")
|
||||
}
|
||||
|
||||
func testCLISEIFlagClear() {
|
||||
@ -64,12 +64,13 @@ class MOS6502InterruptTests: XCTestCase {
|
||||
|
||||
// run for four cycles; the CLI and SEI should have been performed
|
||||
machine.runForNumber(ofCycles: 4)
|
||||
XCTAssert(machine.value(for: .programCounter) == 0x4002, "CLI/SEI pair should have been performed in their entirety")
|
||||
XCTAssertEqual(machine.value(for: .programCounter), 0x4002, "CLI/SEI pair should have been performed in their entirety")
|
||||
|
||||
// run for seven more cycles
|
||||
machine.runForNumber(ofCycles: 7)
|
||||
|
||||
// interrupt should have taken place despite SEI
|
||||
XCTAssert(machine.value(for: .programCounter) == 0x1234, "Interrupt routine should just have begun")
|
||||
XCTAssertEqual(machine.value(for: .programCounter), 0x1234, "Interrupt routine should just have begun")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
0x18, // [2] CLC
|
||||
0x2a, // [2] ROL A
|
||||
]
|
||||
self.runTest(code, expectedRunLength: 10)
|
||||
runTest(code, expectedRunLength: 10)
|
||||
}
|
||||
|
||||
func testLDA() {
|
||||
@ -40,7 +40,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
0xb1, 0x00, // [5] LDA ($00), y (no wrap)
|
||||
0xb1, 0x02, // [6] LDA ($01), y (wrap)
|
||||
]
|
||||
self.runTest(code, expectedRunLength: 48)
|
||||
runTest(code, expectedRunLength: 48)
|
||||
}
|
||||
|
||||
func testBIT() {
|
||||
@ -48,7 +48,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
0x24, 0x2a, // [3] BIT $2a
|
||||
0x2c, 0x2a, 0x2b, // [4] BIT $2b2a
|
||||
]
|
||||
self.runTest(code, expectedRunLength: 7)
|
||||
runTest(code, expectedRunLength: 7)
|
||||
}
|
||||
|
||||
func testSTA() {
|
||||
@ -64,7 +64,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
0x91, 0x00, // [6] STA ($00), y (no wrap)
|
||||
0x91, 0x02, // [6] STA ($01), y (wrap)
|
||||
]
|
||||
self.runTest(code, expectedRunLength: 49)
|
||||
runTest(code, expectedRunLength: 49)
|
||||
}
|
||||
|
||||
func testINC() {
|
||||
@ -75,7 +75,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
0xfe, 0x00, 0x00, // [7] INC $0000, x (no wrap)
|
||||
0xfe, 0x02, 0x00, // [7] INC $0002, x (wrap)
|
||||
]
|
||||
self.runTest(code, expectedRunLength: 31)
|
||||
runTest(code, expectedRunLength: 31)
|
||||
}
|
||||
|
||||
func testJSR() {
|
||||
@ -85,7 +85,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
0x60, // [6] RTS
|
||||
]
|
||||
machine.addTrapAddress(0x0203)
|
||||
self.runTest(code, expectedRunLength: 12)
|
||||
runTest(code, expectedRunLength: 12)
|
||||
}
|
||||
|
||||
func testJMP() {
|
||||
@ -94,7 +94,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x4c, 0x0b, 0x02, // [3] JMP 020b
|
||||
]
|
||||
self.runTest(code, expectedRunLength: 8)
|
||||
runTest(code, expectedRunLength: 8)
|
||||
}
|
||||
|
||||
func testPHAPLA() {
|
||||
@ -103,7 +103,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
0x48, // [3] PHA
|
||||
0x68, // [4] PLA
|
||||
]
|
||||
self.runTest(code, expectedRunLength: 10)
|
||||
runTest(code, expectedRunLength: 10)
|
||||
}
|
||||
|
||||
func testBCS() {
|
||||
@ -130,7 +130,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
]
|
||||
self.runTest(code, expectedRunLength: 14)
|
||||
runTest(code, expectedRunLength: 14)
|
||||
}
|
||||
|
||||
func testSnippet1() {
|
||||
@ -138,7 +138,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
0x8d, 0x08, 0x00, // [4] STA $0008
|
||||
0xc6, 0xb4, // [5] DEC $B4
|
||||
]
|
||||
self.runTest(code, expectedRunLength: 9)
|
||||
runTest(code, expectedRunLength: 9)
|
||||
}
|
||||
|
||||
func testSnippet2() {
|
||||
@ -146,7 +146,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
0x16, 0x16, // [6] ASL $16, x
|
||||
0x46, 0x46, // [5] LSR $46
|
||||
]
|
||||
self.runTest(code, expectedRunLength: 11)
|
||||
runTest(code, expectedRunLength: 11)
|
||||
}
|
||||
|
||||
func testSnippet3() {
|
||||
@ -174,7 +174,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
0x60, // [6] RTS
|
||||
]
|
||||
machine.addTrapAddress(0x0203)
|
||||
self.runTest(code, expectedRunLength: 66)
|
||||
runTest(code, expectedRunLength: 66)
|
||||
}
|
||||
|
||||
func testNOP() {
|
||||
@ -194,10 +194,10 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
0xe2, 0x00, // [2] NOP #
|
||||
0xf4, 0x00, // [4] NOP zpg, x
|
||||
]
|
||||
self.runTest(code, expectedRunLength: 43)
|
||||
runTest(code, expectedRunLength: 43)
|
||||
}
|
||||
|
||||
func runTest(_ code: [UInt8], expectedRunLength: UInt32) {
|
||||
private func runTest(_ code: [UInt8], expectedRunLength: UInt32) {
|
||||
machine.trapHandler = self
|
||||
|
||||
let immediateCode = Data(code)
|
||||
@ -213,17 +213,17 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
machine.setValue(0xff, for: CSTestMachine6502Register.X)
|
||||
machine.setValue(0xfe, for: CSTestMachine6502Register.Y)
|
||||
|
||||
self.endTime = 0
|
||||
while self.endTime == 0 {
|
||||
endTime = 0
|
||||
while endTime == 0 {
|
||||
machine.runForNumber(ofCycles: 10)
|
||||
}
|
||||
|
||||
XCTAssert(self.endTime == expectedRunLength, "Took \(self.endTime) cycles to perform rather than \(expectedRunLength)")
|
||||
XCTAssertEqual(endTime, expectedRunLength, "Took \(endTime) cycles to perform rather than \(expectedRunLength)")
|
||||
}
|
||||
|
||||
func testMachine(_ testMachine: CSTestMachine, didTrapAtAddress address: UInt16) {
|
||||
if self.endTime == 0 {
|
||||
self.endTime = (machine.timestamp / 2) - 1
|
||||
if endTime == 0 {
|
||||
endTime = (machine.timestamp / 2) - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import Foundation
|
||||
|
||||
class MOS6532Tests: XCTestCase {
|
||||
|
||||
fileprivate func with6532(_ action: (MOS6532Bridge) -> ()) {
|
||||
private func with6532(_ action: (MOS6532Bridge) -> ()) {
|
||||
let bridge = MOS6532Bridge()
|
||||
action(bridge)
|
||||
}
|
||||
|
@ -542,4 +542,5 @@ class WDC65816AddressingTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(machine.value(for: .A), 0xcdab)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,4 +27,5 @@ class AllSuiteATests: XCTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class BCDTest: XCTestCase, CSTestMachineTrapHandler {
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate var output: String = ""
|
||||
private var output: String = ""
|
||||
func testMachine(_ testMachine: CSTestMachine, didTrapAtAddress address: UInt16) {
|
||||
let machine6502 = testMachine as! CSTestMachine6502
|
||||
|
||||
@ -48,4 +48,5 @@ class BCDTest: XCTestCase, CSTestMachineTrapHandler {
|
||||
let character = machine6502.value(for: .A)
|
||||
output.append(Character(UnicodeScalar(character)!))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,21 +10,21 @@ import XCTest
|
||||
|
||||
class C1540Tests: XCTestCase {
|
||||
|
||||
fileprivate func with1540(_ action: (C1540Bridge) -> ()) {
|
||||
private func with1540(_ action: (C1540Bridge) -> ()) {
|
||||
let bridge = C1540Bridge()
|
||||
action(bridge)
|
||||
}
|
||||
|
||||
fileprivate func transmit(_ c1540: C1540Bridge, value: Int) {
|
||||
private func transmit(_ c1540: C1540Bridge, value: Int) {
|
||||
var shiftedValue = value
|
||||
|
||||
c1540.dataLine = true
|
||||
c1540.run(forCycles: 256)
|
||||
XCTAssert(c1540.dataLine == false, "Listener should have taken data line low for start of transmission")
|
||||
XCTAssertFalse(c1540.dataLine, "Listener should have taken data line low for start of transmission")
|
||||
|
||||
c1540.clockLine = true
|
||||
c1540.run(forCycles: 256) // this isn't time limited on real hardware
|
||||
XCTAssert(c1540.dataLine == true, "Listener should have let data line go high again")
|
||||
XCTAssertTrue(c1540.dataLine, "Listener should have let data line go high again")
|
||||
|
||||
// set up for byte transfer
|
||||
c1540.clockLine = false
|
||||
@ -47,7 +47,7 @@ class C1540Tests: XCTestCase {
|
||||
// check for acknowledgment
|
||||
c1540.dataLine = true
|
||||
c1540.run(forCycles: 1000)
|
||||
XCTAssert(c1540.dataLine == false, "Listener should have acknowledged byte")
|
||||
XCTAssertFalse(c1540.dataLine, "Listener should have acknowledged byte")
|
||||
}
|
||||
|
||||
// MARK: EOI
|
||||
@ -64,10 +64,11 @@ class C1540Tests: XCTestCase {
|
||||
|
||||
// proceed 1 ms and check that the 1540 pulled the data line low
|
||||
$0.run(forCycles: 1000)
|
||||
XCTAssert($0.dataLine == false, "Listener should have taken data line low")
|
||||
XCTAssertFalse($0.dataLine, "Listener should have taken data line low")
|
||||
|
||||
// transmit LISTEN #8
|
||||
self.transmit($0, value: 0x28)
|
||||
transmit($0, value: 0x28)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import XCTest
|
||||
|
||||
class KlausDormannTests: XCTestCase {
|
||||
|
||||
fileprivate func runTest(resource: String, processor: CSTestMachine6502Processor) -> UInt16 {
|
||||
private func runTest(resource: String, processor: CSTestMachine6502Processor) -> UInt16 {
|
||||
if let filename = Bundle(for: type(of: self)).path(forResource: resource, ofType: "bin") {
|
||||
if let functionalTest = try? Data(contentsOf: URL(fileURLWithPath: filename)) {
|
||||
let machine = CSTestMachine6502(processor: processor)
|
||||
@ -39,7 +39,7 @@ class KlausDormannTests: XCTestCase {
|
||||
return 0
|
||||
}
|
||||
|
||||
func runTest6502(processor: CSTestMachine6502Processor) {
|
||||
private func runTest6502(processor: CSTestMachine6502Processor) {
|
||||
func errorForTrapAddress(_ address: UInt16) -> String? {
|
||||
switch address {
|
||||
case 0x3399: return nil // success!
|
||||
@ -70,7 +70,7 @@ class KlausDormannTests: XCTestCase {
|
||||
XCTAssert(error == nil, "Failed with error \(error!)")
|
||||
}
|
||||
|
||||
func runTest65C02(processor: CSTestMachine6502Processor) {
|
||||
private func runTest65C02(processor: CSTestMachine6502Processor) {
|
||||
func errorForTrapAddress(_ address: UInt16) -> String? {
|
||||
switch address {
|
||||
case 0x24f1: return nil // success!
|
||||
|
@ -11,8 +11,8 @@ import Foundation
|
||||
|
||||
class PatrikRakTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
|
||||
fileprivate var done = false
|
||||
fileprivate var output = ""
|
||||
private var done = false
|
||||
private var output = ""
|
||||
|
||||
private func runTest(_ name: String) {
|
||||
if let filename = Bundle(for: type(of: self)).path(forResource: name, ofType: "tap") {
|
||||
@ -124,4 +124,5 @@ class PatrikRakTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1247,4 +1247,5 @@ class Z80MachineCycleTests: XCTestCase {
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
import XCTest
|
||||
|
||||
class Z80MemptrTester: XCTestCase {
|
||||
|
||||
let machine = CSTestMachineZ80()
|
||||
|
||||
private func test(program : [UInt8], initialValue : UInt16) -> UInt16 {
|
||||
|
@ -11,8 +11,8 @@ import Foundation
|
||||
|
||||
class ZexallTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
|
||||
fileprivate var done = false
|
||||
fileprivate var output = ""
|
||||
private var done = false
|
||||
private var output = ""
|
||||
|
||||
private func runTest(_ name: String) {
|
||||
if let filename = Bundle(for: type(of: self)).path(forResource: name, ofType: "com") {
|
||||
@ -177,4 +177,5 @@ class ZexallTests: XCTestCase, CSTestMachineTrapHandler {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user