|
- # E05-S01: run the free-list heap fixture and check its phase flags, R005
- # exhaustion fault, and screen output.
- [CmdletBinding()]
- param([int]$Port = 6547, [int]$TimeoutSeconds = 180)
-
- $ErrorActionPreference = "Stop"
- $project = Split-Path $PSScriptRoot -Parent
- Import-Module (Join-Path $PSScriptRoot "lib\Nova128Test.psm1") -Force
- & (Join-Path $PSScriptRoot "build-heap-test.ps1")
-
- $out = Join-Path $project "build\heap-test"
- $disk = Join-Path $out "heap-test.d81"
- $expected = @(
- "NOVA128 HEAP TEST",
- "HEAP OK",
- "RUNTIME FAULT R005")
- $failures = @()
-
- $session = Start-Nova128X128 -Autostart $disk -Drive8Image $disk -Port $Port `
- -Screenshot (Join-Path $out "heap-test-vicii.png")
- try {
- $mb = Wait-Nova128Mailbox $session -TimeoutSeconds $TimeoutSeconds
- Start-Sleep -Seconds 1
- $screenRam = Read-Nova128Memory $session 0x0400 1000
- } finally {
- Stop-Nova128X128 $session -SettleSeconds 0
- }
-
- if ($mb[2] -ne 0x03) { $failures += ("producer $($mb[2]) expected 3 (generated program)") }
- if ($mb[3] -ne 0xFA) { $failures += ("status ${0:X2} expected FA (failure)" -f $mb[3]) }
- if ($mb[4] -ne 5 -or $mb[5] -ne 0) { $failures += ("code {0} expected 5 (heap)" -f ($mb[4] + 256 * $mb[5])) }
- $addr = $mb[6] + 256 * $mb[7]
- if ($addr -ne 0x4000) { $failures += ("address ${0:X4} expected 4000" -f $addr) }
- for ($i = 0; $i -lt 8; $i++) {
- if ($mb[8 + $i] -ne 1) { $failures += ("heap phase {0} flag is {1}, expected 1" -f ($i + 1), $mb[8 + $i]) }
- }
-
- $rows = for ($r = 0; $r -lt 25; $r++) {
- $chars = for ($c = 0; $c -lt 40; $c++) {
- $code = $screenRam[$r * 40 + $c]
- if ($code -le 0x1F) { [char]($code + 0x40) } elseif ($code -le 0x3F) { [char]$code } else { '?' }
- }
- (-join $chars).TrimEnd()
- }
- for ($r = 0; $r -lt $expected.Count; $r++) {
- if ($rows[$r] -cne $expected[$r]) {
- $failures += "screen row ${r}: '$($rows[$r])' expected '$($expected[$r])'"
- }
- }
-
- if ($failures) { throw ("heap verification failed:`n " + ($failures -join "`n ")) }
- Write-Host "screen:"
- $rows[0..($expected.Count - 1)] | ForEach-Object { Write-Host " |$_" }
- Write-Host ("mailbox: producer 3, status FA, code 5, address {0:X4}, flags 01 01 01 01 01 01 01 01" -f $addr)
- Write-Host "verified allocation, zeroing, splitting, coalescing, stress, double-free, corrupt-header detection, and R005 exhaustion"
|