Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

188 linhas
9.1KB

  1. # E07-S05: drive build/n128c.prg through scripts/launch-compiler.ps1 on a fresh
  2. # development image and check the PRG, MAP, ERR and summary it produces.
  3. #
  4. # success COUNTER.N8 -> COUNTER.PRG + COUNTER.MAP, no ERR, summary on screen
  5. # failure BAD.N8 -> BAD.ERR, no BAD.PRG/BAD.MAP, earlier outputs intact
  6. # collision COUNTER.N8 -> OUTPUT EXISTS, COUNTER.PRG byte-identical
  7. # run the generated COUNTER.PRG reports MB_ST_PASS in a second session
  8. [CmdletBinding()]
  9. param([int]$Port = 6552, [int]$TimeoutSeconds = 240)
  10. $ErrorActionPreference = "Stop"
  11. $project = Split-Path $PSScriptRoot -Parent
  12. Import-Module (Join-Path $PSScriptRoot "lib\Nova128Test.psm1") -Force
  13. & (Join-Path $PSScriptRoot "build-driver.ps1") | Out-Host
  14. $root = Join-Path $project "build\driver-test"
  15. if (Test-Path -LiteralPath $root) { Remove-Item -LiteralPath $root -Recurse -Force }
  16. New-Item -ItemType Directory -Force -Path $root | Out-Null
  17. $driver = Join-Path $project "build\n128c.prg"
  18. $work = Join-Path $root "work.d81"
  19. $c1541 = Get-ViceTool "c1541"
  20. $failures = @()
  21. $counterPet = Join-Path $root "counter.pet"
  22. [IO.File]::WriteAllBytes($counterPet, (ConvertTo-Nova128Petscii `
  23. (Get-Content -Raw -LiteralPath (Join-Path $project "tests\compiler\counter.n8"))))
  24. $badPet = Join-Path $root "bad.pet"
  25. [IO.File]::WriteAllBytes($badPet, (ConvertTo-Nova128Petscii `
  26. (Get-Content -Raw -LiteralPath (Join-Path $project "tests\grammar\rejected\miss_end.n8"))))
  27. New-Nova128Disk -Path $work -Files @(
  28. @{ Name = "n128c"; Path = $driver; Type = "prg" },
  29. @{ Name = "counter.n8"; Path = $counterPet; Type = "seq" },
  30. @{ Name = "bad.n8"; Path = $badPet; Type = "seq" })
  31. function Invoke-Compile {
  32. param([string]$Keys, [string]$Screenshot)
  33. if (Test-Path -LiteralPath $Screenshot) { Remove-Item -LiteralPath $Screenshot -Force }
  34. & (Join-Path $PSScriptRoot "launch-compiler.ps1") -CompilerPrg $driver -DiskImage $work `
  35. -SkipPrepare -Keys $Keys -KeyDelay 4000 -LimitCycles 200000000 `
  36. -Screenshot $Screenshot -Warp | Out-Host
  37. if (-not (Test-Path -LiteralPath $Screenshot)) {
  38. throw "the compiler session produced no exit screenshot"
  39. }
  40. }
  41. function Get-Listing {
  42. return ((& $c1541 -attach $work -list 2>&1) -join "`n")
  43. }
  44. function Read-DiskFile {
  45. param([string]$Name, [string]$Type, [string]$Dest)
  46. if (Test-Path -LiteralPath $Dest) { Remove-Item -LiteralPath $Dest -Force }
  47. & $c1541 $work -read "$Name,$Type" $Dest 2>&1 | Out-Null
  48. if (-not (Test-Path -LiteralPath $Dest)) { throw "could not read $Name,$Type from the disk" }
  49. return ,([IO.File]::ReadAllBytes($Dest))
  50. }
  51. function Get-ScreenText {
  52. param($Session)
  53. $ram = Read-Nova128Memory $Session 0x0400 1000
  54. $rows = for ($r = 0; $r -lt 25; $r++) {
  55. $chars = for ($c = 0; $c -lt 40; $c++) {
  56. $code = $ram[$r * 40 + $c]
  57. if ($code -le 0x1F) { [char]($code + 0x40) } elseif ($code -le 0x3F) { [char]$code } else { '?' }
  58. }
  59. -join $chars
  60. }
  61. return ($rows -join "`n")
  62. }
  63. # 1: the on-screen summary, read from a copy so the three launcher runs below
  64. # still start from an image without outputs.
  65. $summaryDisk = Join-Path $root "summary.d81"
  66. Copy-Item -LiteralPath $work -Destination $summaryDisk -Force
  67. $session = Start-Nova128X128 -Autostart $summaryDisk -Drive8Image $summaryDisk -Port $Port `
  68. -Keys "counter.n8\n" -KeyDelay 4000 -Screenshot (Join-Path $root "summary-screen.png")
  69. try {
  70. $screenText = ""
  71. $deadline = [DateTime]::UtcNow.AddSeconds(120)
  72. while ([DateTime]::UtcNow -lt $deadline) {
  73. Invoke-Nova128Monitor $session "x" | Out-Null
  74. Start-Sleep -Seconds 1
  75. $screenText = Get-ScreenText $session
  76. if ($screenText -match "OUTPUT COUNTER\.PRG" -and $screenText -match "0 ERRORS" -and
  77. $screenText -match "SOURCE COUNTER\.N8") { break }
  78. }
  79. } finally {
  80. Stop-Nova128X128 $session
  81. }
  82. foreach ($needle in @("NOVA128 COMPILER", "SOURCE COUNTER.N8", "OUTPUT COUNTER.PRG", "0 ERRORS")) {
  83. if ($screenText -notmatch [regex]::Escape($needle)) {
  84. $failures += "the summary did not show '$needle'"
  85. }
  86. }
  87. # 2: success through the launcher.
  88. Invoke-Compile -Keys "counter.n8\n" -Screenshot (Join-Path $root "counter-summary.png")
  89. $listing = Get-Listing
  90. if ($listing -notmatch '"counter\.prg"\s+prg') { $failures += "COUNTER.PRG is missing" }
  91. if ($listing -notmatch '"counter\.map"\s+seq') { $failures += "COUNTER.MAP is missing" }
  92. if ($listing -match '"counter\.err"') { $failures += "a clean source left COUNTER.ERR" }
  93. $prgPath = Join-Path $root "counter.prg"
  94. $prg = Read-DiskFile -Name "counter.prg" -Type "p" -Dest $prgPath
  95. $stub = [byte[]](0x0B, 0x1C, 0x0A, 0x00, 0x9E, 0x37, 0x31, 0x38, 0x31, 0x00, 0x00, 0x00)
  96. if ($prg.Length -lt 14 -or $prg[0] -ne 0x01 -or $prg[1] -ne 0x1C) {
  97. $failures += "COUNTER.PRG does not load at `$1C01"
  98. } else {
  99. for ($i = 0; $i -lt $stub.Length; $i++) {
  100. if ($prg[2 + $i] -ne $stub[$i]) {
  101. $failures += ("COUNTER.PRG stub byte {0} is {1:X2}, expected {2:X2}" -f $i, $prg[2 + $i], $stub[$i])
  102. break
  103. }
  104. }
  105. }
  106. # c1541 translates PETSCII CR to CRLF on read, so normalize before matching.
  107. $map = ([Text.Encoding]::ASCII.GetString((Read-DiskFile -Name "counter.map" -Type "s" `
  108. -Dest (Join-Path $root "counter.map"))) -replace "`r", "`n")
  109. $mapLines = $map -split "`n"
  110. $codeMatch = [regex]::Match($map, '(?im)^SECTION CODE ([0-9a-f]{4}) ([0-9a-f]{4})')
  111. $startMatch = [regex]::Match($map, '(?im)^SECTION START ([0-9a-f]{4}) ([0-9a-f]{4})')
  112. if ($mapLines[0] -ne "NOVA128 MAP 1") { $failures += "MAP header is '$($mapLines[0])'" }
  113. if ($map -notmatch '(?im)^ENTRY 1c0d') { $failures += "MAP ENTRY is not 1C0D" }
  114. if ($map -notmatch '(?im)^SECTION STUB 1c01 000c') { $failures += "MAP STUB section is wrong" }
  115. if (-not $startMatch.Success) {
  116. $failures += "MAP has no START section"
  117. } elseif ([Convert]::ToInt32($startMatch.Groups[1].Value, 16) -ne 0x1C0D) {
  118. $failures += "MAP START does not begin at 1C0D"
  119. }
  120. if (-not $codeMatch.Success) {
  121. $failures += "MAP has no CODE section"
  122. } else {
  123. $codeStart = [Convert]::ToInt32($codeMatch.Groups[1].Value, 16)
  124. $codeSize = [Convert]::ToInt32($codeMatch.Groups[2].Value, 16)
  125. if ($codeStart -ne 0x1C57) { $failures += ("CODE starts at {0:X4}, expected 1C57" -f $codeStart) }
  126. if ($prg.Length -ne (2 + 12 + 0x4A + $codeSize)) {
  127. $failures += ("PRG is {0} bytes, MAP accounts for {1}" -f $prg.Length, (2 + 12 + 0x4A + $codeSize))
  128. }
  129. if ($codeSize -eq 0) { $failures += "CODE section is empty" }
  130. }
  131. # 3: a syntax error writes the ERR file and no PRG, and leaves COUNTER.PRG alone.
  132. Invoke-Compile -Keys "bad.n8\n" -Screenshot (Join-Path $root "bad-summary.png")
  133. $listing = Get-Listing
  134. if ($listing -notmatch '"bad\.err"\s+seq') { $failures += "BAD.ERR is missing" }
  135. if ($listing -match '"bad\.prg"') { $failures += "a failing source produced BAD.PRG" }
  136. if ($listing -match '"bad\.map"') { $failures += "a failing source produced BAD.MAP" }
  137. $errText = [Text.Encoding]::ASCII.GetString((Read-DiskFile -Name "bad.err" -Type "s" `
  138. -Dest (Join-Path $root "bad.err")))
  139. if ($errText -notmatch '^E\d{3} BAD\.N8 \d+ ') { $failures += "BAD.ERR has no catalogued diagnostic" }
  140. if ($listing -notmatch '"counter\.prg"\s+prg') { $failures += "the failure removed COUNTER.PRG" }
  141. $afterFailure = Read-DiskFile -Name "counter.prg" -Type "p" -Dest (Join-Path $root "counter-after.prg")
  142. if ([Convert]::ToBase64String($afterFailure) -ne [Convert]::ToBase64String($prg)) {
  143. $failures += "the failing run changed COUNTER.PRG"
  144. }
  145. # 4: an existing output is refused and the file stays byte-identical.
  146. Invoke-Compile -Keys "counter.n8\n" -Screenshot (Join-Path $root "collision-summary.png")
  147. $listing = Get-Listing
  148. if (([regex]::Matches($listing, '"counter\.prg"')).Count -ne 1) {
  149. $failures += "the collision run changed the COUNTER.PRG directory entry"
  150. }
  151. $afterCollision = Read-DiskFile -Name "counter.prg" -Type "p" -Dest (Join-Path $root "counter-again.prg")
  152. if ([Convert]::ToBase64String($afterCollision) -ne [Convert]::ToBase64String($prg)) {
  153. $failures += "a refused output changed COUNTER.PRG"
  154. }
  155. # 5: the generated program itself runs and reaches its started/pass contract.
  156. $runSession = Start-Nova128X128 -Autostart $prgPath -Port ($Port + 1) `
  157. -Screenshot (Join-Path $root "counter-run.png")
  158. try {
  159. $mb = Wait-Nova128Mailbox $runSession -TimeoutSeconds 120
  160. } finally {
  161. Stop-Nova128X128 $runSession
  162. }
  163. if ($mb[0] -ne 0x4E -or $mb[1] -ne 0x38) { $failures += "the generated program did not initialise the mailbox" }
  164. if ($mb[2] -ne 0x03) { $failures += ("producer {0:X2}, expected 03 (generated program)" -f $mb[2]) }
  165. if ($mb[3] -ne 0xA5) { $failures += ("generated program status {0:X2}, expected A5" -f $mb[3]) }
  166. if ($failures) { throw ("n128c verification failed:`n " + ($failures -join "`n ")) }
  167. Write-Host ("summary: SOURCE COUNTER.N8 / OUTPUT COUNTER.PRG / 0 ERRORS")
  168. Write-Host ("success: COUNTER.PRG {0} bytes, COUNTER.MAP {1} bytes, no COUNTER.ERR" -f
  169. $prg.Length, $map.Length)
  170. Write-Host ("failure: BAD.ERR {0}, no BAD.PRG, COUNTER.PRG unchanged" -f $errText.Trim())
  171. Write-Host "collision: OUTPUT EXISTS and COUNTER.PRG unchanged"
  172. Write-Host "run: generated COUNTER.PRG reported MB_ST_PASS in x128"

Powered by TurnKey Linux.