| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840 |
- #!/usr/bin/env python3
- """Remote collector and package tests for the converged CPLD project."""
- from __future__ import annotations
- import json
- import hashlib
- 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",
- "JtagSpeedHz",
- "BoardPowerPresentBeforeProgram",
- "jtag_speed_hz",
- "board_power_present_before_program",
- "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",
- "tail_drain=pass",
- "jtag_speed_hz=200000",
- "board_power_present_before_program=true",
- "post_j6stat_tail_bytes=04",
- "complete_unterminated_j6raw=pass",
- "incomplete_final_line=J6RAW s=0004",
- ]:
- 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_marks_clear_queue_results_as_pre_sram_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 Clear-HostAckQueue")
- helper_end = script.index("function Update-PreflightEpochReady")
- 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
- $moreStale = @(Clear-HostAckQueue $ackQueue)
- foreach ($ack in $moreStale) {
- Set-AckMetadata $ack "pre_sram_noise" $true
- Add-PreSramNoise $preflight "ack" $ack
- }
- if ($moreStale.Count -ne 1) { throw "unexpected stale count $($moreStale.Count)" }
- if ($moreStale[0] -is [array]) { throw "stale ack was nested array" }
- if (-not $moreStale[0].pre_sram_noise) { throw "pre_sram_noise was not set" }
- if ($preflight.pre_sram_noise_count -ne 1) { throw "preflight 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" }
- """,
- 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",
- "tools\\bmc_replay_uart.py",
- "bitstreams",
- "td-receipts",
- "commands",
- "bmc-replay",
- "pin_inventory.fcb_fpga_mcu0611.json",
- "sha256-inventory.json",
- "Compress-Archive",
- ".zip.sha256.txt",
- "j6-bmc-replay",
- "j6tmp.bit",
- "collect.ps1",
- "capture-bmc.ps1",
- "replay-bmc.ps1",
- "td.json",
- "debug-photo-uart-bmc-replay",
- "formal-uart1-bmc-replay",
- "pc_replay_from_real_bmc_capture",
- "startup-preflight.json",
- "collector first, then PROGRAM_SRAM",
- "tail drain",
- "ForceOverwrite",
- "FormalBlocked",
- "FORMAL-BLOCKED.zh-CN.md",
- "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 [
- "j6-host-sensor-real-fan-ptc-temp-uart-ptc-remap-debug921-v2-epochfix-psarrayfix-tailfix",
- "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",
- ]:
- self.assertNotIn(marker.lower(), script.lower())
- def test_binary921_collector_selftest_and_static_safety_contract(self) -> None:
- script = ROOT / "tools" / "remote" / "collect_j6_binary921.py"
- self.assertTrue(script.is_file())
- text = script.read_text(encoding="utf-8")
- for marker in [
- "binary921",
- "explicit COM ports only",
- "serial.Serial",
- "HostPort",
- "DebugPort",
- "build_host_command",
- "decode_stream",
- "startup-preflight.json",
- "host-command-transcript.json",
- "debug-binary921-frames.json",
- "binary921-evidence-manifest.json",
- "real_fan_ptc_hardware_status",
- "pc_replay_from_real_bmc_capture",
- "SET_PTC",
- "SET_FAN",
- "SET_PID_REQUESTED",
- "DISABLE",
- ]:
- self.assertIn(marker, text)
- for forbidden in [
- "PROGRAM_FLASH",
- "ERASE_FLASH",
- "PROGRAM_SPIBIN",
- "DIRECT_FLASH_WRITE",
- "GetPortNames",
- "Win32_SerialPort",
- "Set-ExecutionPolicy",
- "pip install",
- "driver install",
- "debug_serial.write",
- ]:
- self.assertNotIn(forbidden.lower(), text.lower())
- result = subprocess.run(
- [str(ROOT / ".codex" / "venv" / "Scripts" / "python.exe"), str(script), "--selftest"],
- cwd=ROOT,
- text=True,
- capture_output=True,
- check=False,
- )
- self.assertEqual(result.returncode, 0, result.stderr + result.stdout)
- self.assertIn("selftest=pass", result.stdout)
- def test_binary921_collector_sets_dtr_rts_low_before_opening_pyserial(self) -> None:
- import sys
- import types
- from unittest import mock
- sys.path.insert(0, str(ROOT / "tools" / "remote"))
- import collect_j6_binary921
- calls: list[tuple[str, object]] = []
- class FakeSerial:
- def __init__(self, *args: object, **kwargs: object) -> None:
- calls.append(("init", {"args": args, "kwargs": kwargs}))
- if args or kwargs:
- raise AssertionError("Serial must be constructed closed before setting DTR/RTS")
- self.port = None
- self.baudrate = None
- self.bytesize = None
- self.parity = None
- self.stopbits = None
- self.timeout = None
- self.write_timeout = None
- self.rtscts = None
- self.dsrdtr = None
- self.dtr = None
- self.rts = None
- self.is_open = False
- def open(self) -> None:
- calls.append(
- (
- "open",
- {
- "port": self.port,
- "baudrate": self.baudrate,
- "dtr": self.dtr,
- "rts": self.rts,
- "rtscts": self.rtscts,
- "dsrdtr": self.dsrdtr,
- },
- )
- )
- self.is_open = True
- with mock.patch.dict(sys.modules, {"serial": types.SimpleNamespace(Serial=FakeSerial)}):
- endpoint = collect_j6_binary921._open_serial("COM7", 921600)
- self.assertIs(endpoint.is_open, True)
- self.assertEqual(
- calls,
- [
- ("init", {"args": (), "kwargs": {}}),
- (
- "open",
- {
- "port": "COM7",
- "baudrate": 921600,
- "dtr": False,
- "rts": False,
- "rtscts": False,
- "dsrdtr": False,
- },
- ),
- ],
- )
- def test_binary921_collector_supports_production_combined_uart_profile(self) -> None:
- import sys
- from unittest import mock
- sys.path.insert(0, str(ROOT / "tools"))
- sys.path.insert(0, str(ROOT / "tools" / "remote"))
- from binary921 import CommandId, FrameType, decode_frame, encode_frame, frame_to_dict, profile_id_for_name
- from collect_j6_binary921 import (
- COMMAND_SEQUENCE,
- build_manifest_from_frames,
- collect_live,
- is_combined_uart_profile,
- )
- profile = "production-two-uart-bmc-replay-binary921"
- profile_id = profile_id_for_name(profile)
- self.assertTrue(is_combined_uart_profile(profile))
- commands = [
- {
- "seq": index,
- "name": name,
- "command_id": int(command),
- "channel": channel,
- "percent": percent,
- }
- for index, (name, command, channel, percent) in enumerate(COMMAND_SEQUENCE, start=1)
- ]
- combined_frames = [
- frame_to_dict(
- decode_frame(
- encode_frame(
- profile_id=profile_id,
- frame_type=FrameType.READY,
- seq=0,
- timestamp_tick=0,
- payload=bytes([profile_id, 0, 0, 0]),
- )
- )
- )
- ]
- for row in commands:
- combined_frames.append(
- frame_to_dict(
- decode_frame(
- encode_frame(
- profile_id=profile_id,
- frame_type=FrameType.HOST_ACK,
- seq=row["seq"],
- timestamp_tick=0,
- payload=bytes([1, row["command_id"], 0, 0, 0x34, 0x12]),
- )
- )
- )
- )
- combined_frames.extend(
- [
- frame_to_dict(
- decode_frame(
- encode_frame(
- profile_id=profile_id,
- frame_type=FrameType.BMC_PAYLOAD,
- seq=50,
- timestamp_tick=0,
- payload=bytes([48, 48, 0, 1, 0x1E, 0xFF, 0x08, 0x14]),
- )
- )
- ),
- frame_to_dict(
- decode_frame(
- encode_frame(
- profile_id=profile_id,
- frame_type=FrameType.SENSOR_CACHE,
- seq=51,
- timestamp_tick=0,
- payload=bytes([profile_id, 0, 1, 0xFE, 0xEF, 0xFF, 2, 22]),
- )
- )
- ),
- frame_to_dict(
- decode_frame(
- encode_frame(
- profile_id=profile_id,
- frame_type=FrameType.MODULE_SNAPSHOT,
- seq=52,
- timestamp_tick=0,
- payload=bytes(
- [
- profile_id,
- 0,
- len(COMMAND_SEQUENCE),
- 0,
- 0x1E,
- 0xFF,
- 0x08,
- 0x14,
- CommandId.DISABLE,
- 0,
- 0,
- 0,
- 0,
- 1,
- 2,
- 22,
- 0,
- 0,
- 30,
- 30,
- 0,
- 0x0F,
- 0,
- 0,
- ]
- ),
- )
- )
- ),
- ]
- )
- manifest = build_manifest_from_frames(
- profile=profile,
- startup_ready=combined_frames[0],
- host_commands=commands,
- host_frames=combined_frames,
- debug_frames=combined_frames,
- debug_raw=b"same-com-raw",
- host_raw=b"same-com-raw",
- combined_raw=b"same-com-raw",
- bmc_replay={
- "status": "pass",
- "bmc_source": "pc_replay_from_real_bmc_capture",
- "byte_count": 48,
- "valid_count": 2,
- "missing_count": 22,
- "reply_sha256": "06c173f91f8b6b0e56f9c381b49d5b127d2dbf3a09402843838a0ff2b812f1af",
- },
- )
- self.assertEqual(manifest["status"], "pass")
- self.assertEqual(manifest["profile"], profile)
- self.assertEqual(manifest["transport"], "combined_host_debug_uart")
- self.assertEqual(manifest["combined_uart_baud"], 921600)
- self.assertEqual(manifest["host_ack_matched_count"], len(COMMAND_SEQUENCE))
- self.assertIn("combined-uart-binary921.raw", manifest["artifact_hashes"])
- self.assertEqual(manifest["module_snapshot_count"], 1)
- self.assertEqual(manifest["pwm_logic_evidence"]["status"], "pass")
- self.assertEqual(manifest["pid_evidence"]["status"], "pass")
- self.assertEqual(manifest["timeout_fallback_evidence"]["status"], "pass")
- class ShouldNotOpenSerial:
- def __call__(self, port: str, baud: int) -> object:
- raise AssertionError(f"unexpected open {port} {baud}")
- with mock.patch("collect_j6_binary921._open_serial", ShouldNotOpenSerial()):
- with self.assertRaisesRegex(ValueError, "CombinedPort must be an explicit COM"):
- collect_live(
- type(
- "Args",
- (),
- {
- "profile": profile,
- "transport": "combined-single-com",
- "combined_port": "AUTO",
- "host_port": "",
- "debug_port": "",
- "output_dir": "unused",
- "duration_sec": 0,
- "ready_timeout_sec": 0,
- "ack_window_sec": 0,
- "bitstream": "",
- "td_receipt": "",
- "bmc_replay_receipt": "",
- },
- )()
- )
- def test_binary921_production_manifest_blocks_without_timeout_snapshot(self) -> None:
- import sys
- sys.path.insert(0, str(ROOT / "tools"))
- sys.path.insert(0, str(ROOT / "tools" / "remote"))
- from binary921 import CommandId, FrameType, decode_frame, encode_frame, frame_to_dict, profile_id_for_name
- from collect_j6_binary921 import COMMAND_SEQUENCE, build_manifest_from_frames
- profile = "production-two-uart-bmc-replay-binary921"
- profile_id = profile_id_for_name(profile)
- commands = [
- {
- "seq": index,
- "name": name,
- "command_id": int(command),
- "channel": channel,
- "percent": percent,
- }
- for index, (name, command, channel, percent) in enumerate(COMMAND_SEQUENCE, start=1)
- ]
- frames = [
- frame_to_dict(
- decode_frame(
- encode_frame(
- profile_id=profile_id,
- frame_type=FrameType.READY,
- seq=0,
- timestamp_tick=0,
- payload=bytes([profile_id, 0, 0, 0]),
- )
- )
- )
- ]
- for row in commands:
- frames.append(
- frame_to_dict(
- decode_frame(
- encode_frame(
- profile_id=profile_id,
- frame_type=FrameType.HOST_ACK,
- seq=row["seq"],
- timestamp_tick=0,
- payload=bytes([1, row["command_id"], 0, 0, 0x34, 0x12]),
- )
- )
- )
- )
- frames.append(
- frame_to_dict(
- decode_frame(
- encode_frame(
- profile_id=profile_id,
- frame_type=FrameType.BMC_PAYLOAD,
- seq=50,
- timestamp_tick=0,
- payload=bytes([48, 48, 0, 1, 0x1E, 0xFF, 0x08, 0x14]),
- )
- )
- )
- )
- frames.append(
- frame_to_dict(
- decode_frame(
- encode_frame(
- profile_id=profile_id,
- frame_type=FrameType.SENSOR_CACHE,
- seq=51,
- timestamp_tick=0,
- payload=bytes([profile_id, 0, 1, 0xFE, 0xEF, 0xFF, 2, 22]),
- )
- )
- )
- )
- manifest = build_manifest_from_frames(
- profile=profile,
- startup_ready=frames[0],
- host_commands=commands,
- host_frames=frames,
- debug_frames=frames,
- debug_raw=b"raw",
- host_raw=b"raw",
- combined_raw=b"raw",
- bmc_replay={
- "status": "pass",
- "source": "real_bmc_capture",
- "bmc_source": "pc_replay_from_real_bmc_capture",
- "byte_count": 48,
- "valid_count": 2,
- "missing_count": 22,
- "reply_sha256": "06c173f91f8b6b0e56f9c381b49d5b127d2dbf3a09402843838a0ff2b812f1af",
- "capture_text_sha256": "1" * 64,
- },
- )
- self.assertNotEqual(manifest["status"], "pass")
- self.assertIn("missing_module_snapshot", manifest["blockers"])
- self.assertIn("timeout_fallback_evidence_incomplete", manifest["blockers"])
- def test_binary921_collector_requires_exact_ack_and_bmc_payload_for_pass(self) -> None:
- import sys
- sys.path.insert(0, str(ROOT / "tools"))
- sys.path.insert(0, str(ROOT / "tools" / "remote"))
- from binary921 import CommandId, FrameType, decode_frame, encode_frame, frame_to_dict
- from collect_j6_binary921 import COMMAND_SEQUENCE, build_manifest_from_frames
- commands = [
- {
- "seq": index,
- "name": name,
- "command_id": int(command),
- "channel": channel,
- "percent": percent,
- }
- for index, (name, command, channel, percent) in enumerate(COMMAND_SEQUENCE, start=1)
- ]
- wrong_acks = [
- frame_to_dict(
- decode_frame(
- encode_frame(
- profile_id=1,
- frame_type=FrameType.HOST_ACK,
- seq=index + 1,
- timestamp_tick=0,
- payload=bytes([1, int(CommandId.GET_STATUS), 0, 0, 0, 0]),
- )
- )
- )
- for index in range(1, 13)
- ]
- ready = frame_to_dict(
- decode_frame(
- encode_frame(profile_id=1, frame_type=FrameType.READY, seq=1, timestamp_tick=0, payload=b"\x01\x00\x00\x00")
- )
- )
- manifest = build_manifest_from_frames(
- profile="debug-photo-bmc-replay-binary921",
- startup_ready=ready,
- host_commands=commands,
- host_frames=wrong_acks,
- debug_frames=[ready],
- debug_raw=b"",
- host_raw=b"",
- )
- self.assertEqual(manifest["status"], "blocked_host_ack")
- self.assertEqual(manifest["host_ack_count"], 12)
- self.assertEqual(manifest["host_ack_matched_count"], 0)
- self.assertIn("missing_bmc_payload", manifest["blockers"])
- def test_binary921_collector_writes_blocked_manifest_when_ready_is_missing(self) -> None:
- import sys
- sys.path.insert(0, str(ROOT / "tools" / "remote"))
- from collect_j6_binary921 import write_blocked_manifest
- with tempfile.TemporaryDirectory() as tmp:
- manifest = write_blocked_manifest(
- Path(tmp),
- profile="debug-photo-bmc-replay-binary921",
- status="blocked_waiting_for_binary921_ready",
- startup_raw=b"old-noise",
- startup_frames=[],
- error="timeout",
- )
- manifest_path = Path(tmp) / "binary921-evidence-manifest.json"
- self.assertTrue(manifest_path.is_file())
- self.assertEqual(manifest["status"], "blocked_waiting_for_binary921_ready")
- self.assertEqual(manifest["host_command_count"], 0)
- self.assertEqual(manifest["startup_pre_sram_noise_sha256"], "2720ea258623d86efdb0d4c7767f6806839c402b231d2dacde75d9d2256a0d45")
- def test_binary921_package_script_creates_debug_and_formal_packages(self) -> None:
- powershell = shutil.which("powershell")
- if powershell is None:
- self.skipTest("PowerShell is not available")
- script = ROOT / "tools" / "package_j6_binary921.ps1"
- self.assertTrue(script.is_file())
- static_text = script.read_text(encoding="utf-8")
- for marker in [
- "debug-photo-bmc-replay-binary921",
- "formal-uart1-bmc-replay-binary921",
- "collect_j6_binary921.py",
- "binary921.py",
- "bmc_replay_uart.py",
- "j6bin.bit",
- "collect-binary921.ps1",
- "START-HERE.zh-CN.md",
- "sha256-inventory.json",
- "binary921-evidence-manifest.json",
- "pc_replay_from_real_bmc_capture",
- "PYTHONDONTWRITEBYTECODE",
- "Remove-PythonCache",
- "__pycache__",
- ]:
- self.assertIn(marker, static_text)
- self.assertNotIn("Set-ExecutionPolicy", static_text)
- self.assertNotIn("pip install", static_text.lower())
- self.assertNotIn("PROGRAM_FLASH", static_text)
- with tempfile.TemporaryDirectory() as tmp:
- bitstream = Path(tmp) / "fake-binary921.bit"
- td_receipt = Path(tmp) / "td-binary921.json"
- bitstream.write_bytes(b"fake-binary921-sram-bitstream")
- td_receipt.write_text(json.dumps({"schema": "td-build-receipt-v1", "status": "pass"}), encoding="utf-8")
- for profile, package_name, expected_debug_rx, expected_debug_tx in [
- ("debug-photo-bmc-replay-binary921", "j6bin-debug-test", "P10", "R10"),
- ("formal-uart1-bmc-replay-binary921", "j6bin-formal-test", "M14", "M15"),
- ]:
- with self.subTest(profile=profile):
- result = subprocess.run(
- [
- powershell,
- "-NoProfile",
- "-ExecutionPolicy",
- "Bypass",
- "-File",
- str(script),
- "-OutputDir",
- tmp,
- "-PackageName",
- package_name,
- "-Profile",
- profile,
- "-Bitstream",
- str(bitstream),
- "-TdReceipt",
- str(td_receipt),
- ],
- cwd=ROOT,
- text=True,
- capture_output=True,
- check=False,
- )
- self.assertEqual(result.returncode, 0, result.stderr + result.stdout)
- stage = Path(tmp) / package_name
- self.assertTrue((stage / "j6bin.bit").is_file())
- self.assertTrue((stage / "td.json").is_file())
- self.assertTrue((stage / "collect-binary921.ps1").is_file())
- self.assertTrue((stage / "tools" / "collect_j6_binary921.py").is_file())
- self.assertTrue((stage / "tools" / "binary921.py").is_file())
- self.assertTrue((stage / "tools" / "bmc_replay_uart.py").is_file())
- self.assertTrue((stage / "START-HERE.zh-CN.md").is_file())
- self.assertTrue((stage / "sha256-inventory.json").is_file())
- self.assertTrue((Path(tmp) / f"{package_name}.zip").is_file())
- self.assertTrue((Path(tmp) / f"{package_name}.zip.sha256.txt").is_file())
- self.assertEqual((stage / "j6bin.bit").read_bytes(), bitstream.read_bytes())
- start_here = (stage / "START-HERE.zh-CN.md").read_text(encoding="utf-8-sig")
- self.assertIn("collector first, then PROGRAM_SRAM", start_here)
- self.assertIn("JTAG speed 200k", start_here)
- self.assertIn("board power", start_here)
- self.assertIn(".\\j6bin.bit", start_here)
- self.assertIn("-File .\\collect-binary921.ps1", start_here)
- self.assertIn("-BmcReplayReceipt .\\bmc-replay-session.json", start_here)
- self.assertIn(profile, start_here)
- self.assertIn("binary921", start_here)
- self.assertIn("COM8", start_here)
- self.assertIn("COM7", start_here)
- self.assertIn("COM9", start_here)
- self.assertNotIn("Set-ExecutionPolicy", start_here)
- self.assertNotIn("pip install", start_here.lower())
- manifest = json.loads((stage / "manifest.json").read_text(encoding="utf-8-sig"))
- expected_status = (
- "pass"
- if profile == "debug-photo-bmc-replay-binary921"
- else "blocked_waiting_for_uart1_uart2_access"
- )
- self.assertEqual(manifest["status"], expected_status)
- self.assertEqual(manifest["protocol"], "binary921")
- self.assertEqual(manifest["pin_profile"], profile)
- self.assertEqual(manifest["jtag_programming"]["jtag_speed_hz"], 200000)
- self.assertEqual(manifest["jtag_programming"]["board_power_present_before_program"], True)
- self.assertEqual(manifest["jtag_programming"]["program_mode"], "PROGRAM_SRAM")
- self.assertEqual(manifest["bitstream"]["path"], "j6bin.bit")
- self.assertEqual(manifest["bmc_source"], "pc_replay_from_real_bmc_capture")
- self.assertEqual(manifest["collector"]["bmc_replay_receipt"], "bmc-replay-session.json")
- self.assertEqual(manifest["real_fan_ptc_hardware_status"], "not_run")
- self.assertEqual(manifest["pin_map"]["uart_assignments"]["debug_uart_rx"]["fpga_ball"], expected_debug_rx)
- self.assertEqual(manifest["pin_map"]["uart_assignments"]["debug_uart_tx"]["fpga_ball"], expected_debug_tx)
- inv = json.loads((stage / "sha256-inventory.json").read_text(encoding="utf-8-sig"))
- paths = {item["path"] for item in inv["inventory"]}
- self.assertIn("j6bin.bit", paths)
- self.assertIn("collect-binary921.ps1", paths)
- self.assertIn("tools/collect_j6_binary921.py", paths)
- self.assertIn("tools/binary921.py", paths)
- self.assertIn("tools/bmc_replay_uart.py", paths)
- self.assertNotIn("sha256-inventory.json", paths)
- self.assertFalse(any(part == "__pycache__" for path in stage.rglob("*") for part in path.parts))
- self.assertFalse(any(path.suffix in {".pyc", ".pyo"} for path in stage.rglob("*")))
- def test_binary921_package_script_creates_production_two_uart_package(self) -> None:
- powershell = shutil.which("powershell")
- if powershell is None:
- self.skipTest("PowerShell is not available")
- script = ROOT / "tools" / "package_j6_binary921.ps1"
- with tempfile.TemporaryDirectory() as tmp:
- bitstream = Path(tmp) / "fake-production-binary921.bit"
- td_receipt = Path(tmp) / "td-production-binary921.json"
- payload_path = Path(tmp) / "historical-bmc-payload.json"
- bitstream_bytes = b"fake-production-two-uart-sram-bitstream"
- bitstream.write_bytes(bitstream_bytes)
- bit_sha = hashlib.sha256(bitstream_bytes).hexdigest()
- td_receipt.write_text(
- json.dumps(
- {
- "schema": "td-build-receipt-v1",
- "status": "pass",
- "top": "uart_rs232_j6_host_sensor_real_fan_ptc_production_two_uart_bmc_replay_binary921",
- "top_module": "uart_rs232_j6_host_sensor_real_fan_ptc_production_two_uart_bmc_replay_binary921_top",
- "mode": "implementation",
- "pin_profile": "production-two-uart-bmc-replay-binary921",
- "timing_gate": {"status": "pass"},
- "bitstream": {"sha256": bit_sha},
- }
- ),
- encoding="utf-8",
- )
- historical_reply = (
- "1e 4b ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff "
- "20 19 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff\r\n"
- )
- payload_path.write_text(
- json.dumps(
- {
- "schema": "j6-bmc-replay-payload-v1",
- "status": "pass",
- "source": "real_bmc_capture",
- "bmc_source": "pc_replay_from_real_bmc_capture",
- "live_bmc_link_status": "not_used",
- "reply_text": historical_reply,
- "reply_sha256": "06c173f91f8b6b0e56f9c381b49d5b127d2dbf3a09402843838a0ff2b812f1af",
- "capture_text_sha256": "1" * 64,
- "byte_count": 48,
- "valid_count": 2,
- "missing_count": 22,
- }
- ),
- encoding="utf-8",
- )
- result = subprocess.run(
- [
- powershell,
- "-NoProfile",
- "-ExecutionPolicy",
- "Bypass",
- "-File",
- str(script),
- "-OutputDir",
- tmp,
- "-PackageName",
- "j6prod-2uart-bmc-replay-test",
- "-Profile",
- "production-two-uart-bmc-replay-binary921",
- "-Bitstream",
- str(bitstream),
- "-TdReceipt",
- str(td_receipt),
- "-BmcReplayPayload",
- str(payload_path),
- ],
- cwd=ROOT,
- text=True,
- capture_output=True,
- check=False,
- )
- self.assertEqual(result.returncode, 0, result.stderr + result.stdout)
- stage = Path(tmp) / "j6prod-2uart-bmc-replay-test"
- self.assertTrue((stage / "j6bin.bit").is_file())
- self.assertTrue((stage / "td.json").is_file())
- self.assertTrue((stage / "bmc-replay-payload.json").is_file())
- self.assertTrue((stage / "collect-binary921.ps1").is_file())
- self.assertTrue((Path(tmp) / "j6prod-2uart-bmc-replay-test.zip").is_file())
- start_here = (stage / "START-HERE.zh-CN.md").read_text(encoding="utf-8-sig")
- for marker in [
- "production-two-uart-bmc-replay-binary921",
- "J3",
- "1=TCK",
- "2=GND",
- "3=TDO",
- "4=VREF",
- "5=TMS",
- "9=TDI",
- "10=GND",
- "UART1",
- "L10",
- "M9",
- "UART2",
- "M10",
- "N11",
- "-CombinedPort",
- "不要求重新上电",
- "-Iterations 3",
- "-TimeoutSeconds 600",
- "921600",
- "115200",
- ".\\bmc-replay-payload.json",
- ]:
- self.assertIn(marker, start_here)
- self.assertNotIn("-HostPort COM8 -DebugPort COM7", start_here)
- self.assertNotIn("Set-ExecutionPolicy", start_here)
- self.assertNotIn("pip install", start_here.lower())
- manifest = json.loads((stage / "manifest.json").read_text(encoding="utf-8-sig"))
- self.assertEqual(manifest["status"], "pass")
- self.assertEqual(manifest["pin_profile"], "production-two-uart-bmc-replay-binary921")
- self.assertEqual(manifest["transport"], "combined_host_debug_uart")
- self.assertEqual(manifest["combined_uart_baud"], 921600)
- self.assertEqual(manifest["bmc_replay_uart_baud"], 115200)
- self.assertEqual(manifest["pin_map"]["uart_assignments"]["bmc_replay_uart_tx"]["fpga_ball"], "L10")
- self.assertEqual(manifest["pin_map"]["uart_assignments"]["bmc_replay_uart_rx"]["fpga_ball"], "M9")
- self.assertEqual(manifest["pin_map"]["uart_assignments"]["combined_debug_host_uart_tx"]["fpga_ball"], "M10")
- self.assertEqual(manifest["pin_map"]["uart_assignments"]["combined_debug_host_uart_rx"]["fpga_ball"], "N11")
- self.assertEqual(manifest["bmc_replay_payload"]["reply_sha256"], "06c173f91f8b6b0e56f9c381b49d5b127d2dbf3a09402843838a0ff2b812f1af")
- self.assertEqual(manifest["bitstream"]["sha256"], bit_sha)
- self.assertFalse(manifest["jtag_programming"]["power_cycle_required"])
- self.assertEqual(manifest["bmc_replay_payload"]["valid_count"], 2)
- self.assertEqual(manifest["bmc_replay_payload"]["missing_count"], 22)
- self.assertEqual(manifest["real_fan_ptc_hardware_status"], "not_run")
- paths = {item["path"] for item in json.loads((stage / "sha256-inventory.json").read_text(encoding="utf-8-sig"))["inventory"]}
- self.assertIn("bmc-replay-payload.json", paths)
- self.assertIn("collect-binary921.ps1", paths)
- self.assertIn("tools/collect_j6_binary921.py", paths)
- def test_binary921_production_package_rejects_unbound_td_receipt_and_payload_hash(self) -> None:
- powershell = shutil.which("powershell")
- if powershell is None:
- self.skipTest("PowerShell is not available")
- script = ROOT / "tools" / "package_j6_binary921.ps1"
- with tempfile.TemporaryDirectory() as tmp:
- bitstream = Path(tmp) / "fake-production-binary921.bit"
- td_receipt = Path(tmp) / "td-production-binary921.json"
- payload_path = Path(tmp) / "historical-bmc-payload.json"
- bitstream.write_bytes(b"fake-production-two-uart-sram-bitstream")
- td_receipt.write_text(json.dumps({"schema": "td-build-receipt-v1", "status": "pass"}), encoding="utf-8")
- payload_path.write_text(
- json.dumps(
- {
- "schema": "j6-bmc-replay-payload-v1",
- "status": "pass",
- "source": "real_bmc_capture",
- "bmc_source": "pc_replay_from_real_bmc_capture",
- "reply_text": "1e 4b\r\n",
- "reply_sha256": "0" * 64,
- "capture_text_sha256": "1" * 64,
- "byte_count": 48,
- "valid_count": 2,
- "missing_count": 22,
- }
- ),
- encoding="utf-8",
- )
- result = subprocess.run(
- [
- powershell,
- "-NoProfile",
- "-ExecutionPolicy",
- "Bypass",
- "-File",
- str(script),
- "-OutputDir",
- tmp,
- "-PackageName",
- "j6prod-2uart-bmc-replay-test",
- "-Profile",
- "production-two-uart-bmc-replay-binary921",
- "-Bitstream",
- str(bitstream),
- "-TdReceipt",
- str(td_receipt),
- "-BmcReplayPayload",
- str(payload_path),
- ],
- cwd=ROOT,
- text=True,
- capture_output=True,
- check=False,
- )
- self.assertNotEqual(result.returncode, 0)
- self.assertIn("TD receipt", result.stderr + result.stdout)
- def test_j6_host_sensor_real_fan_ptc_package_output_contains_bmc_replay_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, expected in [
- (
- "debug-photo-uart-bmc-replay",
- "j6-bmc-replay-debug-test",
- {
- "host_ports": "-HostPort COM8 -DebugPort COM7 -BmcReplayPort COM9",
- "bmc_tx": "T4",
- "bmc_rx": "R5",
- "hardware_access_status": "photo_visible_header",
- "ptc_note": "PTC03/PTC04/PTC17/PTC18/PTC21/PTC22",
- },
- ),
- (
- "formal-uart1-bmc-replay",
- "j6-bmc-replay-formal-test",
- {
- "host_ports": "-HostPort COM8 -DebugPort COM7 -BmcReplayPort COM9",
- "bmc_tx": "L10",
- "bmc_rx": "M9",
- "hardware_access_status": "blocked_waiting_for_uart1_uart2_access",
- "ptc_note": "HEAT/PTC/FAN",
- },
- ),
- ]:
- 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
- short_bit = stage / "j6tmp.bit"
- short_collect = stage / "collect.ps1"
- short_td = stage / "td.json"
- self.assertTrue((stage / "START-HERE.zh-CN.md").is_file())
- self.assertTrue(short_bit.is_file())
- self.assertTrue(short_collect.is_file())
- self.assertTrue(short_td.is_file())
- self.assertTrue((stage / "collector" / "collect-j6-host-sensor-real-fan-ptc.ps1").is_file())
- self.assertTrue((stage / "bmc-replay" / "bmc_replay_uart.py").is_file())
- self.assertTrue((stage / "capture-bmc.ps1").is_file())
- self.assertTrue((stage / "replay-bmc.ps1").is_file())
- self.assertTrue((stage / "bmc-replay-payload.example.json").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.assertEqual(short_bit.read_bytes(), bitstream.read_bytes())
- self.assertEqual(json.loads(short_td.read_text(encoding="utf-8-sig"))["status"], "pass")
- self.assertLess(len(str(short_bit)), 100)
- 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("先准备并启动 BMC replay", 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(expected["host_ports"], start_here)
- self.assertIn("pc_replay_from_real_bmc_capture", start_here)
- self.assertIn("collector_protocol_profile=temp-uart-ptc-remap", start_here)
- self.assertIn("JTAG speed 200k", start_here)
- self.assertIn("board power", start_here)
- self.assertIn(expected["bmc_tx"], start_here)
- self.assertIn(expected["bmc_rx"], start_here)
- self.assertIn("capture-bmc.ps1", start_here)
- self.assertIn("replay-bmc.ps1", start_here)
- self.assertLess(start_here.index("replay-bmc.ps1"), start_here.index("collect.ps1"))
- self.assertLess(start_here.index("collect.ps1"), start_here.index("PROGRAM_SRAM"))
- self.assertIn("bmc-replay-payload.example.json", start_here)
- self.assertIn("Python", start_here)
- self.assertIn("does not install Python/pip/driver", start_here)
- self.assertIn(expected["ptc_note"], start_here)
- if profile == "formal-uart1-bmc-replay":
- self.assertNotIn("PTC03/PTC04/PTC17/PTC18/PTC21/PTC22 使用临时", start_here)
- self.assertIn(".\\j6tmp.bit", start_here)
- self.assertIn(".\\td.json", start_here)
- self.assertIn("-File .\\collect.ps1", start_here)
- self.assertIn("Cannot open file", start_here)
- self.assertIn("bitstreams", start_here)
- self.assertNotIn(f".\\bitstreams\\{bitstream.name}", start_here)
- self.assertNotIn(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.assertIn("tail drain", start_here)
- self.assertIn("[中文 runbook](docs/j6-host-sensor-real-fan-ptc-debug921-runbook.zh-CN.md)", start_here)
- self.assertIn("[collector 脚本](collector/collect-j6-host-sensor-real-fan-ptc.ps1)", start_here)
- self.assertIn("[SHA256 inventory](sha256-inventory.json)", 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 .\\collect.ps1", collect_template)
- shortcut = short_collect.read_text(encoding="utf-8-sig")
- self.assertIn("$PSHOME", shortcut)
- self.assertIn("$PSScriptRoot", shortcut)
- self.assertIn('"-File"', shortcut)
- self.assertIn('Join-Path $packageRoot "collector\\collect-j6-host-sensor-real-fan-ptc.ps1"', shortcut)
- self.assertIn('[string]$Bitstream = ".\\j6tmp.bit"', shortcut)
- self.assertIn('[string]$TdReceipt = ".\\td.json"', shortcut)
- self.assertIn('"-Bitstream"', shortcut)
- self.assertIn('"-TdReceipt"', shortcut)
- self.assertIn("[switch]$SelfTest", shortcut)
- self.assertNotIn("Set-ExecutionPolicy", shortcut)
- self.assertNotIn("-AssumeManualSramProgrammed", shortcut)
- 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.assertIn("j6-bmc-replay", manifest["package_name"])
- self.assertEqual(manifest["collector"]["user_profile_argument"], profile)
- self.assertEqual(manifest["collector"]["collector_protocol_profile"], "temp-uart-ptc-remap")
- self.assertEqual(manifest["collector"]["ready_profile_string"], "temp-uart-ptc-remap")
- self.assertEqual(manifest["bmc_source"], "pc_replay_from_real_bmc_capture")
- self.assertEqual(manifest["live_bmc_link_status"], "not_used")
- self.assertIn("Python", manifest["remote_dependencies"])
- self.assertIn("no pip setup", manifest["remote_dependencies"])
- self.assertIn("no driver", manifest["remote_dependencies"])
- self.assertEqual(manifest["pin_map"]["hardware_access_status"], expected["hardware_access_status"])
- self.assertEqual(manifest["pin_map"]["uart_assignments"]["bmc_replay_uart_tx"]["fpga_ball"], expected["bmc_tx"])
- self.assertEqual(manifest["pin_map"]["uart_assignments"]["bmc_replay_uart_rx"]["fpga_ball"], expected["bmc_rx"])
- self.assertEqual(manifest["programming_mode"], "PROGRAM_SRAM")
- self.assertEqual(manifest["jtag_programming"]["jtag_speed_hz"], 200000)
- self.assertEqual(manifest["jtag_programming"]["board_power_present_before_program"], True)
- self.assertEqual(manifest["jtag_programming"]["program_mode"], "PROGRAM_SRAM")
- self.assertEqual(manifest["bitstream"]["path"], "j6tmp.bit")
- self.assertEqual(manifest["td_receipt"]["path"], "td.json")
- self.assertEqual(manifest["short_path_aliases"]["bitstream"]["source"], f"bitstreams/{bitstream.name}")
- self.assertEqual(manifest["short_path_aliases"]["td_receipt"]["source"], f"td-receipts/{td_receipt.name}")
- self.assertIn("host_control_commands", manifest)
- self.assertIn("pin_map", manifest)
- self.assertIn("bmc_replay", manifest)
- self.assertIn("tail_drain", 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("j6tmp.bit", inventory_paths)
- self.assertIn("collect.ps1", inventory_paths)
- self.assertIn("td.json", inventory_paths)
- self.assertIn("collector/collect-j6-host-sensor-real-fan-ptc.ps1", inventory_paths)
- self.assertIn("bmc-replay/bmc_replay_uart.py", inventory_paths)
- self.assertIn("capture-bmc.ps1", inventory_paths)
- self.assertIn("replay-bmc.ps1", inventory_paths)
- self.assertIn("bmc-replay-payload.example.json", 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_package_script_creates_formal_blocked_package_without_bitstream(self) -> None:
- powershell = shutil.which("powershell")
- if powershell is None:
- self.skipTest("PowerShell is not available")
- with tempfile.TemporaryDirectory() as tmp:
- td_receipt = Path(tmp) / "td-formal-fail.json"
- td_receipt.write_text(
- json.dumps(
- {
- "schema": "td-build-receipt-v1",
- "status": "fail",
- "top": "uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart1_bmc_replay_debug921",
- "pin_profile": "formal-uart1-bmc-replay",
- "phy": {"log_has_error": True},
- "bitstream": None,
- }
- ),
- encoding="utf-8",
- )
- result = subprocess.run(
- [
- powershell,
- "-NoProfile",
- "-ExecutionPolicy",
- "Bypass",
- "-File",
- str(ROOT / "tools" / "package_j6_host_sensor_real_fan_ptc_debug921.ps1"),
- "-OutputDir",
- tmp,
- "-PackageName",
- "j6-bmc-replay-formal-blocked-test",
- "-Profile",
- "formal-uart1-bmc-replay",
- "-TdReceipt",
- str(td_receipt),
- "-FormalBlocked",
- ],
- 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) / "j6-bmc-replay-formal-blocked-test"
- self.assertTrue(stage.is_dir())
- self.assertFalse((stage / "j6tmp.bit").exists())
- self.assertFalse((stage / "collect.ps1").exists())
- self.assertTrue((stage / "FORMAL-BLOCKED.zh-CN.md").is_file())
- self.assertTrue((stage / "START-HERE.zh-CN.md").is_file())
- self.assertTrue((stage / "td.json").is_file())
- self.assertTrue((Path(tmp) / "j6-bmc-replay-formal-blocked-test.zip").is_file())
- start_here = (stage / "START-HERE.zh-CN.md").read_text(encoding="utf-8-sig")
- self.assertIn("blocked_td_mslice_over_limit", start_here)
- self.assertIn("1137", start_here)
- self.assertIn("1131", start_here)
- self.assertIn("1120", start_here)
- self.assertIn("不能刷机", start_here)
- self.assertNotIn("PROGRAM_SRAM", start_here)
- self.assertNotIn("j6tmp.bit", start_here)
- manifest = json.loads((stage / "manifest.json").read_text(encoding="utf-8-sig"))
- self.assertEqual(manifest["status"], "blocked_td_mslice_over_limit")
- self.assertEqual(manifest["pin_profile"], "formal-uart1-bmc-replay")
- self.assertEqual(manifest["bitstream"], None)
- self.assertEqual(manifest["real_fan_ptc_hardware_status"], "not_run")
- self.assertEqual(manifest["bmc_source"], "pc_replay_from_real_bmc_capture")
- self.assertEqual(manifest["blocked_reason"]["latest_attempt_mslices"], 1137)
- self.assertEqual(manifest["blocked_reason"]["best_observed_mslices"], 1131)
- self.assertEqual(manifest["pin_map"]["uart_assignments"]["debug_uart_tx"]["fpga_ball"], "N14")
- self.assertEqual(manifest["pin_map"]["uart_assignments"]["debug_uart_rx"]["fpga_ball"], "P15")
- inventory = json.loads((stage / "sha256-inventory.json").read_text(encoding="utf-8-sig"))
- inventory_paths = {item["path"] for item in inventory["inventory"]}
- self.assertIn("FORMAL-BLOCKED.zh-CN.md", inventory_paths)
- self.assertIn("td.json", inventory_paths)
- self.assertNotIn("j6tmp.bit", 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",
- "JTAG speed 200k",
- "board_power_present_before_program",
- "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"})
- programming_props = schema["properties"]["programming"]["properties"]
- self.assertEqual(programming_props["jtag_speed_hz"], {"const": 200000})
- self.assertEqual(programming_props["board_power_present_before_program"], {"const": True})
- manual_props = layers["manual_sram_programming"]["properties"]
- self.assertEqual(manual_props["jtag_speed_hz"], {"const": 200000})
- self.assertEqual(manual_props["board_power_present_before_program"], {"const": True})
- 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()
|