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,153 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
final class AssemblyReferenceTests: XCTestCase {
|
||||
private let catalog = AssemblyReference.shared
|
||||
private var root: URL {
|
||||
URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent()
|
||||
.deletingLastPathComponent().deletingLastPathComponent()
|
||||
}
|
||||
|
||||
func testVocabularyAgainstBundledAssemblerAndDecoder() throws {
|
||||
func matches(_ expression: String, _ file: String) throws -> [[String]] {
|
||||
let text = try String(contentsOf: root.appendingPathComponent(file), encoding: .utf8) as NSString
|
||||
let regex = try NSRegularExpression(pattern: expression)
|
||||
return regex.matches(in: text as String, range: NSRange(location: 0, length: text.length)).map { match in
|
||||
(1..<match.numberOfRanges).map { text.substring(with: match.range(at: $0)) }
|
||||
}
|
||||
}
|
||||
let rows = try matches(#"\{\s*"([^"]+)",\s*\{[^}]+\}\s*,\s*insn_parse_\w+,[^}]+?lwasm_insn_(normal|is6309)\s*\}"#, "third_party/lwtools/lwasm/instab.c")
|
||||
let instructions = catalog.entries.filter { $0.category == .instructions }
|
||||
let words = Set(instructions.flatMap { [$0.name] + $0.aliases })
|
||||
XCTAssertEqual(words, Set(rows.map { $0[0].uppercased() }))
|
||||
for row in rows {
|
||||
let item = try XCTUnwrap(catalog.entry(row[0]))
|
||||
XCTAssertEqual(item.only6309, row[1] == "is6309", row[0])
|
||||
}
|
||||
let allAssemblerWords = try matches(#"\{\s*"([^"]+)",\s*\{[^}]+\}\s*,\s*\w+,[^}]+?lwasm_insn_\w+\s*\}"#, "third_party/lwtools/lwasm/instab.c")
|
||||
for row in allAssemblerWords { XCTAssertNotNil(catalog.entry(row[0]), row[0]) }
|
||||
let decoder = Set(try matches(#"0x[0-9a-fA-F]{2},\s*"([^"]+)""#, "src/core/OpCodeTables.h").map { $0[0] })
|
||||
.subtracting(["-","page2","page3","HALT","BREAK"])
|
||||
XCTAssertTrue(decoder.isSubset(of: words))
|
||||
XCTAssertTrue(instructions.allSatisfy { !decoder.isDisjoint(with: [$0.name] + $0.aliases) })
|
||||
XCTAssertEqual(Set(catalog.entries.map(\.id)).count, catalog.entries.count)
|
||||
for item in catalog.entries {
|
||||
for link in item.links { XCTAssertNotNil(catalog.entry(link), link) }
|
||||
for citation in item.citations {
|
||||
XCTAssertTrue(AssemblyReference.bibliography.keys.contains(where: citation.hasPrefix), citation)
|
||||
}
|
||||
if let example = item.example { XCTAssertTrue(AssemblyReferenceLesson.all.contains { $0.id == example }) }
|
||||
}
|
||||
}
|
||||
|
||||
func testTargetAwareSearchAndOperandCompletion() {
|
||||
func complete(_ source: String, _ hd: Bool = false) -> [String] {
|
||||
catalog.completions(in: source, at: (source as NSString).length, target6309: hd)
|
||||
}
|
||||
XCTAssertEqual(catalog.search("BHS", target6309: false, category: nil).first?.name, "BCC")
|
||||
XCTAssertTrue(catalog.search("TFM", target6309: false, category: .instructions).isEmpty)
|
||||
XCTAssertTrue(catalog.search(",X+", target6309: nil, category: .addressing).contains { $0.name == "Indexed" })
|
||||
XCTAssertTrue(catalog.search("copy a byte", target6309: false, category: nil).contains { $0.name == "LDA" })
|
||||
XCTAssertEqual(complete(" tfr a,b"), ["B"])
|
||||
XCTAssertFalse(complete(" tfr a,").contains("X"))
|
||||
XCTAssertTrue(complete(" lda ,", true).contains("W"))
|
||||
XCTAssertFalse(complete(" lda ,").contains("W"))
|
||||
XCTAssertTrue(complete("save fcb 0\n sta #s").isEmpty)
|
||||
XCTAssertTrue(complete(" lda E,").isEmpty)
|
||||
XCTAssertFalse(complete(" lda A,", true).contains("W"))
|
||||
XCTAssertFalse(complete(" pshs ").contains("S"))
|
||||
XCTAssertTrue(complete(" pshu ").contains("S"))
|
||||
XCTAssertEqual(complete(" tfm x-,y", true), ["Y-"])
|
||||
XCTAssertTrue(complete(" fcc /ld").isEmpty)
|
||||
XCTAssertTrue(complete(" lda #1 ; ld").isEmpty)
|
||||
XCTAssertTrue(complete(" lda #1 ld").isEmpty)
|
||||
XCTAssertTrue(complete(" i\u{0301} ; ld").isEmpty)
|
||||
XCTAssertEqual(complete("myTable fcb 1\n lda myT"), ["myTable"])
|
||||
XCTAssertEqual(catalog.topic(in: "start lda ,x+", at: 10, target6309: false), "LDA")
|
||||
XCTAssertNil(catalog.topic(in: " ldw #1", at: 10, target6309: false))
|
||||
let lesson = AssemblyReferenceLesson.all[0]
|
||||
XCTAssertNotEqual(lesson.request.id, lesson.request.id)
|
||||
}
|
||||
|
||||
/// All teaching listings use one DECB load block and an entry at $3F00.
|
||||
private func assemble(_ lesson: AssemblyReferenceLesson, hd: Bool, folder: URL) throws -> (Int32, Data) {
|
||||
let candidates = [Bundle.main.resourceURL?.appendingPathComponent("Toolchain/bin/lwasm"),
|
||||
root.appendingPathComponent("platforms/macos/LocalResources/ToolchainBundle/bin/lwasm"),
|
||||
root.appendingPathComponent(".build/toolchain/install/bin/lwasm")].compactMap { $0 }
|
||||
guard let tool = candidates.first(where: { FileManager.default.isExecutableFile(atPath: $0.path) }) else {
|
||||
throw XCTSkip("A local or bundled LWASM is required to assemble the reference lessons.")
|
||||
}
|
||||
let source = folder.appendingPathComponent(lesson.id + ".asm")
|
||||
let output = folder.appendingPathComponent(UUID().uuidString + ".bin")
|
||||
try lesson.source.write(to: source, atomically: true, encoding: .utf8)
|
||||
let process = Process()
|
||||
process.executableURL = tool
|
||||
process.arguments = [hd ? "--6309" : "--6809","--format=decb","--output=" + output.path,source.path]
|
||||
try process.run()
|
||||
process.waitUntilExit()
|
||||
return (process.terminationStatus, (try? Data(contentsOf: output)) ?? Data())
|
||||
}
|
||||
|
||||
@MainActor func testAssembledLessonsExecuteOnDeclaredProcessorsAndModes() async throws {
|
||||
let folder = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
|
||||
try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
|
||||
defer { try? FileManager.default.removeItem(at: folder) }
|
||||
func command(_ operation: (@escaping @Sendable (VCCMachineSnapshot) -> Void) -> Void) async -> VCCMachineSnapshot {
|
||||
await withCheckedContinuation { cont in operation { cont.resume(returning: $0) } }
|
||||
}
|
||||
for lesson in AssemblyReferenceLesson.all {
|
||||
if lesson.hd { XCTAssertNotEqual(try assemble(lesson, hd: false, folder: folder).0, 0) }
|
||||
for hd in (lesson.hd ? [true] : [false,true]) {
|
||||
let (status, bin) = try assemble(lesson, hd: hd, folder: folder)
|
||||
XCTAssertEqual(status, 0)
|
||||
guard bin.count >= 10 else { XCTFail(lesson.id); continue }
|
||||
XCTAssertEqual(Array(bin.prefix(1)), [0])
|
||||
XCTAssertEqual(Array(bin[3...4]), [0x3F,0])
|
||||
XCTAssertEqual(Array(bin.suffix(5)), [0xFF,0,0,0x3F,0])
|
||||
let code = Data(bin.dropFirst(5).dropLast(5))
|
||||
XCTAssertEqual(code.count, Int(bin[1]) * 256 + Int(bin[2]))
|
||||
if lesson.id == "cell" { XCTAssertEqual(Array(code), [0x86,0x8F,0xB7,4,0,0x20,0xFE]) }
|
||||
for native in (hd ? [false,true] : [false]) {
|
||||
let controller = VCCMachineController()
|
||||
_ = await command { controller.setAudioEnabled(false, volume: 0, completion: $0) }
|
||||
_ = await command { controller.loadDiagnostic(use6309: hd, completion: $0) }
|
||||
if native {
|
||||
_ = await command { controller.debuggerWriteMemory(address: 0x3E00, data: Data([0x11,0x3D,1]), completion: $0) }
|
||||
_ = await command { controller.debuggerSetPC(0x3E00, completion: $0) }
|
||||
_ = await command(controller.debuggerStep)
|
||||
}
|
||||
_ = await command { controller.debuggerWriteMemory(address: 0x3F00, data: code, completion: $0) }
|
||||
_ = await command { controller.debuggerSetPC(0x3F00, completion: $0) }
|
||||
let steps = ["cell":2,"count":7,"call":6,"page":2,"signed":4,"word":1,"transfer":4][lesson.id]!
|
||||
for _ in 0..<steps { _ = await command(controller.debuggerStep) }
|
||||
let address: UInt16 = ["cell":0x0400,"page":0x1A00,"call":0x3F10,"transfer":0x3F13][lesson.id] ?? 0x3F00
|
||||
let snap: VCCDebuggerSnapshot = await withCheckedContinuation { cont in
|
||||
controller.debuggerSnapshot(address: 0, followPC: true, memoryAddress: address) { cont.resume(returning: $0) }
|
||||
}
|
||||
if hd { XCTAssertEqual((snap.registers["MD"]?.intValue ?? -1) & 1, native ? 1 : 0) }
|
||||
let context = "\(lesson.id) hd=\(hd) native=\(native)"
|
||||
switch lesson.id {
|
||||
case "cell": XCTAssertEqual(snap.memory.first, 0x8F, context)
|
||||
case "count": XCTAssertEqual(snap.registers["B"]?.intValue, 0, context)
|
||||
XCTAssertEqual((snap.registers["CC"]?.intValue ?? 0) & 4, 4, context)
|
||||
XCTAssertEqual(snap.machine.programCounter, 0x3F05, context)
|
||||
case "call": XCTAssertEqual(snap.memory.first, 8, context)
|
||||
XCTAssertEqual(snap.registers["S"]?.intValue, 0x3F51, context)
|
||||
case "page": XCTAssertEqual(snap.memory.first, 0xAA, context)
|
||||
case "signed": XCTAssertEqual(snap.machine.programCounter, 0x3F0C, context)
|
||||
XCTAssertEqual((snap.registers["CC"]?.intValue ?? 0) & 15, 8, context)
|
||||
case "word": XCTAssertEqual(snap.registers["E"]?.intValue, 0x12, context)
|
||||
XCTAssertEqual(snap.registers["F"]?.intValue, 0x34, context)
|
||||
case "transfer": XCTAssertEqual(Array(snap.memory.prefix(3)), [0xA5,0x5A,0x42], context)
|
||||
XCTAssertEqual(snap.registers["X"]?.intValue, 0x3F13, context)
|
||||
XCTAssertEqual(snap.registers["Y"]?.intValue, 0x3F16, context)
|
||||
XCTAssertEqual(snap.registers["F"]?.intValue, 0, context)
|
||||
default: XCTFail("Missing outcome for " + lesson.id)
|
||||
}
|
||||
_ = await command(controller.shutdown)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user