|
|
@@ -338,7 +338,7 @@ function Read-PortAvailableBytes($Serial, [System.Collections.Generic.List[byte]
|
|
|
try {
|
|
|
$available = $Serial.BytesToRead
|
|
|
if ($available -le 0) {
|
|
|
- return
|
|
|
+ return 0
|
|
|
}
|
|
|
$buffer = New-Object byte[] $available
|
|
|
$read = $Serial.Read($buffer, 0, $available)
|
|
|
@@ -366,11 +366,127 @@ function Read-PortAvailableBytes($Serial, [System.Collections.Generic.List[byte]
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ return $read
|
|
|
} catch [System.TimeoutException] {
|
|
|
- return
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function Test-J6RawEventChecksum($Event) {
|
|
|
+ if ($null -eq $Event -or -not ($Event -is [System.Collections.IDictionary]) -or $Event.kind -ne "j6raw") {
|
|
|
+ return $false
|
|
|
+ }
|
|
|
+ if (-not $Event.fields.Contains("data")) {
|
|
|
+ return $false
|
|
|
+ }
|
|
|
+ $dataHex = [string]$Event.fields.data
|
|
|
+ if ($dataHex -notmatch '^[0-9A-Fa-f]*$' -or (($dataHex.Length % 2) -ne 0)) {
|
|
|
+ return $false
|
|
|
+ }
|
|
|
+ $chunk = Convert-HexToBytes $dataHex
|
|
|
+ if ($Event.fields.Contains("len") -and [int64]$Event.fields.len -ne $chunk.Length) {
|
|
|
+ return $false
|
|
|
+ }
|
|
|
+ if ($Event.fields.Contains("sum")) {
|
|
|
+ $actualSum = [int64]0
|
|
|
+ foreach ($byte in $chunk) {
|
|
|
+ $actualSum = ($actualSum + [int64]$byte) -band 0xFFFF
|
|
|
+ }
|
|
|
+ if ([int64]$Event.fields.sum -ne $actualSum) {
|
|
|
+ return $false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $true
|
|
|
+}
|
|
|
+
|
|
|
+function Get-DebugTailSummary([System.Collections.Generic.List[object]]$Events, [string]$PendingLine, [bool]$FinalLineTerminated, [bool]$TailDrainTimedOut, [int]$TailDrainBytes, [int]$TailDrainMs, [int]$QuietMs) {
|
|
|
+ $lastRawEndOffset = $null
|
|
|
+ $lastRawLineIndex = $null
|
|
|
+ $lastStatRawIn = $null
|
|
|
+ $lastStatRawOut = $null
|
|
|
+ $lastStatLineIndex = $null
|
|
|
+ for ($i = 0; $i -lt $Events.Count; $i++) {
|
|
|
+ $event = $Events[$i]
|
|
|
+ if ($event.kind -eq "j6raw" -and $event.fields.Contains("off") -and $event.fields.Contains("len")) {
|
|
|
+ $lastRawEndOffset = [int64]$event.fields.off + [int64]$event.fields.len
|
|
|
+ $lastRawLineIndex = $i
|
|
|
+ } elseif ($event.kind -eq "j6stat") {
|
|
|
+ if ($event.fields.Contains("raw_in")) { $lastStatRawIn = [int64]$event.fields.raw_in }
|
|
|
+ if ($event.fields.Contains("raw_out")) { $lastStatRawOut = [int64]$event.fields.raw_out }
|
|
|
+ $lastStatLineIndex = $i
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $watermark = $null
|
|
|
+ if ($null -ne $lastStatRawIn -and $null -ne $lastStatRawOut) {
|
|
|
+ $watermark = [Math]::Min($lastStatRawIn, $lastStatRawOut)
|
|
|
+ } elseif ($null -ne $lastStatRawIn) {
|
|
|
+ $watermark = $lastStatRawIn
|
|
|
+ } elseif ($null -ne $lastStatRawOut) {
|
|
|
+ $watermark = $lastStatRawOut
|
|
|
+ }
|
|
|
+ $postTailBytes = 0
|
|
|
+ if ($null -ne $lastRawEndOffset -and $null -ne $watermark -and $lastRawEndOffset -gt $watermark) {
|
|
|
+ $postTailBytes = [int64]($lastRawEndOffset - $watermark)
|
|
|
+ }
|
|
|
+ $coversReplay = ($null -ne $lastRawEndOffset -and $null -ne $watermark -and $watermark -ge $lastRawEndOffset)
|
|
|
+ return [ordered]@{
|
|
|
+ tail_drain_timeout = $TailDrainTimedOut
|
|
|
+ tail_drain_bytes = $TailDrainBytes
|
|
|
+ tail_drain_ms = $TailDrainMs
|
|
|
+ tail_quiet_ms = $QuietMs
|
|
|
+ final_line_terminated = $FinalLineTerminated
|
|
|
+ incomplete_final_line = if ($FinalLineTerminated) { "" } else { $PendingLine }
|
|
|
+ last_j6raw_end_offset = $lastRawEndOffset
|
|
|
+ last_j6raw_event_index = $lastRawLineIndex
|
|
|
+ last_j6stat_raw_in = $lastStatRawIn
|
|
|
+ last_j6stat_raw_out = $lastStatRawOut
|
|
|
+ last_j6stat_event_index = $lastStatLineIndex
|
|
|
+ post_j6stat_tail_bytes = $postTailBytes
|
|
|
+ last_j6stat_covers_replay = $coversReplay
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function Complete-DebugPendingLine([System.Text.StringBuilder]$DebugAsciiWindow, [System.Collections.Generic.List[object]]$DebugEvents, [string[]]$Prefixes) {
|
|
|
+ if ($DebugAsciiWindow.Length -le 0) {
|
|
|
+ return [ordered]@{ pending_line = ""; complete_frame_added = $false; incomplete_final_line = ""; final_line_terminated = $true }
|
|
|
+ }
|
|
|
+ $pending = $DebugAsciiWindow.ToString()
|
|
|
+ $event = Convert-FrameLine $pending $Prefixes
|
|
|
+ if ($null -ne $event -and $event.kind -eq "j6raw" -and (Test-J6RawEventChecksum $event)) {
|
|
|
+ $event["line_terminated"] = $false
|
|
|
+ $event["parse_status"] = "pass_unterminated_eof"
|
|
|
+ $DebugEvents.Add($event) | Out-Null
|
|
|
+ [void]$DebugAsciiWindow.Clear()
|
|
|
+ return [ordered]@{ pending_line = $pending; complete_frame_added = $true; incomplete_final_line = ""; final_line_terminated = $false }
|
|
|
+ }
|
|
|
+ return [ordered]@{ pending_line = $pending; complete_frame_added = $false; incomplete_final_line = $pending; final_line_terminated = $false }
|
|
|
+}
|
|
|
+
|
|
|
+function Invoke-DebugTailDrain($DebugSerial, [System.Collections.Generic.List[byte]]$DebugRaw, [System.Text.StringBuilder]$DebugAsciiWindow, [System.Collections.Generic.List[object]]$DebugEvents, [int]$MaxMs = 3000, [int]$QuietMs = 350) {
|
|
|
+ $prefixes = @("J6READY", "J6CMD", "J6RAW", "J6EVT", "J6PWM", "J6MOD", "J6STAT", "J6MAP", "J6TEMP")
|
|
|
+ $startedAt = (Get-Date).ToUniversalTime()
|
|
|
+ $deadline = $startedAt.AddMilliseconds($MaxMs)
|
|
|
+ $lastByteAt = $startedAt
|
|
|
+ $bytesRead = 0
|
|
|
+ while ((Get-Date).ToUniversalTime() -lt $deadline) {
|
|
|
+ $read = Read-PortAvailableBytes $DebugSerial $DebugRaw $DebugAsciiWindow $DebugEvents $prefixes
|
|
|
+ if ($read -gt 0) {
|
|
|
+ $bytesRead += $read
|
|
|
+ $lastByteAt = (Get-Date).ToUniversalTime()
|
|
|
+ } elseif (((Get-Date).ToUniversalTime() - $lastByteAt).TotalMilliseconds -ge $QuietMs) {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ Start-Sleep -Milliseconds 20
|
|
|
+ }
|
|
|
+ $completedAt = (Get-Date).ToUniversalTime()
|
|
|
+ $pending = Complete-DebugPendingLine $DebugAsciiWindow $DebugEvents $prefixes
|
|
|
+ $timedOut = ($completedAt -ge $deadline)
|
|
|
+ $summary = Get-DebugTailSummary $DebugEvents ([string]$pending.incomplete_final_line) ([bool]$pending.final_line_terminated) $timedOut $bytesRead ([int](($completedAt - $startedAt).TotalMilliseconds)) $QuietMs
|
|
|
+ $summary["complete_unterminated_frame_added"] = [bool]$pending.complete_frame_added
|
|
|
+ $summary["pending_line_before_eof"] = [string]$pending.pending_line
|
|
|
+ return $summary
|
|
|
+}
|
|
|
+
|
|
|
function Get-ExpectedAckCmd([string]$Command) {
|
|
|
if ($Command -match '^SET PTC ') { return "PTCCH" }
|
|
|
if ($Command -match '^SET FAN ') { return "FANCH" }
|
|
|
@@ -660,7 +776,7 @@ function Invoke-StartupPreflight($HostSerial, $DebugSerial, [System.Collections.
|
|
|
|
|
|
while ((Get-Date).ToUniversalTime() -lt $deadline -and (-not ([bool]$preflight.ready_seen -and [bool]$preflight.j6ready_seen))) {
|
|
|
Read-HostPortAvailableLines $HostSerial $HostRaw $HostAsciiWindow $HostReports $AckQueue @("READY", "SENS", "DIMM", "STAT", "PWM", "PID")
|
|
|
- Read-PortAvailableBytes $DebugSerial $DebugRaw $DebugAsciiWindow $DebugEvents @("J6READY", "J6CMD", "J6RAW", "J6EVT", "J6PWM", "J6MOD", "J6STAT", "J6MAP", "J6TEMP")
|
|
|
+ $null = Read-PortAvailableBytes $DebugSerial $DebugRaw $DebugAsciiWindow $DebugEvents @("J6READY", "J6CMD", "J6RAW", "J6EVT", "J6PWM", "J6MOD", "J6STAT", "J6MAP", "J6TEMP")
|
|
|
|
|
|
while ($AckQueue.Count -gt 0) {
|
|
|
$ack = $AckQueue.Dequeue()
|
|
|
@@ -729,6 +845,27 @@ function Invoke-CollectorSelfTest {
|
|
|
$rawEvents.Add((Convert-FrameLine "J6RAW s=0001 o=00000000 l=04 u=000A d=01020304" @("J6READY", "J6RAW"))) | Out-Null
|
|
|
$rawReplay = New-BmcRawReplay $rawEvents
|
|
|
if ($rawReplay.Length -ne 4 -or $rawReplay[0] -ne 1 -or $rawReplay[3] -ne 4) { throw "post_j6ready_raw_replay failed" }
|
|
|
+ $tailEvents = New-Object System.Collections.Generic.List[object]
|
|
|
+ $tailEvents.Add((Convert-FrameLine "J6READY profile=temp-uart-ptc-remap" @("J6READY", "J6RAW", "J6STAT"))) | Out-Null
|
|
|
+ $tailEvents.Add((Convert-FrameLine "J6RAW s=0001 o=00000000 l=04 u=000A d=01020304" @("J6READY", "J6RAW", "J6STAT"))) | Out-Null
|
|
|
+ $tailEvents.Add((Convert-FrameLine "J6STAT ri=00000004 ro=00000004 rd=00 hd=00 be=00 he=00" @("J6READY", "J6RAW", "J6STAT"))) | Out-Null
|
|
|
+ $tailEvents.Add((Convert-FrameLine "J6RAW s=0002 o=00000004 l=04 u=0220 d=AA55BB66" @("J6READY", "J6RAW", "J6STAT"))) | Out-Null
|
|
|
+ $tailSummary = Get-DebugTailSummary $tailEvents "J6RAW s=0004" $false $false 0 0 350
|
|
|
+ if ([int64]$tailSummary.post_j6stat_tail_bytes -ne 4) { throw "post_j6stat_tail_bytes failed: $($tailSummary.post_j6stat_tail_bytes)" }
|
|
|
+ if ([bool]$tailSummary.last_j6stat_covers_replay) { throw "last_j6stat_covers_replay should be false" }
|
|
|
+ if ([string]$tailSummary.incomplete_final_line -ne "J6RAW s=0004") { throw "incomplete_final_line failed" }
|
|
|
+ $pendingWindow = New-Object System.Text.StringBuilder
|
|
|
+ [void]$pendingWindow.Append("J6RAW s=0003 o=00000008 l=04 u=000A d=01020304")
|
|
|
+ $pendingEvents = New-Object System.Collections.Generic.List[object]
|
|
|
+ $pending = Complete-DebugPendingLine $pendingWindow $pendingEvents @("J6RAW")
|
|
|
+ if (-not [bool]$pending.complete_frame_added) { throw "complete_unterminated_j6raw failed" }
|
|
|
+ if ($pendingEvents.Count -ne 1 -or -not (Test-J6RawEventChecksum $pendingEvents[0])) { throw "complete_unterminated_j6raw checksum failed" }
|
|
|
+ $incompleteWindow = New-Object System.Text.StringBuilder
|
|
|
+ [void]$incompleteWindow.Append("J6RAW s=0004")
|
|
|
+ $incompleteEvents = New-Object System.Collections.Generic.List[object]
|
|
|
+ $incomplete = Complete-DebugPendingLine $incompleteWindow $incompleteEvents @("J6RAW")
|
|
|
+ if ([bool]$incomplete.complete_frame_added) { throw "incomplete final line was promoted" }
|
|
|
+ if ([string]$incomplete.incomplete_final_line -ne "J6RAW s=0004") { throw "incomplete final line text failed" }
|
|
|
Write-Host "selftest=pass"
|
|
|
Write-Host "ready_line=READY profile=temp-uart-ptc-remap seq=00000000"
|
|
|
Write-Host "j6ready_line=J6READY profile=temp-uart-ptc-remap"
|
|
|
@@ -737,6 +874,10 @@ function Invoke-CollectorSelfTest {
|
|
|
Write-Host "post_j6ready_raw_replay=pass"
|
|
|
Write-Host "formal_ack=OK seq=00000001 cmd=PTCCH"
|
|
|
Write-Host "stale_ack_isolated=pass"
|
|
|
+ Write-Host "tail_drain=pass"
|
|
|
+ Write-Host "post_j6stat_tail_bytes=04"
|
|
|
+ Write-Host "complete_unterminated_j6raw=pass"
|
|
|
+ Write-Host "incomplete_final_line=J6RAW s=0004"
|
|
|
}
|
|
|
|
|
|
function Get-SensEventCount([System.Collections.Generic.List[object]]$HostReports) {
|
|
|
@@ -948,7 +1089,7 @@ try {
|
|
|
if ($command -eq "GET SENSOR" -and [string]$ack.class -eq "ok" -and [bool]$ack.seq_match -and [bool]$ack.cmd_match) {
|
|
|
$sensor_sample_seen = Wait-HostSensorSample $hostSerial $hostRaw $hostAsciiWindow $hostReportEvents $hostAckQueue $sensBefore 4000
|
|
|
}
|
|
|
- Read-PortAvailableBytes $debugSerial $debugRaw $debugAsciiWindow $debugEvents @("J6READY", "J6CMD", "J6RAW", "J6EVT", "J6PWM", "J6MOD", "J6STAT", "J6MAP", "J6TEMP")
|
|
|
+ $null = Read-PortAvailableBytes $debugSerial $debugRaw $debugAsciiWindow $debugEvents @("J6READY", "J6CMD", "J6RAW", "J6EVT", "J6PWM", "J6MOD", "J6STAT", "J6MAP", "J6TEMP")
|
|
|
$hostCommandEvents.Add([ordered]@{
|
|
|
seq = $seq
|
|
|
timestamp = $writtenAt.ToString("o")
|
|
|
@@ -980,9 +1121,10 @@ try {
|
|
|
|
|
|
while ((Get-Date).ToUniversalTime() -lt $deadline) {
|
|
|
Read-HostPortAvailableLines $hostSerial $hostRaw $hostAsciiWindow $hostReportEvents $hostAckQueue @("READY", "SENS", "DIMM", "STAT", "PWM", "PID")
|
|
|
- Read-PortAvailableBytes $debugSerial $debugRaw $debugAsciiWindow $debugEvents @("J6READY", "J6CMD", "J6RAW", "J6EVT", "J6PWM", "J6MOD", "J6STAT", "J6MAP", "J6TEMP")
|
|
|
+ $null = Read-PortAvailableBytes $debugSerial $debugRaw $debugAsciiWindow $debugEvents @("J6READY", "J6CMD", "J6RAW", "J6EVT", "J6PWM", "J6MOD", "J6STAT", "J6MAP", "J6TEMP")
|
|
|
Start-Sleep -Milliseconds 20
|
|
|
}
|
|
|
+ $debugTail = Invoke-DebugTailDrain $debugSerial $debugRaw $debugAsciiWindow $debugEvents
|
|
|
} finally {
|
|
|
if ($hostSerial.IsOpen) {
|
|
|
$hostSerial.DtrEnable = $false
|
|
|
@@ -999,6 +1141,9 @@ try {
|
|
|
}
|
|
|
|
|
|
$end = (Get-Date).ToUniversalTime()
|
|
|
+if ($null -eq $debugTail) {
|
|
|
+ $debugTail = Get-DebugTailSummary $debugEvents $debugAsciiWindow.ToString() ($debugAsciiWindow.Length -eq 0) $false 0 0 0
|
|
|
+}
|
|
|
$hostRawArray = $hostRaw.ToArray()
|
|
|
$debugRawArray = $debugRaw.ToArray()
|
|
|
$rawReplayArray = New-BmcRawReplay $debugEvents
|
|
|
@@ -1085,6 +1230,7 @@ $debugFrameStream = [ordered]@{
|
|
|
host_report_drop = $hostReportDrop
|
|
|
bmc_berr = $bmcBerr
|
|
|
host_err = $hostErr
|
|
|
+ tail = $debugTail
|
|
|
}
|
|
|
Write-JsonFile $debugFrameStream $debugFrameStreamPath
|
|
|
|
|
|
@@ -1155,6 +1301,7 @@ $manifest = [ordered]@{
|
|
|
enumerates_com_ports = $false
|
|
|
opens_unknown_com_ports = $false
|
|
|
duration_s = $DurationSeconds
|
|
|
+ debug_tail = $debugTail
|
|
|
pin_profile_name = $Profile
|
|
|
pin_profile = $pinMap
|
|
|
status = $captureStatus
|
|
|
@@ -1252,6 +1399,7 @@ $receipt = [ordered]@{
|
|
|
debug_frame_stream = [ordered]@{ path = "debug-frame-stream.json"; sha256 = $debugFrameHash }
|
|
|
manifest = [ordered]@{ path = "j6-host-sensor-real-fan-ptc-capture-manifest.json"; sha256 = $manifestHash }
|
|
|
startup_preflight = [ordered]@{ path = "startup-preflight.json"; sha256 = $startupPreflightHash }
|
|
|
+ tail = $debugTail
|
|
|
}
|
|
|
bmc_raw_sampling = [ordered]@{ status = if ($bmcTimeout) { "blocked_bmc_timeout" } else { "pass" }; minimum_completed_samples = 3; completed_samples = $sampleCount; bmc_timeout = $bmcTimeout }
|
|
|
pid_boundary = [ordered]@{ status = "pass"; pid_requested = ($pidRequested -ne 0); pid_requested_ever = $pidRequestedEver; pid_active = ($pidActive -ne 0); pwm_source = "host_manual" }
|
|
|
@@ -1287,7 +1435,7 @@ $receipt = [ordered]@{
|
|
|
qualifies_final_gate = $false
|
|
|
}
|
|
|
artifact_hashes = [ordered]@{
|
|
|
- status = if ($receiptStatus -eq "pass") { "pass" } else { $receiptStatus }
|
|
|
+ status = "pass"
|
|
|
bitstream_sha256 = $bitstreamRef.sha256
|
|
|
td_receipt_sha256 = $tdReceiptRef.sha256
|
|
|
manual_sram_attestation_sha256 = $manualSramRef.sha256
|