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.

159 linhas
8.5KB

  1. <#
  2. .SYNOPSIS
  3. Build each target, run it headless in VICE, and check that the expected screen appears.
  4. .DESCRIPTION
  5. For every target in project.json (resolved.targets) that has a "smoke" section:
  6. 1. builds the artifact (and disk image, if any);
  7. 2. starts VICE minimized, in warp mode, with sound off and a private config file,
  8. so your own VICE settings are never read or changed;
  9. 3. sets non-stopping monitor tracepoints on the program's "ready" point. When the
  10. program reaches it, VICE saves the listed memory ranges (screen RAM, a VDC probe,
  11. mode flags) to build/smoke/<target>/*.bin;
  12. 4. lets VICE quit after a fixed number of cycles (-limitcycles) and saves a screenshot;
  13. 5. compares the saved memory with the expected text and bytes.
  14. Exit codes: 0 = all automated checks passed, 1 = a check failed, 2 = a tool is missing,
  15. 3 = nothing automated to run (manual verification only).
  16. .EXAMPLE
  17. pwsh -File tools/smoke.ps1
  18. pwsh -File tools/smoke.ps1 -Target c64
  19. #>
  20. [CmdletBinding()]
  21. param(
  22. [string]$Target,
  23. [switch]$NoBuild,
  24. [int]$TimeoutSeconds = 180
  25. )
  26. . (Join-Path $PSScriptRoot 'lib.ps1')
  27. function Resolve-SmokeAddress([hashtable]$Target, [string]$Symbol, [string]$Address) {
  28. if ($Address) { return [Convert]::ToInt32($Address, 16) }
  29. $labels = Get-RepoPath $Target.build.labels
  30. if (-not (Test-Path -LiteralPath $labels)) { throw "Label file $($Target.build.labels) not found; cannot resolve symbol '$Symbol'." }
  31. foreach ($line in Get-Content -LiteralPath $labels) {
  32. $parts = $line -split '\s+'
  33. if ($parts.Count -ge 3 -and $parts[2].TrimStart('.') -eq $Symbol.TrimStart('.')) { return [Convert]::ToInt32($parts[1], 16) }
  34. }
  35. throw "Symbol '$Symbol' not found in $($Target.build.labels). Keep the smoke hook in the source (see AGENTS.md)."
  36. }
  37. function ConvertFrom-ScreenCodes([byte[]]$Codes, [string]$Encoding) {
  38. $chars = foreach ($b in $Codes) {
  39. $c = $b -band 0x7F
  40. if ($c -eq 0) { '@' }
  41. elseif ($c -ge 1 -and $c -le 26) { if ($Encoding -eq 'screen-mixed') { [char](0x60 + $c) } else { [char](0x40 + $c) } }
  42. elseif ($c -ge 0x1B -and $c -le 0x1F) { [char](0x40 + $c) }
  43. elseif ($c -ge 0x20 -and $c -le 0x3F) { [char]$c }
  44. elseif ($c -ge 0x41 -and $c -le 0x5A -and $Encoding -eq 'screen-mixed') { [char]$c }
  45. else { '.' }
  46. }
  47. -join $chars
  48. }
  49. function Invoke-TargetSmoke([hashtable]$Project, [hashtable]$Target) {
  50. $smoke = $Target.smoke
  51. $dir = Get-RepoPath "build/smoke/$($Target.id)"
  52. if (Test-Path -LiteralPath $dir) { Remove-Item -LiteralPath $dir -Recurse -Force }
  53. New-Item -ItemType Directory -Force -Path $dir | Out-Null
  54. $readyAddr = Resolve-SmokeAddress $Target $smoke.ready.symbol $smoke.ready.address
  55. $mon = [System.Collections.Generic.List[string]]::new()
  56. $n = 0
  57. foreach ($d in @($smoke.dumps)) {
  58. $n++
  59. $start = Resolve-SmokeAddress $Target $d.symbol $d.address
  60. $end = $start + [int]$d.length - 1
  61. $mon.Add(('trace {0} ${1:x4}' -f $smoke.ready.kind, $readyAddr))
  62. $mon.Add(('command {0} "bsave \"{1}.bin\" 0 {2:x4} {3:x4}"' -f $n, $d.name, $start, $end))
  63. }
  64. Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value $mon
  65. Set-Content -LiteralPath (Join-Path $dir 'vicerc') -Value ''
  66. $emu = Get-ToolPath $Project $Target.emulator.binary
  67. $vargs = @('-config', 'vicerc', '-default', '-sounddev', 'dummy', '-warp', '-minimized') + (Get-VideoArgs $Target) + @($Target.emulator.args)
  68. $vargs += @('-limitcycles', [string]$smoke.limitCycles, '-exitscreenshot', 'screen.png')
  69. if ($Target.emulator.binary -eq 'x128') { $vargs += @('-exitscreenshotvicii', 'vicii.png') }
  70. $vargs += @('-moncommands', 'monitor.txt')
  71. if ($Target.emulator.autostart -eq 'disk') {
  72. $vargs += @('-autostart', (Get-AutostartFile $Target))
  73. } else {
  74. if ($Target.disk) { $vargs += @('-8', (Get-RepoPath $Target.disk.image)) }
  75. $vargs += @('-autostartprgmode', '1', '-autostart', (Get-AutostartFile $Target))
  76. }
  77. $quoted = $vargs | ForEach-Object { if ($_ -match '[\s"]') { '"' + ($_ -replace '"', '\"') + '"' } else { $_ } }
  78. Set-Content -LiteralPath (Join-Path $dir 'command.txt') -Value ("`"$emu`" " + ($quoted -join ' '))
  79. Write-Host "[$($Target.id)] running $($Target.emulator.binary) headless (limit $($smoke.limitCycles) cycles)"
  80. $sw = [Diagnostics.Stopwatch]::StartNew()
  81. $p = Start-Process -FilePath $emu -ArgumentList $quoted -WorkingDirectory $dir -PassThru `
  82. -RedirectStandardOutput (Join-Path $dir 'vice.log') -RedirectStandardError (Join-Path $dir 'vice.err')
  83. if (-not $p.WaitForExit($TimeoutSeconds * 1000)) {
  84. $p.Kill($true)
  85. return @{ target = $Target.id; status = 'FAIL'; seconds = [int]$sw.Elapsed.TotalSeconds; checks = @(); message = "VICE did not exit within $TimeoutSeconds s (killed)." }
  86. }
  87. $checks = @()
  88. $reached = @($smoke.dumps | Where-Object { Test-Path -LiteralPath (Join-Path $dir "$($_.name).bin") }).Count -gt 0
  89. if (-not $reached) {
  90. $where = if ($smoke.ready.symbol) { "symbol $($smoke.ready.symbol)" } else { "store to `$$($smoke.ready.address)" }
  91. return @{ target = $Target.id; status = 'FAIL'; seconds = [int]$sw.Elapsed.TotalSeconds; checks = @(); message = "Program never reached its ready point ($where) within $($smoke.limitCycles) cycles. See build/smoke/$($Target.id)/vice.log and screen.png." }
  92. }
  93. foreach ($c in @($smoke.checks)) {
  94. $file = Join-Path $dir "$($c.dump).bin"
  95. $result = @{ description = $c.description; pass = $false; detail = '' }
  96. if (-not (Test-Path -LiteralPath $file)) { $result.detail = "dump '$($c.dump)' missing"; $checks += $result; continue }
  97. $data = [IO.File]::ReadAllBytes($file)
  98. $expected = if ($null -ne $c.text) { ConvertTo-ScreenCodes $c.text $c.encoding } else { [byte[]]($c.bytes -split '\s+' | Where-Object { $_ } | ForEach-Object { [Convert]::ToByte($_, 16) }) }
  99. $offset = [int]$c.offset
  100. if ($offset + $expected.Length -gt $data.Length) { $result.detail = "dump '$($c.dump)' too short"; $checks += $result; continue }
  101. $actual = [byte[]]$data[$offset..($offset + $expected.Length - 1)]
  102. $result.pass = ((Format-Hex $actual) -eq (Format-Hex $expected))
  103. if ($null -ne $c.text) {
  104. $result.detail = "expected '$($c.text)', found '$(ConvertFrom-ScreenCodes $actual $c.encoding)'"
  105. } else {
  106. $result.detail = "expected $(Format-Hex $expected), found $(Format-Hex $actual)"
  107. }
  108. $checks += $result
  109. }
  110. $status = if (@($checks | Where-Object { -not $_.pass }).Count -eq 0) { 'PASS' } else { 'FAIL' }
  111. $shots = @('screen.png', 'vicii.png') | Where-Object { Test-Path -LiteralPath (Join-Path $dir $_) } | ForEach-Object { "build/smoke/$($Target.id)/$_" }
  112. @{ target = $Target.id; status = $status; seconds = [int]$sw.Elapsed.TotalSeconds; checks = $checks; screenshots = @($shots); message = $smoke.expectedScreen }
  113. }
  114. $exitCode = 0
  115. try {
  116. $project = Get-ProjectConfig
  117. $targets = Get-ProjectTargets $project $Target
  118. $done = @{}
  119. $results = @()
  120. foreach ($t in $targets) {
  121. if (-not $NoBuild) { Invoke-TargetBuild $project $t $done }
  122. if (-not $t.smoke) {
  123. $results += @{ target = $t.id; status = 'MANUAL'; checks = @(); message = 'No automated smoke check for this target; follow docs/manual-tests.md (M0).' }
  124. continue
  125. }
  126. $results += Invoke-TargetSmoke $project $t
  127. }
  128. } catch [MissingToolException] {
  129. Write-Host ""
  130. Write-Host $_.Exception.Message -ForegroundColor Yellow
  131. exit 2
  132. }
  133. Write-Host ""
  134. Write-Host "Smoke results"
  135. foreach ($r in $results) {
  136. $color = switch ($r.status) { 'PASS' { 'Green' } 'FAIL' { 'Red' } default { 'Yellow' } }
  137. Write-Host (" [{0}] {1}" -f $r.status, $r.target) -ForegroundColor $color
  138. foreach ($c in @($r.checks)) { Write-Host (" {0} {1}: {2}" -f ($(if ($c.pass) { 'ok ' } else { 'FAIL' })), $c.description, $c.detail) }
  139. if ($r.ContainsKey('screenshots') -and $r.screenshots) { Write-Host (" screenshot: {0}" -f ($r.screenshots -join ', ')) }
  140. if ($r.message) { Write-Host " $($r.message)" }
  141. }
  142. New-Item -ItemType Directory -Force -Path (Get-RepoPath 'build/smoke') | Out-Null
  143. $results | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath (Get-RepoPath 'build/smoke/results.json')
  144. if (@($results | Where-Object { $_.status -eq 'FAIL' }).Count -gt 0) { $exitCode = 1 }
  145. elseif (@($results | Where-Object { $_.status -eq 'PASS' }).Count -eq 0) { $exitCode = 3 }
  146. exit $exitCode

Powered by TurnKey Linux.