120 lines
3.9 KiB
PowerShell
120 lines
3.9 KiB
PowerShell
<#
|
|
run_boot_test.ps1 - Full automated boot-log capture + verify in one call.
|
|
|
|
Orchestrates:
|
|
1. serial_capture.ps1 (with -FlashCmd): stable-start capture -> flash -> collect
|
|
2. Extract the captured text from the JSON
|
|
3. verify_log.ps1 on the extracted boot log
|
|
|
|
Usage:
|
|
powershell -ExecutionPolicy Bypass -File run_boot_test.ps1 `
|
|
[-Port COM6] [-BaudRate 115200] `
|
|
[-DurationMs 30000] [-InitialTimeoutMs 90000] [-IdleTimeoutMs 8000] `
|
|
[-FlashCmd "D:\...\download.bat"] `
|
|
[-Required "App init OK;Network Init;net init: OK;PHY: 100M FULL"] `
|
|
[-Forbidden "FAIL;ERROR;HardFault"] `
|
|
[-OutDir C:\temp] [-ShowTailLines 15]
|
|
|
|
Exit codes:
|
|
0 = PASS (captured + all required markers + no forbidden)
|
|
1 = FAIL (marker miss / forbidden hit)
|
|
2 = capture or flash error
|
|
3 = verify file error
|
|
|
|
NOTE: ASCII-only on purpose - project source files contain Chinese and must
|
|
never be rewritten by encoding-sensitive PowerShell. Keep this script ASCII.
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
param(
|
|
[string]$Port = "COM6",
|
|
[int]$BaudRate = 115200,
|
|
[int]$DurationMs = 30000,
|
|
[int]$InitialTimeoutMs = 90000,
|
|
[int]$IdleTimeoutMs = 8000,
|
|
[int]$MaxBytes = 65536,
|
|
[string]$FlashCmd = "",
|
|
[string]$Required = "App init OK;Network Init;net init: OK",
|
|
[string]$Forbidden = "FAIL;ERROR;HardFault",
|
|
[string]$OutDir = "$env:TEMP\opencode",
|
|
[int]$ShowTailLines = 15
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$captureScript = Join-Path $scriptDir "serial_capture.ps1"
|
|
$verifyScript = Join-Path $scriptDir "verify_log.ps1"
|
|
|
|
# Default flash command: resolve relative to this script's repo location
|
|
# (the old hardcoded absolute path pointed at a stale checkout location).
|
|
if (-not $FlashCmd) {
|
|
$FlashCmd = Join-Path $scriptDir "..\MDK-ARM\download.bat"
|
|
}
|
|
|
|
if (-not (Test-Path -LiteralPath $captureScript)) {
|
|
Write-Output "RUN_TEST_ERROR: serial_capture.ps1 not found"
|
|
exit 2
|
|
}
|
|
if (-not (Test-Path -LiteralPath $verifyScript)) {
|
|
Write-Output "RUN_TEST_ERROR: verify_log.ps1 not found"
|
|
exit 2
|
|
}
|
|
|
|
if (-not (Test-Path -LiteralPath $OutDir)) {
|
|
New-Item -ItemType Directory -Path $OutDir -Force | Out-Null
|
|
}
|
|
|
|
$stamp = Get-Date -Format "yyyyMMdd_HHmmss"
|
|
$capJson = Join-Path $OutDir "boot_capture_$stamp.json"
|
|
$bootTxt = Join-Path $OutDir "boot_log_$stamp.txt"
|
|
|
|
Write-Output "=== Boot test $stamp ==="
|
|
Write-Output "Capture: $capJson"
|
|
|
|
& $captureScript -OutFile $capJson -Port $Port -BaudRate $BaudRate `
|
|
-DurationMs $DurationMs -InitialTimeoutMs $InitialTimeoutMs `
|
|
-IdleTimeoutMs $IdleTimeoutMs -MaxBytes $MaxBytes `
|
|
-FlashCmd $FlashCmd -MaxRetries 3 -RetryDelayMs 1500
|
|
$capRc = $LASTEXITCODE
|
|
if ($capRc -ne 0) {
|
|
Write-Output "RUN_TEST_ERROR: capture failed (rc=$capRc)"
|
|
exit 2
|
|
}
|
|
|
|
if (-not (Test-Path -LiteralPath $capJson)) {
|
|
Write-Output "RUN_TEST_ERROR: no capture JSON at $capJson"
|
|
exit 2
|
|
}
|
|
|
|
try {
|
|
$json = Get-Content -LiteralPath $capJson -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
} catch {
|
|
Write-Output "RUN_TEST_ERROR: cannot parse capture JSON: $_"
|
|
exit 2
|
|
}
|
|
|
|
if (-not $json.read) {
|
|
Write-Output "RUN_TEST_ERROR: capture JSON has no 'read' object"
|
|
exit 2
|
|
}
|
|
|
|
Write-Output ("Capture: bytes_read={0} completion_reason={1} waited_ms={2} elapsed_ms={3}" -f `
|
|
$json.read.bytes_read, $json.read.completion_reason, $json.read.waited_ms, $json.read.elapsed_ms)
|
|
|
|
$data = [string]$json.read.data
|
|
if ([string]::IsNullOrEmpty($data)) {
|
|
Write-Output "RUN_TEST_ERROR: capture returned no data (device silent?)"
|
|
Write-Output "Hint: raise -InitialTimeoutMs if flashing is slow, or check the device boots."
|
|
exit 2
|
|
}
|
|
|
|
[System.IO.File]::WriteAllText($bootTxt, $data, [System.Text.Encoding]::UTF8)
|
|
Write-Output "Boot log: $bootTxt"
|
|
|
|
& $verifyScript -LogPath $bootTxt -Required $Required -Forbidden $Forbidden `
|
|
-ShowTailLines $ShowTailLines
|
|
$verifyRc = $LASTEXITCODE
|
|
Write-Output "RUN_TEST_RC=$verifyRc"
|
|
exit $verifyRc
|