|
- # E02-S01: run the source-reader test in x128 (1581 true drive) and compare
- # every result record with the host-computed expectations.
- [CmdletBinding()]
- param([int]$Port = 6531, [int]$TimeoutSeconds = 180)
-
- $ErrorActionPreference = "Stop"
- $project = Split-Path $PSScriptRoot -Parent
- Import-Module (Join-Path $PSScriptRoot "lib\Nova128Test.psm1") -Force
- & (Join-Path $PSScriptRoot "build-source-test.ps1")
-
- $out = Join-Path $project "build\source-test"
- $disk = Join-Path $out "source-test.d81"
- $screenshot = Join-Path $out "source-test-vicii.png"
- $expected = Get-Content -Raw (Join-Path $out "expected.json") | ConvertFrom-Json
-
- $session = Start-Nova128X128 -Autostart $disk -Drive8Image $disk -Port $Port -Screenshot $screenshot
- try {
- $mb = Wait-Nova128Mailbox $session -TimeoutSeconds $TimeoutSeconds
- $count = $mb[8]
- $table = $mb[9] + 256 * $mb[10]
- if ($count -ne $expected.Count) { throw "program ran $count fixtures, host expects $($expected.Count)" }
- $raw = Read-Nova128Memory $session $table (16 * $count)
- } finally {
- Stop-Nova128X128 $session
- }
-
- $failures = @()
- for ($i = 0; $i -lt $count; $i++) {
- $r = $raw[(16 * $i)..(16 * $i + 15)]
- $e = $expected[$i]
- $got = [ordered]@{
- code = $r[0]; dos = $r[1]; kernal = $r[2]; line = $r[3] + 256 * $r[4]; col = $r[5]
- ldtnd = $r[6]; lines = $r[7] + 256 * $r[8]; len = $r[9] + 256 * $r[10]
- s1 = $r[11]; s2 = $r[12]; flag = $r[13]; lastline = $r[14] + 256 * $r[15]
- }
- $problems = @()
- if ($got.code -ne $e.code) { $problems += "code $($got.code) expected $($e.code)" }
- if ($got.ldtnd -ne 0) { $problems += "$($got.ldtnd) file(s) left open" }
- if ($got.flag -ne 1) {
- $problems += $(if ($e.code -eq 0) { "passes differ" } else { "source delivered after failure" })
- }
- if ($e.code -eq 0) {
- foreach ($k in "lines", "len", "s1", "s2") {
- if ($got[$k] -ne $e.$k) { $problems += "$k $($got[$k]) expected $($e.$k)" }
- }
- if ($got.lastline -ne $e.lines) { $problems += "src_line_no $($got.lastline) expected $($e.lines)" }
- $detail = "{0} lines, {1} bytes, fletcher {2:X2}{3:X2}" -f $got.lines, $got.len, $got.s1, $got.s2
- } else {
- if ($got.len -ne 0) { $problems += "src_len $($got.len) after failure" }
- if ($null -ne $e.line -and ($got.line -ne $e.line -or $got.col -ne $e.col)) {
- $problems += "position $($got.line):$($got.col) expected $($e.line):$($e.col)"
- }
- if ($null -ne $e.dos -and $got.dos -ne $e.dos) { $problems += "DOS $($got.dos) expected $($e.dos)" }
- $detail = if ($e.code -eq 1) { "DOS {0}" -f $got.dos } else { "at {0}:{1}" -f $got.line, $got.col }
- }
- $status = if ($problems) { "FAIL" } else { "ok" }
- Write-Host (" {0,-11} code {1} {2,-36} {3}" -f $e.name, $got.code, $detail, $status)
- if ($problems) { $failures += "$($e.name): " + ($problems -join "; ") }
- }
-
- if ($mb[3] -ne 0xA5) { $failures += ("C128 reported FAIL ({0} fixture(s))" -f $mb[4]) }
- if ($failures) { throw ("source-reader verification failed:`n " + ($failures -join "`n ")) }
- Write-Host "verified source reader: $count fixtures match host expectations"
- Write-Host "screenshot: $screenshot"
|