Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

56 wiersze
2.7KB

  1. # E02-S02: run the C128 lexer over every fixture in x128 and compare its token
  2. # dump with tests/lexer/golden/*.tokens (which the host reference lexer must
  3. # also reproduce; build-lexer-test.ps1 checks that first).
  4. [CmdletBinding()]
  5. param([int]$Port = 6532, [int]$TimeoutSeconds = 180)
  6. $ErrorActionPreference = "Stop"
  7. $project = Split-Path $PSScriptRoot -Parent
  8. Import-Module (Join-Path $PSScriptRoot "lib\Nova128Test.psm1") -Force
  9. . (Join-Path $project "tests\lexer\reference-lexer.ps1")
  10. & (Join-Path $PSScriptRoot "build-lexer-test.ps1")
  11. $out = Join-Path $project "build\lexer-test"
  12. $disk = Join-Path $out "lexer-test.d81"
  13. $screenshot = Join-Path $out "lexer-test-vicii.png"
  14. $names = @("minimal", "decls", "arrays", "exprs", "forward", "nulls", "stmts",
  15. "tokens", "errors", "badchar")
  16. $session = Start-Nova128X128 -Autostart $disk -Drive8Image $disk -Port $Port -Screenshot $screenshot
  17. try {
  18. $mb = Wait-Nova128Mailbox $session -TimeoutSeconds $TimeoutSeconds
  19. $address = $mb[8] + 256 * $mb[9]
  20. $length = $mb[10] + 256 * $mb[11]
  21. $dump = Read-Nova128Memory $session $address $length
  22. } finally {
  23. Stop-Nova128X128 $session
  24. }
  25. [IO.File]::WriteAllBytes((Join-Path $out "lexer-dump.bin"), $dump)
  26. $fixtures = ConvertFrom-TokenDump $dump
  27. $failures = @()
  28. if ($mb[3] -ne 0xA5) { $failures += "C128 reported FAIL (code `$" + $mb[4].ToString("X2") + ")" }
  29. if ($fixtures.Count -ne $names.Count) { $failures += "dump holds $($fixtures.Count) fixtures, expected $($names.Count)" }
  30. for ($i = 0; $i -lt $names.Count; $i++) {
  31. $name = $names[$i]
  32. $golden = (Get-Content -LiteralPath (Join-Path $project "tests\lexer\golden\$name.tokens")) |
  33. Where-Object { $_ -ne "" }
  34. $entry = $fixtures[$i]
  35. if ($null -eq $entry) { $failures += "${name}: missing from dump"; continue }
  36. if ($entry.Load -ne 0) { $failures += "${name}: src_load returned $($entry.Load)"; continue }
  37. $got = @($entry.Tokens)
  38. $diff = Compare-Object -ReferenceObject $golden -DifferenceObject $got -SyncWindow 0
  39. if ($diff) {
  40. $first = 0
  41. while ($first -lt [Math]::Min($golden.Count, $got.Count) -and $golden[$first] -eq $got[$first]) { $first++ }
  42. $failures += ("{0}: token {1} differs: golden '{2}' vs C128 '{3}' ({4} vs {5} tokens)" -f
  43. $name, ($first + 1), $golden[$first], $got[$first], $golden.Count, $got.Count)
  44. Write-Host (" {0,-8} {1,4} tokens FAIL" -f $name, $got.Count)
  45. } else {
  46. Write-Host (" {0,-8} {1,4} tokens match" -f $name, $got.Count)
  47. }
  48. }
  49. if ($failures) { throw ("lexer verification failed:`n " + ($failures -join "`n ")) }
  50. Write-Host ("verified C128 lexer: {0} fixtures, {1} dump bytes, all tokens match golden files" -f $names.Count, $length)
  51. Write-Host "screenshot: $screenshot"

Powered by TurnKey Linux.