Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

100 rindas
4.5KB

  1. # E04-S03: run the scalar emitter fixture, check results, capture golden bytes,
  2. # disassemble them with da65, and compare committed expectations when present.
  3. [CmdletBinding()]
  4. param(
  5. [int]$Port = 6530,
  6. [int]$TimeoutSeconds = 90
  7. )
  8. $ErrorActionPreference = "Stop"
  9. $project = Split-Path $PSScriptRoot -Parent
  10. Import-Module (Join-Path $PSScriptRoot "lib\Nova128Test.psm1") -Force
  11. & (Join-Path $PSScriptRoot "build-scalar-test.ps1")
  12. $out = Join-Path $project "build\scalar-test"
  13. $prg = Join-Path $out "scalar-test.prg"
  14. $labels = Join-Path $out "scalar-test.lbl"
  15. $session = Start-Nova128X128 -Autostart $prg -Port $Port `
  16. -Screenshot (Join-Path $out "scalar-test-vicii.png")
  17. try {
  18. $mb = Wait-Nova128Mailbox $session -TimeoutSeconds $TimeoutSeconds
  19. $lenAddr = Get-Nova128Label -Labels $labels -Name "golden_len"
  20. $copyAddr = Get-Nova128Label -Labels $labels -Name "golden_copy"
  21. $lenBytes = Read-Nova128Memory -Session $session -Address $lenAddr -Count 1
  22. $goldenLen = [int]$lenBytes[0]
  23. if ($goldenLen -eq 0) { throw "golden_len is zero" }
  24. $golden = Read-Nova128Memory -Session $session -Address $copyAddr -Count $goldenLen
  25. } finally {
  26. Stop-Nova128X128 $session
  27. }
  28. Write-Host ('mailbox: ' + (($mb | ForEach-Object { $_.ToString('X2') }) -join ' '))
  29. Write-Host ("results: byte={0:X2} cmp={1:X2} add={2:X2}{3:X2} sub={4:X2}{5:X2} mul={6:X2} fault={7}" -f `
  30. $mb[8], $mb[9], $mb[11], $mb[10], $mb[13], $mb[12], $mb[14], $mb[15])
  31. $failures = @()
  32. if ($mb[2] -ne 0x03) { $failures += "producer $($mb[2]) is not a generated program" }
  33. if ($mb[3] -ne 0xA5) { $failures += "fixture status is not PASS" }
  34. if ($mb[4] -ne 0 -or $mb[5] -ne 0) { $failures += "code is $($mb[4] + 256 * $mb[5])" }
  35. $want = [ordered]@{
  36. byte = 0x5A
  37. cmp = 0x0E
  38. addLow = 0x21; addHigh = 0x22
  39. subLow = 0xBB; subHigh = 0xEC
  40. mulLow = 0xE0
  41. fault = 1
  42. }
  43. if ($mb[8] -ne $want.byte) { $failures += ('byte assignment is {0:X2}, expected {1:X2}' -f $mb[8], $want.byte) }
  44. if ($mb[9] -ne $want.cmp) { $failures += ('comparisons are {0:X2}, expected {1:X2}' -f $mb[9], $want.cmp) }
  45. if ($mb[10] -ne $want.addLow -or $mb[11] -ne $want.addHigh) {
  46. $failures += ('add is {0:X2}{1:X2}, expected {2:X2}{3:X2}' -f $mb[11], $mb[10], $want.addHigh, $want.addLow)
  47. }
  48. if ($mb[12] -ne $want.subLow -or $mb[13] -ne $want.subHigh) {
  49. $failures += ('sub is {0:X2}{1:X2}, expected {2:X2}{3:X2}' -f $mb[13], $mb[12], $want.subHigh, $want.subLow)
  50. }
  51. if ($mb[14] -ne $want.mulLow) { $failures += ('mul low is {0:X2}, expected {1:X2}' -f $mb[14], $want.mulLow) }
  52. if ($mb[15] -ne $want.fault) { $failures += "fault byte is $($mb[15]), expected 1" }
  53. $binPath = Join-Path $out "scalar.golden.bin"
  54. [IO.File]::WriteAllBytes($binPath, $golden)
  55. $disPath = Join-Path $out "scalar.golden.dis"
  56. $da65 = (Get-Command da65 -ErrorAction Stop).Source
  57. & $da65 --cpu 6502 --start-addr 0000 -o $disPath $binPath 2>&1 | Out-Null
  58. if ($LASTEXITCODE -ne 0) { throw "da65 failed on $binPath" }
  59. # Remove da65's timestamp/path header so the committed listing is stable.
  60. $disLines = Get-Content -LiteralPath $disPath | Where-Object {
  61. $_.Trim() -ne "" -and -not $_.StartsWith(";")
  62. }
  63. [IO.File]::WriteAllText($disPath, (($disLines -join "`n") + "`n"))
  64. $hex = (($golden | ForEach-Object { $_.ToString("X2") }) -join " ") + "`n"
  65. $actualHex = Join-Path $out "scalar.golden.hex"
  66. [IO.File]::WriteAllText($actualHex, $hex)
  67. Write-Host "golden bytes: $goldenLen"
  68. Write-Host "hex: $actualHex"
  69. Write-Host "disassembly: $disPath"
  70. $expectedHexPath = Join-Path $project "tests\codegen\scalar.expected.hex"
  71. if (Test-Path -LiteralPath $expectedHexPath) {
  72. $expectedHex = ([IO.File]::ReadAllText($expectedHexPath)).Trim()
  73. if ($hex.Trim() -ne $expectedHex) {
  74. $failures += "golden bytes differ from tests/codegen/scalar.expected.hex"
  75. }
  76. } else {
  77. Write-Host "no tests/codegen/scalar.expected.hex yet"
  78. }
  79. $expectedDisPath = Join-Path $project "tests\codegen\scalar.expected.dis"
  80. if (Test-Path -LiteralPath $expectedDisPath) {
  81. $expectedDis = ([IO.File]::ReadAllText($expectedDisPath)).Replace("`r`n", "`n").TrimEnd()
  82. $actualDis = ([IO.File]::ReadAllText($disPath)).Replace("`r`n", "`n").TrimEnd()
  83. if ($actualDis -ne $expectedDis) {
  84. $failures += "golden disassembly differs from tests/codegen/scalar.expected.dis"
  85. }
  86. } else {
  87. Write-Host "no tests/codegen/scalar.expected.dis yet"
  88. }
  89. if ($failures) { throw ("scalar verification failed:`n " + ($failures -join "`n ")) }
  90. Write-Host "verified scalar assignments, comparisons, short-circuit, arithmetic, and divide-by-zero"

Powered by TurnKey Linux.