1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-29 12:50:28 +00:00

Added one basic timing test, for now: implied nop should be two cycles.

This commit is contained in:
Thomas Harte 2015-08-13 01:06:56 +01:00
parent d19f8ed507
commit e8f70398c1
3 changed files with 36 additions and 1 deletions

View File

@ -37,6 +37,7 @@ extern const uint8_t CSTestMachineJamOpcode;
- (void)returnFromSubroutine; - (void)returnFromSubroutine;
@property (nonatomic, readonly) BOOL isJammed; @property (nonatomic, readonly) BOOL isJammed;
@property (nonatomic, readonly) uint32_t timestamp;
@property (nonatomic, weak) id <CSTestMachineJamHandler> jamHandler; @property (nonatomic, weak) id <CSTestMachineJamHandler> jamHandler;
@end @end

View File

@ -95,4 +95,8 @@ class MachineJamHandler: public CPU6502::AllRAMProcessor::JamHandler {
delete _cppJamHandler; delete _cppJamHandler;
} }
- (uint32_t)timestamp {
return _processor.get_timestamp();
}
@end @end

View File

@ -9,5 +9,35 @@
import Foundation import Foundation
import XCTest import XCTest
class TimingTests: XCTestCase { class TimingTests: XCTestCase, CSTestMachineJamHandler {
private var endTime: UInt32 = 0
func testImpliedNOP() {
let code: [UInt8] = [0xea, CSTestMachineJamOpcode]
self.runTest(code, expectedRunLength: 2)
}
func runTest(code: [UInt8], expectedRunLength: UInt32) {
let machine = CSTestMachine()
machine.jamHandler = self
let immediateCode = NSData(bytes: code, length: code.count)
machine.setData(immediateCode, atAddress: 0x200)
machine.setValue(0x200, forRegister: CSTestMachineRegister.ProgramCounter)
self.endTime = 0
while self.endTime == 0 {
machine.runForNumberOfCycles(10)
}
XCTAssert(self.endTime == expectedRunLength, "Took \(self.endTime) cycles to perform")
}
func testMachine(machine: CSTestMachine!, didJamAtAddress address: UInt16) {
if self.endTime == 0 {
self.endTime = machine.timestamp - 3
}
}
} }