Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

101 строка
4.3KB

  1. # E07-S02 integration checks for scripts/launch-editor.ps1 and
  2. # scripts/launch-compiler.ps1.
  3. [CmdletBinding()]
  4. param()
  5. $ErrorActionPreference = "Stop"
  6. $project = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
  7. $repository = Split-Path $project -Parent
  8. $launchEditor = Join-Path $project "scripts\launch-editor.ps1"
  9. $launchCompiler = Join-Path $project "scripts\launch-compiler.ps1"
  10. $modulePath = Join-Path $project "scripts\lib\Nova128Launcher.psm1"
  11. $source = Join-Path $repository "vim\vim-improved.d81"
  12. $minimal = Join-Path $project "build\minimal.prg"
  13. $testRoot = Join-Path $project "build\launcher-test"
  14. $diskA = Join-Path $testRoot "editor.d81"
  15. $diskB = Join-Path $testRoot "compiler.d81"
  16. $editorShot = Join-Path $testRoot "editor.png"
  17. $compilerShot = Join-Path $testRoot "compiler.png"
  18. foreach ($path in @($launchEditor, $launchCompiler, $modulePath)) {
  19. if (-not (Test-Path -LiteralPath $path -PathType Leaf)) { throw "missing $path" }
  20. }
  21. if (-not (Test-Path -LiteralPath $source -PathType Leaf)) { throw "source image missing: $source" }
  22. New-Item -ItemType Directory -Force -Path $testRoot | Out-Null
  23. & (Join-Path $project "scripts\build-minimal.ps1") | Out-Host
  24. if (-not (Test-Path -LiteralPath $minimal -PathType Leaf)) { throw "minimal PRG missing" }
  25. Import-Module $modulePath -Force
  26. function Assert-FailsWith {
  27. param(
  28. [Parameter(Mandatory = $true)][scriptblock]$Action,
  29. [Parameter(Mandatory = $true)][string]$Pattern
  30. )
  31. $caught = $null
  32. try { & $Action } catch { $caught = $_.Exception.Message }
  33. if ($null -eq $caught) { throw "expected failure matching '$Pattern', but it succeeded" }
  34. if ($caught -notmatch $Pattern) { throw "failure '$caught' did not match '$Pattern'" }
  35. }
  36. $sourceHashBefore = (Get-FileHash -LiteralPath $source -Algorithm SHA256).Hash
  37. # 1: missing inputs are reported before any emulator starts.
  38. Assert-FailsWith -Pattern 'editor program not found' -Action {
  39. & $launchEditor -EditorPrg (Join-Path $testRoot "missing.prg") `
  40. -SourceImage $source -DiskImage $diskA
  41. }
  42. Assert-FailsWith -Pattern 'compiler program not found' -Action {
  43. & $launchCompiler -CompilerPrg (Join-Path $testRoot "missing.prg") `
  44. -DiskImage $diskB -SkipPrepare
  45. }
  46. # 2: an editor session owns the image for the duration; a live lock blocks the
  47. # compiler launcher on the same folder.
  48. Copy-Item -LiteralPath $source -Destination $diskA -Force
  49. $held = Enter-Nova128ImageSession -Image $diskA -Kind "editor"
  50. try {
  51. Assert-FailsWith -Pattern 'still owns|already holds' -Action {
  52. & $launchCompiler -CompilerPrg $minimal -DiskImage $diskA -SkipPrepare
  53. }
  54. } finally {
  55. Exit-Nova128ImageSession -Session $held
  56. }
  57. if (Test-Path -LiteralPath (Join-Path $testRoot ".newlang-session.lock")) {
  58. throw "the session lock was not released"
  59. }
  60. # 3: flush waiting refuses a locked image and accepts a released one.
  61. $partner = [IO.File]::Open($diskA, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::None)
  62. try {
  63. Assert-FailsWith -Pattern 'still locked' -Action {
  64. Wait-Nova128ImageFlush -Image $diskA -TimeoutSeconds 1
  65. }
  66. } finally {
  67. $partner.Dispose()
  68. }
  69. Wait-Nova128ImageFlush -Image $diskA -TimeoutSeconds 2
  70. # 4: the editor launcher autostarts its program in x64sc on a fresh copy and
  71. # returns only after the process exits and the image flushes.
  72. & $launchEditor -EditorPrg $minimal -SourceImage $source -DiskImage $diskA `
  73. -LimitCycles 2000000 -Screenshot $editorShot -Warp
  74. if (-not (Test-Path -LiteralPath $editorShot)) { throw "editor launcher produced no screenshot" }
  75. # 5: the compiler launcher autostarts its program in x128 and leaves the
  76. # disposable image flushed and unlocked.
  77. Copy-Item -LiteralPath $source -Destination $diskB -Force
  78. & $launchCompiler -CompilerPrg $minimal -DiskImage $diskB -LimitCycles 2000000 `
  79. -Screenshot $compilerShot -Warp -SkipPrepare
  80. if (-not (Test-Path -LiteralPath $compilerShot)) { throw "compiler launcher produced no screenshot" }
  81. Wait-Nova128ImageFlush -Image $diskB -TimeoutSeconds 2
  82. $sourceHashAfter = (Get-FileHash -LiteralPath $source -Algorithm SHA256).Hash
  83. if ($sourceHashAfter -ne $sourceHashBefore) { throw "the Vim source image changed during the session tests" }
  84. Write-Host "launcher tests passed"
  85. Write-Host "editor disk copy, lock refusal, flush wait, x64sc autostart, x128 autostart"
  86. Write-Host "source disk unchanged: $sourceHashAfter"

Powered by TurnKey Linux.