| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788 |
- #!/usr/bin/env python3
- """Remote collector and package tests for the converged CPLD project."""
- from __future__ import annotations
- import json
- import shutil
- import subprocess
- import tempfile
- import unittest
- from pathlib import Path
- ROOT = Path(__file__).resolve().parents[2]
- class RemoteScriptTests(unittest.TestCase):
- def test_remote_tools_only_expose_latest_real_fan_ptc_collector(self) -> None:
- scripts = sorted(path.name for path in (ROOT / "tools" / "remote").glob("*.ps1"))
- self.assertEqual(scripts, ["collect-j6-host-sensor-real-fan-ptc.ps1"])
- self.assertFalse((ROOT / "tools" / "serial_debug_capture.py").exists())
- self.assertFalse((ROOT / "tools" / "windows_serial_validation.py").exists())
- def test_collect_j6_host_sensor_real_fan_ptc_is_static_allowlisted_host_writer_and_debug_reader(self) -> None:
- script = (ROOT / "tools" / "remote" / "collect-j6-host-sensor-real-fan-ptc.ps1").read_text(
- encoding="utf-8"
- )
- for marker in [
- "System.IO.Ports.SerialPort",
- "[ValidatePattern('^COM[0-9]+$')]",
- "HostPort",
- "DebugPort",
- 'if (-not $SelfTest -and $HostPort -eq $DebugPort)',
- 'if (-not $SelfTest -and $HostPort -ne "COM8")',
- 'if (-not $SelfTest -and $DebugPort -ne "COM7")',
- "BaudRate = 115200",
- "DebugBaud = 921600",
- "DtrEnable = $false",
- "RtsEnable = $false",
- "host-port-raw.bin",
- "host-port-escaped.txt",
- "debug-uart-raw.bin",
- "debug-uart-escaped.txt",
- "bmc-raw-replay.bin",
- "host-sensor-report.json",
- "debug-frame-stream.json",
- "host-command-transcript.json",
- "j6-host-sensor-real-fan-ptc-capture-manifest.json",
- "real-bmc-j6-host-sensor-real-fan-ptc-debug921-v1-receipt-draft.json",
- "real-bmc-j6-host-sensor-real-fan-ptc-debug921-v1",
- "J6CMD",
- "J6RAW",
- "J6EVT",
- "J6PWM",
- "J6MOD",
- "J6STAT",
- "J6MAP",
- "J6TEMP",
- "SENS",
- "DIMM",
- "PTCCH",
- "FANCH",
- "SET PTC 01 10",
- "SET PTC 24 20",
- "SET FAN 01 40",
- "SET FAN 04 30",
- "SET PID ENABLE",
- "GET STATUS",
- "GET MAP",
- "GET SENSOR",
- "SET PID DISABLE",
- "DISABLE",
- "host_port_writes_to_serial",
- "debug_port_writes_to_serial",
- "driver_install_attempted = $false",
- "enumerates_com_ports = $false",
- "opens_unknown_com_ports = $false",
- "AssumeManualSramProgrammed",
- "PROGRAM_SRAM",
- "SelfTest",
- "startup-preflight.json",
- "READY",
- "J6READY",
- "preflight",
- "blocked_waiting_for_ready_epoch",
- ]:
- self.assertIn(marker, script)
- self.assertIn("$hostSerial.Write", script)
- self.assertNotIn("$debugSerial.Write", script)
- for forbidden in [
- "SET PTC 00",
- "SET FAN 00",
- "SET FAN 05",
- "SET FAN 06",
- "GetPortNames",
- "Win32_SerialPort",
- "Get-CimInstance",
- "Get-WmiObject",
- "pip install",
- "pyserial",
- "python",
- "pnputil",
- "devcon",
- "install-driver",
- "add-windowsdriver",
- "driverquery",
- "PROGRAM_FLASH",
- "ERASE_FLASH",
- "PROGRAM_SPIBIN",
- "DIRECT_FLASH_WRITE",
- "blocked_edit_required",
- ]:
- self.assertNotIn(forbidden.lower(), script.lower())
- def test_collect_j6_host_sensor_real_fan_ptc_has_startup_preflight_selftest(self) -> None:
- powershell = shutil.which("powershell")
- if powershell is None:
- self.skipTest("PowerShell is not available")
- script_path = ROOT / "tools" / "remote" / "collect-j6-host-sensor-real-fan-ptc.ps1"
- result = subprocess.run(
- [
- powershell,
- "-NoProfile",
- "-ExecutionPolicy",
- "Bypass",
- "-File",
- str(script_path),
- "-SelfTest",
- ],
- cwd=ROOT,
- text=True,
- capture_output=True,
- check=False,
- )
- output = result.stderr + result.stdout
- self.assertEqual(result.returncode, 0, output)
- for marker in [
- "selftest=pass",
- "ready_line=READY profile=temp-uart-ptc-remap seq=00000000",
- "j6ready_line=J6READY profile=temp-uart-ptc-remap",
- "epoch_locked=pass",
- "pre_sram_noise=OK seq=0000000D cmd=STATUS",
- "post_j6ready_raw_replay=pass",
- "formal_ack=OK seq=00000001 cmd=PTCCH",
- "stale_ack_isolated=pass",
- ]:
- self.assertIn(marker, output)
- def test_collect_j6_host_sensor_real_fan_ptc_accepts_native_bool_argument_shape(self) -> None:
- powershell = shutil.which("powershell")
- if powershell is None:
- self.skipTest("PowerShell is not available")
- script_path = ROOT / "tools" / "remote" / "collect-j6-host-sensor-real-fan-ptc.ps1"
- result = subprocess.run(
- [
- powershell,
- "-NoProfile",
- "-ExecutionPolicy",
- "Bypass",
- "-File",
- str(script_path),
- "-SelfTest",
- "-AssumeManualSramProgrammed",
- "$true",
- ],
- cwd=ROOT,
- text=True,
- capture_output=True,
- check=False,
- )
- output = result.stderr + result.stdout
- self.assertEqual(result.returncode, 0, output)
- self.assertIn("selftest=pass", output)
- def test_collect_j6_host_sensor_real_fan_ptc_handles_discarded_ack_arrays(self) -> None:
- powershell = shutil.which("powershell")
- if powershell is None:
- self.skipTest("PowerShell is not available")
- script_path = ROOT / "tools" / "remote" / "collect-j6-host-sensor-real-fan-ptc.ps1"
- script = script_path.read_text(encoding="utf-8-sig")
- helper_start = script.index("function Read-HostPortAvailableLines")
- helper_end = script.index("function Invoke-StartupPreflight")
- helpers = script[helper_start:helper_end]
- with tempfile.TemporaryDirectory() as tmp:
- probe_path = Path(tmp) / "probe.ps1"
- probe_path.write_text(
- helpers
- + """
- $hostRaw = New-Object System.Collections.Generic.List[byte]
- $hostWindow = New-Object System.Text.StringBuilder
- $hostReports = New-Object System.Collections.Generic.List[object]
- $queue = New-Object System.Collections.Generic.Queue[object]
- $queue.Enqueue([ordered]@{
- ack_line = "OK seq=00000001 cmd=STATUS"
- raw = "OK seq=00000001 cmd=STATUS"
- token = "OK seq=00000001 cmd=STATUS"
- class = "ok"
- seq = 1
- cmd = "STATUS"
- ack_offset = 1
- response_offset = 1
- delimiter = "CR"
- timestamp = (Get-Date).ToUniversalTime().ToString("o")
- }) | Out-Null
- $queue.Enqueue([ordered]@{
- ack_line = "OK seq=00000001 cmd=PTCCH"
- raw = "OK seq=00000001 cmd=PTCCH"
- token = "OK seq=00000001 cmd=PTCCH"
- class = "ok"
- seq = 1
- cmd = "PTCCH"
- ack_offset = 10
- response_offset = 10
- delimiter = "CR"
- timestamp = (Get-Date).ToUniversalTime().ToString("o")
- }) | Out-Null
- $serial = [pscustomobject]@{ BytesToRead = 0 }
- $ack = Read-HostAckLine $serial $hostRaw $hostWindow $hostReports $queue 5 200 1 "PTCCH"
- if ($ack.ack_line -ne "OK seq=00000001 cmd=PTCCH") { throw "candidate ack not returned: $($ack.ack_line)" }
- if ($ack.discarded_acks.Count -ne 1) { throw "discarded ack count was $($ack.discarded_acks.Count)" }
- if (-not $ack.discarded_acks[0].stale) { throw "discarded ack was not marked stale" }
- """,
- encoding="utf-8",
- )
- result = subprocess.run(
- [powershell, "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(probe_path)],
- cwd=ROOT,
- text=True,
- capture_output=True,
- check=False,
- )
- self.assertEqual(result.returncode, 0, result.stderr + result.stdout)
- def test_collect_j6_host_sensor_real_fan_ptc_epoch_lock_discards_pre_sram_ack_noise(self) -> None:
- powershell = shutil.which("powershell")
- if powershell is None:
- self.skipTest("PowerShell is not available")
- script_path = ROOT / "tools" / "remote" / "collect-j6-host-sensor-real-fan-ptc.ps1"
- script = script_path.read_text(encoding="utf-8-sig")
- helper_start = script.index("function Read-HostPortAvailableLines")
- helper_end = script.index("function Invoke-CollectorSelfTest")
- helpers = script[helper_start:helper_end]
- with tempfile.TemporaryDirectory() as tmp:
- probe_path = Path(tmp) / "probe.ps1"
- probe_path.write_text(
- helpers
- + """
- $preflight = New-StartupPreflightRecord
- $ackQueue = New-Object System.Collections.Generic.Queue[object]
- $ackQueue.Enqueue([ordered]@{
- ack_line = "OK seq=0000000D cmd=STATUS"
- raw = "OK seq=0000000D cmd=STATUS"
- token = "OK seq=0000000D cmd=STATUS"
- class = "ok"
- seq = 13
- cmd = "STATUS"
- ack_offset = 25
- response_offset = 25
- delimiter = "CR"
- timestamp = (Get-Date).ToUniversalTime().ToString("o")
- }) | Out-Null
- $preReadyDiscard = @(Clear-HostAckQueue $ackQueue)
- Add-PreSramNoise $preflight "ack" $preReadyDiscard[0]
- $hostReady = [ordered]@{ kind = "ready"; raw = "READY profile=temp-uart-ptc-remap seq=00000000"; fields = [ordered]@{} }
- $debugReady = [ordered]@{ kind = "j6ready"; raw = "J6READY profile=temp-uart-ptc-remap"; fields = [ordered]@{} }
- Update-PreflightEpochReady $preflight $hostReady 100 200
- Update-PreflightEpochReady $preflight $debugReady 300 400
- Complete-StartupPreflightRecord $preflight
- if ($preflight.status -ne "pass") { throw "preflight status was $($preflight.status)" }
- if (-not $preflight.epoch_locked) { throw "epoch was not locked" }
- if ($preflight.sync_ack_seen) { throw "preflight incorrectly accepted sync ack" }
- if ($preflight.pre_sram_noise_count -ne 1) { throw "pre_sram_noise_count was $($preflight.pre_sram_noise_count)" }
- if ($preflight.pre_sram_noise[0].ack_line -ne "OK seq=0000000D cmd=STATUS") { throw "wrong pre_sram noise ack" }
- if ($preflight.epoch_locked_at_host_offset -ne 100) { throw "wrong host epoch offset" }
- if ($preflight.epoch_locked_at_debug_offset -ne 400) { throw "wrong debug epoch offset" }
- $ackQueue.Enqueue([ordered]@{
- ack_line = "OK seq=00000001 cmd=PTCCH"
- raw = "OK seq=00000001 cmd=PTCCH"
- token = "OK seq=00000001 cmd=PTCCH"
- class = "ok"
- seq = 1
- cmd = "PTCCH"
- ack_offset = 150
- response_offset = 150
- delimiter = "CR"
- timestamp = (Get-Date).ToUniversalTime().ToString("o")
- }) | Out-Null
- $serial = [pscustomobject]@{ BytesToRead = 0 }
- $hostRaw = New-Object System.Collections.Generic.List[byte]
- $hostWindow = New-Object System.Text.StringBuilder
- $hostReports = New-Object System.Collections.Generic.List[object]
- $ack = Read-HostAckLine $serial $hostRaw $hostWindow $hostReports $ackQueue 120 200 1 "PTCCH"
- if ($ack.ack_line -ne "OK seq=00000001 cmd=PTCCH") { throw "formal ack not returned: $($ack.ack_line)" }
- if (-not $ack.seq_match -or -not $ack.cmd_match) { throw "formal ack mismatch" }
- """,
- encoding="utf-8",
- )
- result = subprocess.run(
- [powershell, "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(probe_path)],
- cwd=ROOT,
- text=True,
- capture_output=True,
- check=False,
- )
- self.assertEqual(result.returncode, 0, result.stderr + result.stdout)
- def test_collect_j6_host_sensor_real_fan_ptc_handles_timeout_discarded_ack_arrays(self) -> None:
- powershell = shutil.which("powershell")
- if powershell is None:
- self.skipTest("PowerShell is not available")
- script_path = ROOT / "tools" / "remote" / "collect-j6-host-sensor-real-fan-ptc.ps1"
- script = script_path.read_text(encoding="utf-8-sig")
- helper_start = script.index("function Read-HostPortAvailableLines")
- helper_end = script.index("function Invoke-StartupPreflight")
- helpers = script[helper_start:helper_end]
- with tempfile.TemporaryDirectory() as tmp:
- probe_path = Path(tmp) / "probe.ps1"
- probe_path.write_text(
- helpers
- + """
- $hostRaw = New-Object System.Collections.Generic.List[byte]
- $hostWindow = New-Object System.Text.StringBuilder
- $hostReports = New-Object System.Collections.Generic.List[object]
- $queue = New-Object System.Collections.Generic.Queue[object]
- $queue.Enqueue([ordered]@{
- ack_line = "OK seq=00000001 cmd=STATUS"
- raw = "OK seq=00000001 cmd=STATUS"
- token = "OK seq=00000001 cmd=STATUS"
- class = "ok"
- seq = 1
- cmd = "STATUS"
- ack_offset = 1
- response_offset = 1
- delimiter = "CR"
- timestamp = (Get-Date).ToUniversalTime().ToString("o")
- }) | Out-Null
- $serial = [pscustomobject]@{ BytesToRead = 0 }
- $ack = Read-HostAckLine $serial $hostRaw $hostWindow $hostReports $queue 5 100 1 "PTCCH"
- if ($ack.class -ne "timeout") { throw "ack class was $($ack.class)" }
- if ($ack.discarded_acks.Count -ne 1) { throw "discarded ack count was $($ack.discarded_acks.Count)" }
- if (-not $ack.discarded_acks[0].stale) { throw "discarded ack was not marked stale" }
- """,
- encoding="utf-8",
- )
- result = subprocess.run(
- [powershell, "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(probe_path)],
- cwd=ROOT,
- text=True,
- capture_output=True,
- check=False,
- )
- self.assertEqual(result.returncode, 0, result.stderr + result.stdout)
- def test_collect_j6_host_sensor_real_fan_ptc_preserves_empty_raw_replay_byte_array(self) -> None:
- powershell = shutil.which("powershell")
- if powershell is None:
- self.skipTest("PowerShell is not available")
- script_path = ROOT / "tools" / "remote" / "collect-j6-host-sensor-real-fan-ptc.ps1"
- script = script_path.read_text(encoding="utf-8")
- helper_start = script.index("function Convert-HexToBytes")
- helper_end = script.index("$out =")
- helpers = script[helper_start:helper_end]
- with tempfile.TemporaryDirectory() as tmp:
- probe_path = Path(tmp) / "probe.ps1"
- out_path = Path(tmp) / "empty-replay.bin"
- probe_path.write_text(
- helpers
- + f"""
- $events = New-Object System.Collections.Generic.List[object]
- $rawReplayArray = New-BmcRawReplay $events
- if ($null -eq $rawReplayArray) {{
- throw "raw replay array was null"
- }}
- if ($rawReplayArray.GetType().FullName -ne "System.Byte[]") {{
- throw "raw replay array type was $($rawReplayArray.GetType().FullName)"
- }}
- if ($rawReplayArray.Length -ne 0) {{
- throw "raw replay array length was $($rawReplayArray.Length)"
- }}
- [System.IO.File]::WriteAllBytes("{out_path}", $rawReplayArray)
- """,
- encoding="utf-8",
- )
- result = subprocess.run(
- [powershell, "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(probe_path)],
- cwd=ROOT,
- text=True,
- capture_output=True,
- check=False,
- )
- self.assertEqual(result.returncode, 0, result.stderr + result.stdout)
- self.assertTrue(out_path.exists())
- self.assertEqual(out_path.stat().st_size, 0)
- def test_collect_j6_host_sensor_real_fan_ptc_parses_hex_fields_without_losing_payload_width(self) -> None:
- powershell = shutil.which("powershell")
- if powershell is None:
- self.skipTest("PowerShell is not available")
- script_path = ROOT / "tools" / "remote" / "collect-j6-host-sensor-real-fan-ptc.ps1"
- script = script_path.read_text(encoding="utf-8")
- helper_start = script.index("function Convert-TokenValue")
- helper_end = script.index("function Convert-BytesToEscapedText")
- replay_helper_start = script.index("function Convert-HexToBytes")
- replay_helper_end = script.index("function Get-LastFieldOrDefault")
- helpers = script[helper_start:helper_end] + script[replay_helper_start:replay_helper_end]
- with tempfile.TemporaryDirectory() as tmp:
- probe_path = Path(tmp) / "probe.ps1"
- probe_path.write_text(
- helpers
- + """
- $events = New-Object System.Collections.Generic.List[object]
- $events.Add((Convert-FrameLine "J6PWM seq=0000000A src=hm pid=disabled timeout=1 ptc01=00 ptc24=00 fan01=1E fan04=1E" @("J6PWM"))) | Out-Null
- $events.Add((Convert-FrameLine "J6TEMP seq=00000003 status=valid valid=1E missing=00 fault=0 host_report_drop=00000000" @("J6TEMP"))) | Out-Null
- $events.Add((Convert-FrameLine "J6RAW seq=00000001 off=00000000 len=02 sum=0031 data=0031" @("J6RAW"))) | Out-Null
- $events.Add((Convert-FrameLine "J6RAW s=002A o=00000100 l=04 u=000A d=01020304" @("J6RAW"))) | Out-Null
- $events.Add((Convert-FrameLine "J6EVT s=06 cmd=PID_E c=01 p=000 ok=1 e=0 to=0" @("J6EVT"))) | Out-Null
- $events.Add((Convert-FrameLine "DIMM i=10 t=00 m=1" @("DIMM"))) | Out-Null
- foreach ($probe in @(
- @($events[0].fields.fan01, "fan01"),
- @($events[0].fields.timeout, "timeout"),
- @($events[1].fields.valid, "valid"),
- @($events[1].fields.missing, "missing"),
- @($events[2].fields.len, "len"),
- @($events[2].fields.sum, "sum"),
- @($events[3].fields.seq, "compact_seq"),
- @($events[3].fields.off, "compact_off"),
- @($events[3].fields.len, "compact_len"),
- @($events[3].fields.sum, "compact_sum"),
- @($events[4].fields.ch, "compact_ch"),
- @($events[4].fields.pct, "compact_pct"),
- @($events[4].fields.err, "compact_err")
- )) {
- if ($probe[0].GetType().FullName -ne "System.Int64") {
- throw "$($probe[1]) parsed as $($probe[0].GetType().FullName)"
- }
- }
- if ([int64]$events[0].fields.fan01 -ne 30) { throw "fan01 was $($events[0].fields.fan01)" }
- if ([int64]$events[0].fields.timeout -ne 1) { throw "timeout was $($events[0].fields.timeout)" }
- if ([int64]$events[1].fields.valid -ne 30) { throw "valid was $($events[1].fields.valid)" }
- if ([int64]$events[1].fields.missing -ne 0) { throw "missing was $($events[1].fields.missing)" }
- if ([int64]$events[2].fields.len -ne 2) { throw "len was $($events[2].fields.len)" }
- if ([int64]$events[2].fields.sum -ne 49) { throw "sum was $($events[2].fields.sum)" }
- if ([int64]$events[3].fields.seq -ne 42) { throw "compact seq was $($events[3].fields.seq)" }
- if ([int64]$events[3].fields.off -ne 256) { throw "compact off was $($events[3].fields.off)" }
- if ([int64]$events[3].fields.len -ne 4) { throw "compact len was $($events[3].fields.len)" }
- if ([int64]$events[3].fields.sum -ne 10) { throw "compact sum was $($events[3].fields.sum)" }
- if ($events[2].fields.data.GetType().FullName -ne "System.String") { throw "data parsed as $($events[2].fields.data.GetType().FullName)" }
- if ($events[2].fields.data -ne "0031") { throw "data was $($events[2].fields.data)" }
- if ($events[3].fields.data -ne "01020304") { throw "compact data was $($events[3].fields.data)" }
- if ([int64]$events[4].fields.ch -ne 1) { throw "compact ch was $($events[4].fields.ch)" }
- if ([int64]$events[4].fields.pct -ne 0) { throw "compact pct was $($events[4].fields.pct)" }
- if ([int64]$events[4].fields.err -ne 0) { throw "compact err was $($events[4].fields.err)" }
- if ([int64]$events[5].fields.id -ne 16) { throw "dimm id was $($events[5].fields.id)" }
- $replay = New-BmcRawReplay $events
- $replayHex = (($replay | ForEach-Object { $_.ToString("X2") }) -join "")
- if ($replayHex -ne "003101020304") { throw "replay was $replayHex" }
- """,
- encoding="utf-8",
- )
- result = subprocess.run(
- [powershell, "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(probe_path)],
- cwd=ROOT,
- text=True,
- capture_output=True,
- check=False,
- )
- self.assertEqual(result.returncode, 0, result.stderr + result.stdout)
- def test_collect_j6_host_sensor_real_fan_ptc_keeps_command_tokens_as_strings(self) -> None:
- powershell = shutil.which("powershell")
- if powershell is None:
- self.skipTest("PowerShell is not available")
- script_path = ROOT / "tools" / "remote" / "collect-j6-host-sensor-real-fan-ptc.ps1"
- script = script_path.read_text(encoding="utf-8")
- helper_start = script.index("function Convert-TokenValue")
- helper_end = script.index("function Convert-BytesToEscapedText")
- helpers = script[helper_start:helper_end]
- with tempfile.TemporaryDirectory() as tmp:
- probe_path = Path(tmp) / "probe.ps1"
- probe_path.write_text(
- helpers
- + """
- $events = New-Object System.Collections.Generic.List[object]
- $events.Add((Convert-FrameLine "J6CMD seq=00000001 cmd=raw text=ipmitool" @("J6CMD"))) | Out-Null
- $events.Add((Convert-FrameLine "J6EVT seq=00000002 ok=1 err=0 type=PTCCH ch=01 pct=0A" @("J6EVT"))) | Out-Null
- $events.Add((Convert-FrameLine "OK seq=00000003 cmd=FANCH" @("OK"))) | Out-Null
- if ($events[0].fields.cmd -ne "raw") { throw "cmd was $($events[0].fields.cmd)" }
- if ($events[1].fields.type -ne "PTCCH") { throw "type was $($events[1].fields.type)" }
- if ($events[1].fields.ch.GetType().FullName -ne "System.Int64") { throw "ch type was $($events[1].fields.ch.GetType().FullName)" }
- if ([int64]$events[1].fields.ch -ne 1) { throw "ch was $($events[1].fields.ch)" }
- if ([int64]$events[1].fields.pct -ne 10) { throw "pct was $($events[1].fields.pct)" }
- if ($events[2].fields.cmd -ne "FANCH") { throw "ack cmd was $($events[2].fields.cmd)" }
- """,
- encoding="utf-8",
- )
- result = subprocess.run(
- [powershell, "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(probe_path)],
- cwd=ROOT,
- text=True,
- capture_output=True,
- check=False,
- )
- self.assertEqual(result.returncode, 0, result.stderr + result.stdout)
- def test_j6_host_sensor_real_fan_ptc_package_script_creates_temp_profile_package(self) -> None:
- script = (ROOT / "tools" / "package_j6_host_sensor_real_fan_ptc_debug921.ps1").read_text(
- encoding="utf-8"
- )
- for marker in [
- "START-HERE.zh-CN.md",
- "tools\\remote\\collect-j6-host-sensor-real-fan-ptc.ps1",
- "bitstreams",
- "td-receipts",
- "commands",
- "pin_inventory.fcb_fpga_mcu0611.json",
- "sha256-inventory.json",
- "Compress-Archive",
- ".zip.sha256.txt",
- "temp-uart-ptc-remap",
- "j6-host-sensor-real-fan-ptc-temp-uart-ptc-remap-debug921-v2",
- "startup-preflight.json",
- "READY profile=temp-uart-ptc-remap",
- "collector first, then PROGRAM_SRAM",
- "ForceOverwrite",
- "SET PTC 01 10",
- "SET PTC 24 20",
- "SET FAN 01 40",
- "SET FAN 04 30",
- "excluded_self_referential_file",
- ]:
- self.assertIn(marker, script)
- self.assertNotIn("Set-ExecutionPolicy", script)
- self.assertNotIn("-AssumeManualSramProgrammed $true", script)
- for marker in [
- "formal-uart",
- "j6-host-sensor-real-fan-ptc-formal-uart-debug921-v1",
- "debug115",
- "swapped",
- "-ManualSramAttestation",
- "$att.status",
- "blocked_edit_required",
- "collect-com8-host-com7-debug.ps1",
- r"-Bitstream .\bitstreams\uart_rs232_j6_host_sensor_real_fan_ptc_debug921_primary.bit",
- "SET PTC 00",
- "SET FAN 00",
- "SET FAN 05",
- "SET FAN 06",
- "pip install",
- "pyserial",
- "python",
- ]:
- self.assertNotIn(marker.lower(), script.lower())
- def test_j6_host_sensor_real_fan_ptc_package_output_contains_temp_profile_artifacts(self) -> None:
- powershell = shutil.which("powershell")
- if powershell is None:
- self.skipTest("PowerShell is not available")
- with tempfile.TemporaryDirectory() as tmp:
- bitstream = Path(tmp) / "fake.bit"
- td_receipt = Path(tmp) / "td-receipt.json"
- bitstream.write_bytes(b"fake-sram-bitstream")
- td_receipt.write_text(
- json.dumps(
- {
- "schema": "td-build-receipt-v1",
- "status": "pass",
- "programming_mode": "SRAM-only",
- "bitstream": {"sha256": "0" * 64},
- }
- ),
- encoding="utf-8",
- )
- for profile, package_name in [
- ("temp-uart-ptc-remap", "j6-host-sensor-real-fan-ptc-temp-uart-ptc-remap-debug921-v2-test"),
- ]:
- with self.subTest(profile=profile):
- result = subprocess.run(
- [
- powershell,
- "-NoProfile",
- "-ExecutionPolicy",
- "Bypass",
- "-File",
- str(ROOT / "tools" / "package_j6_host_sensor_real_fan_ptc_debug921.ps1"),
- "-OutputDir",
- tmp,
- "-PackageName",
- package_name,
- "-Profile",
- profile,
- "-Bitstream",
- str(bitstream),
- "-TdReceipt",
- str(td_receipt),
- ],
- cwd=ROOT,
- capture_output=True,
- check=False,
- )
- output = (result.stderr or b"").decode("utf-8", errors="replace") + (
- result.stdout or b""
- ).decode("utf-8", errors="replace")
- self.assertEqual(result.returncode, 0, output)
- stage = Path(tmp) / package_name
- self.assertTrue((stage / "START-HERE.zh-CN.md").is_file())
- self.assertTrue((stage / "collector" / "collect-j6-host-sensor-real-fan-ptc.ps1").is_file())
- self.assertTrue((stage / "commands" / "collect-template.ps1").is_file())
- self.assertTrue((stage / "bitstreams" / bitstream.name).is_file())
- self.assertTrue((stage / "td-receipts" / td_receipt.name).is_file())
- self.assertTrue((stage / "config" / "pin_inventory.fcb_fpga_mcu0611.json").is_file())
- self.assertTrue((stage / "schemas" / "real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt.schema.json").is_file())
- self.assertFalse((stage / "blocked").exists())
- self.assertTrue((Path(tmp) / f"{package_name}.zip").is_file())
- self.assertTrue((Path(tmp) / f"{package_name}.zip.sha256.txt").is_file())
- start_here = (stage / "START-HERE.zh-CN.md").read_text(encoding="utf-8-sig")
- self.assertIn("PROGRAM_SRAM", start_here)
- self.assertIn("先启动 collector", start_here)
- self.assertIn("collector first, then PROGRAM_SRAM", start_here)
- self.assertIn(f"-Profile {profile}", start_here)
- self.assertIn(f".\\bitstreams\\{bitstream.name}", start_here)
- self.assertIn(f".\\td-receipts\\{td_receipt.name}", start_here)
- self.assertIn("powershell.exe -NoProfile -ExecutionPolicy Bypass -File", start_here)
- self.assertIn("-HostPort COM8 -DebugPort COM7", start_here)
- self.assertNotIn("Set-ExecutionPolicy", start_here)
- self.assertNotIn("-AssumeManualSramProgrammed", start_here)
- self.assertNotIn("先手动刷 SRAM", start_here)
- self.assertNotIn("刷完 SRAM 后采集", start_here)
- collect_template = (stage / "commands" / "collect-template.ps1").read_text(
- encoding="utf-8-sig"
- )
- self.assertNotIn("Set-ExecutionPolicy", collect_template)
- self.assertNotIn("-AssumeManualSramProgrammed", collect_template)
- self.assertIn("-NoProfile", collect_template)
- self.assertIn("-ExecutionPolicy Bypass", collect_template)
- self.assertIn("-File .\\collector\\collect-j6-host-sensor-real-fan-ptc.ps1", collect_template)
- self.assertNotIn("blocked_pin_conflict_with_locked_debug_uart", start_here)
- manifest = json.loads((stage / "manifest.json").read_text(encoding="utf-8-sig"))
- self.assertEqual(manifest["status"], "pass")
- self.assertEqual(manifest["pin_profile"], profile)
- self.assertEqual(manifest["programming_mode"], "PROGRAM_SRAM")
- self.assertIn("host_control_commands", manifest)
- self.assertIn("pin_map", manifest)
- self.assertNotIn("pin_conflicts", manifest)
- inventory = json.loads((stage / "sha256-inventory.json").read_text(encoding="utf-8-sig"))
- self.assertEqual(inventory["self_hash_policy"], "excluded_self_referential_file")
- inventory_paths = {item["path"] for item in inventory["inventory"]}
- self.assertIn("manifest.json", inventory_paths)
- self.assertIn("START-HERE.zh-CN.md", inventory_paths)
- self.assertIn("collector/collect-j6-host-sensor-real-fan-ptc.ps1", inventory_paths)
- self.assertIn("commands/collect-template.ps1", inventory_paths)
- self.assertNotIn("sha256-inventory.json", inventory_paths)
- def test_j6_host_sensor_real_fan_ptc_runbook_is_chinese_copy_paste_ready_with_english_paths(self) -> None:
- runbook = (ROOT / "docs" / "j6-host-sensor-real-fan-ptc-debug921-runbook.zh-CN.md").read_text(
- encoding="utf-8"
- )
- for marker in [
- "J6 Host Sensor Real FAN/PTC Debug921",
- "START-HERE.zh-CN.md",
- "temp-uart-ptc-remap",
- "PROGRAM_SRAM",
- "collector first, then PROGRAM_SRAM",
- "COM8",
- "COM7",
- "PTC03",
- "PTC04",
- "PTC17",
- "PTC18",
- "PTC21",
- "PTC22",
- "SET PTC 01 10",
- "SET PTC 24 20",
- "SET FAN 01 40",
- "SET FAN 04 30",
- "SET PID ENABLE",
- "GET SENSOR",
- "SET PID DISABLE",
- "DISABLE",
- "PTCCH",
- "FANCH",
- "1-based",
- "SENS",
- "DIMM",
- "J6TEMP",
- "J6RAW",
- "host-port-escaped.txt",
- "debug-uart-escaped.txt",
- "host-sensor-report.json",
- "bmc-raw-replay.bin",
- "不安装驱动",
- "不枚举未知 COM",
- "不写 DebugPort",
- "blocked_pin_conflict_with_locked_debug_uart",
- ]:
- self.assertIn(marker, runbook)
- for forbidden in [
- "debug115",
- "Manual SRAM attestation status must be pass",
- "blocked_edit_required",
- "当前不要刷机",
- "Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force",
- "先手动刷 SRAM",
- "确认 SRAM 下载完成后",
- r".\commands\collect-com8-host-com7-debug.ps1",
- r"bitstreams\uart_rs232_j6_host_sensor_real_fan_ptc_debug921_primary.bit",
- "collector/collect-j6-host-sensor-real-fan-ptc.ps1",
- "SET PTC 00",
- "SET FAN 00",
- "SET FAN 05",
- "SET FAN 06",
- r".\collector\采集",
- ]:
- self.assertNotIn(forbidden, runbook)
- def test_j6_host_sensor_real_fan_ptc_schema_requires_sensor_pwm_pid_pinmap_and_debug_artifacts(self) -> None:
- schema = json.loads(
- (ROOT / "schemas" / "real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt.schema.json").read_text(
- encoding="utf-8"
- )
- )
- layers = schema["properties"]["layers"]["properties"]
- self.assertEqual(schema["properties"]["diagnostic_scope"], {"const": "host_sensor_real_fan_ptc_debug921"})
- for layer in [
- "host_command_sequence",
- "host_control_transcript",
- "host_sensor_reports",
- "debug_frame_capture",
- "bmc_raw_sampling",
- "pid_boundary",
- "timeout_evidence",
- "pin_map",
- "real_fan_ptc_hardware_status",
- "artifact_hashes",
- ]:
- self.assertIn(layer, layers)
- commands = layers["host_command_sequence"]["properties"]["commands"]["prefixItems"]
- self.assertEqual(commands[0], {"const": "SET PTC 01 10"})
- self.assertEqual(commands[1], {"const": "SET PTC 24 20"})
- self.assertEqual(commands[2], {"const": "SET FAN 01 40"})
- self.assertEqual(commands[3], {"const": "SET FAN 04 30"})
- self.assertIn("host_sensor_report", layers["host_sensor_reports"]["required"])
- self.assertIn("debug_frame_stream", layers["debug_frame_capture"]["required"])
- self.assertIn("raw_replay", layers["debug_frame_capture"]["required"])
- self.assertEqual(layers["pin_map"]["properties"]["ptc_count"], {"const": 24})
- self.assertEqual(layers["pin_map"]["properties"]["fan_count"], {"const": 4})
- if __name__ == "__main__":
- unittest.main()
|