Publish VCC Plus OSS source distribution for 3.6.2 build 60
This commit is contained in:
commit
c652a5276d
1192 files changed
+272368
No files matched your search
@@ -0,0 +1,98 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
import XCTest
|
||||
|
||||
final class DebuggerTests: XCTestCase {
|
||||
@MainActor private func command(_ operation: (@escaping @Sendable (VCCMachineSnapshot) -> Void) -> Void) async -> VCCMachineSnapshot {
|
||||
await withCheckedContinuation { continuation in operation { continuation.resume(returning: $0) } }
|
||||
}
|
||||
@MainActor private func capture(_ controller: VCCMachineController, address: UInt16 = 0x8000,
|
||||
memory: UInt16 = 0x4000, followPC: Bool = true) async -> VCCDebuggerSnapshot {
|
||||
await withCheckedContinuation { continuation in
|
||||
controller.debuggerSnapshot(address: address, followPC: followPC, memoryAddress: memory) {
|
||||
continuation.resume(returning: $0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@MainActor func testDebuggerBridgeSnapshotsEditsAndBreakpointsBothCPUs() async {
|
||||
for use6309 in [false, true] {
|
||||
let controller = VCCMachineController()
|
||||
_ = await command { controller.setAudioEnabled(false, volume: 0, completion: $0) }
|
||||
let loaded = await command { controller.loadDiagnostic(use6309: use6309, completion: $0) }
|
||||
let before = await capture(controller)
|
||||
XCTAssertTrue(Thread.isMainThread)
|
||||
XCTAssertEqual(before.machine.state, .paused)
|
||||
XCTAssertEqual(before.instructions.first?.mnemonic, "INC")
|
||||
XCTAssertEqual(before.instructions.first?.address, 0x8000)
|
||||
XCTAssertEqual(before.registers["PC"]?.uint16Value, 0x8000)
|
||||
XCTAssertEqual(before.registers["E"] != nil, use6309)
|
||||
XCTAssertEqual(before.memory.count, 256)
|
||||
let stepped = await command(controller.debuggerStep)
|
||||
XCTAssertNil(stepped.errorMessage); XCTAssertEqual(stepped.programCounter, 0x8003)
|
||||
XCTAssertEqual(stepped.generation, loaded.generation); XCTAssertEqual(stepped.state, .paused)
|
||||
XCTAssertGreaterThan(stepped.cycles, before.machine.cycles)
|
||||
let after = await capture(controller)
|
||||
XCTAssertEqual(after.memory[0], before.memory[0] &+ 1)
|
||||
XCTAssertEqual(before.instructions.first?.address, 0x8000, "Published snapshots remain immutable")
|
||||
let written = await command { controller.debuggerWriteMemory(address: 0x4000, data: Data([0x5A, 0xA5]), completion: $0) }
|
||||
XCTAssertNil(written.errorMessage)
|
||||
let edited = await capture(controller)
|
||||
XCTAssertEqual(edited.memory.prefix(2), Data([0x5A, 0xA5]))
|
||||
_ = await command { controller.debuggerSetPC(0x8000, completion: $0) }
|
||||
_ = await command { controller.debuggerSetBreakpoints([0x8003], completion: $0) }
|
||||
let running = await command(controller.resume)
|
||||
XCTAssertEqual(running.state, .running)
|
||||
var hit = running
|
||||
for _ in 0..<100 {
|
||||
hit = await command(controller.snapshot)
|
||||
if hit.state == .paused { break }
|
||||
try? await Task.sleep(nanoseconds: 10_000_000)
|
||||
}
|
||||
XCTAssertEqual(hit.state, .paused); XCTAssertEqual(hit.programCounter, 0x8003)
|
||||
let stopped = await capture(controller)
|
||||
XCTAssertEqual(stopped.breakpoints, [0x8003])
|
||||
XCTAssertEqual(hit.generation, loaded.generation)
|
||||
_ = await command(controller.resume)
|
||||
for _ in 0..<100 {
|
||||
hit = await command(controller.snapshot)
|
||||
if hit.state == .paused { break }
|
||||
try? await Task.sleep(nanoseconds: 10_000_000)
|
||||
}
|
||||
XCTAssertGreaterThan(hit.cycles, stopped.machine.cycles, "Continue must pass the current breakpoint before stopping again")
|
||||
XCTAssertEqual(hit.programCounter, 0x8003)
|
||||
_ = await command(controller.shutdown)
|
||||
}
|
||||
}
|
||||
@MainActor func testDebuggerRejectionsAndUnavailableMemoryAreSafe() async {
|
||||
let controller = VCCMachineController()
|
||||
let empty = await capture(controller)
|
||||
XCTAssertEqual(empty.machine.state, .empty); XCTAssertTrue(empty.instructions.isEmpty)
|
||||
_ = await command { controller.setAudioEnabled(false, volume: 0, completion: $0) }
|
||||
_ = await command(controller.loadDiagnostic)
|
||||
let before = await capture(controller, address: 0xFF00, memory: 0xFF00, followPC: false)
|
||||
XCTAssertEqual(before.memoryAvailable[0], 0)
|
||||
XCTAssertFalse(before.instructions.first?.valid ?? true)
|
||||
XCTAssertEqual(before.instructions.first?.bytes.count, 0)
|
||||
let boundary = await capture(controller, address: 0xFF8F, memory: 0xFF80, followPC: false)
|
||||
XCTAssertFalse(boundary.instructions[0].valid)
|
||||
XCTAssertEqual(boundary.instructions[1].address, 0xFF90,
|
||||
"An unavailable port must not consume the first safe GIME byte as an operand")
|
||||
for (address, data) in [(UInt16(0x8000), Data([0])), (0xFF00, Data([0])), (0xFFFF, Data([1, 2]))] {
|
||||
let rejected = await command { controller.debuggerWriteMemory(address: address, data: data, completion: $0) }
|
||||
XCTAssertNotNil(rejected.errorMessage)
|
||||
XCTAssertEqual(rejected.cycles, before.machine.cycles)
|
||||
XCTAssertEqual(rejected.generation, before.machine.generation)
|
||||
}
|
||||
for values: [NSNumber] in [[-1], [65536], [1.5], [NSNumber(value: Double.nan)]] {
|
||||
let rejected = await command { controller.debuggerSetBreakpoints(values, completion: $0) }
|
||||
XCTAssertNotNil(rejected.errorMessage)
|
||||
}
|
||||
_ = await command(controller.resume)
|
||||
let edit = await command { controller.debuggerSetPC(0x5000, completion: $0) }
|
||||
XCTAssertNotNil(edit.errorMessage); XCTAssertEqual(edit.state, .running)
|
||||
let rejectedStep = await command(controller.debuggerStep)
|
||||
XCTAssertNotNil(rejectedStep.errorMessage); XCTAssertEqual(rejectedStep.state, .running)
|
||||
_ = await command(controller.shutdown)
|
||||
let closed = await capture(controller)
|
||||
XCTAssertEqual(closed.machine.state, .closed); XCTAssertTrue(closed.instructions.isEmpty)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user