test_product_regression.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. from __future__ import annotations
  2. import copy
  3. import sys
  4. from pathlib import Path
  5. import pytest
  6. ROOT = Path(__file__).resolve().parents[2]
  7. VIEWER_ROOT = ROOT / "tools" / "board-viewer"
  8. sys.path.insert(0, str(VIEWER_ROOT))
  9. from board_viewer.regression import BoardRegressionError, validate_product_regression # noqa: E402
  10. FOUR_CONTACT_REFS = {
  11. "CON12", "CON30", "CON31", "CON32", "CON33", "CON34", "CON35", "CON36",
  12. "CON37", "CON38", "CON39", "CON40", "CON54", "CON58", "CON59", "CON60",
  13. "CON61", "CON62", "CON63", "CON64", "CON65", "CON66", "CON67", "CON68",
  14. "CON69", "CON70", "CON77", "CON78",
  15. }
  16. THREE_CONTACT_REFS = {
  17. "CON53", "CON55", "CON56", "CON57", "CON79", "CON80", "CON81", "CON82",
  18. "CON83", "CON84", "CON85", "CON86", "CON87", "CON88", "CON89", "CON90",
  19. "CON91", "CON92", "CON93", "CON94", "CON95", "CON96", "CON97", "CON98",
  20. }
  21. FOURTEEN_CONTACT_REFS = {"CON18", "CON27", "CON28", "CON29"}
  22. POWER_CONTACT_REFS = {"CON2", "CON23"}
  23. FAN_CONTACT_REFS = {"CON8", "CON24", "CON25", "CON26"}
  24. J3_GRID = [["6", "1"], ["7", "2"], ["8", "3"], ["9", "4"], ["10", "5"]]
  25. J3_NETS = {
  26. "1": "N9532014",
  27. "2": "GND",
  28. "3": "N9532092",
  29. "4": "N9532034",
  30. "5": "N9532142",
  31. "6": "Net_649",
  32. "7": "Net_650",
  33. "8": "Net_648",
  34. "9": "N9532240",
  35. "10": "GND",
  36. }
  37. J3_SIGNALS = {
  38. "1": ("FPGA_TCK", "A7", "input", "jtag_tck", "R63"),
  39. "3": ("FPGA_TDO", "C6", "output", "jtag_tdo", "R65"),
  40. "5": ("FPGA_TMS", "B8", "input", "jtag_tms", "R67"),
  41. "9": ("FPGA_TDI", "A6", "input", "jtag_tdi", "R69"),
  42. }
  43. def expected_connector_contract(reference: str) -> tuple[str, list[list[str]], list[str], int]:
  44. if reference in FOUR_CONTACT_REFS:
  45. order = ["1", "2", "3", "4"] if reference in {"CON54", "CON77", "CON78"} else ["4", "3", "2", "1"]
  46. return "CON_11251W00_NPX_SX_4P", [[number] for number in order], ["5", "6"], 0
  47. if reference in THREE_CONTACT_REFS:
  48. return "CON_51541_003_P1D25", [["3", "2", "1"]], ["4", "5"], 0
  49. if reference in FOURTEEN_CONTACT_REFS:
  50. return (
  51. "CON_3110_14P_P2D54",
  52. [
  53. ["13", "11", "9", "7", "5", "3", "1"],
  54. ["14", "12", "10", "8", "6", "4", "2"],
  55. ],
  56. [],
  57. 0,
  58. )
  59. if reference == "CON23":
  60. return "CON_C22930_1084N_X", [["5", "1"], ["6", "2"], ["7", "3"], ["8", "4"]], ["9", "10"], 2
  61. if reference == "CON2":
  62. return "CON_C22930_1084N_X", [["4", "8"], ["3", "7"], ["2", "6"], ["1", "5"]], ["9", "10"], 2
  63. if reference in FAN_CONTACT_REFS:
  64. return "CON_PZGM_B03_08P", [[str(number)] for number in range(8, 0, -1)], [], 1
  65. raise AssertionError(f"missing test connector contract for {reference}")
  66. def connector_fixture(reference: str) -> dict[str, object]:
  67. profile, grid, shields, mechanical_count = expected_connector_contract(reference)
  68. contact_order = [number for row in grid for number in row]
  69. pins: list[dict[str, object]] = []
  70. for board_order, number in enumerate(contact_order, start=1):
  71. row = next(index for index, values in enumerate(grid, start=1) if number in values)
  72. pins.append(
  73. {
  74. "id": f"{reference}.contact-{number}",
  75. "number": number,
  76. "pad_role": "contact",
  77. "row": row,
  78. "column": grid[row - 1].index(number) + 1,
  79. "board_order": board_order,
  80. "net": f"{reference}_{number}",
  81. "path": [],
  82. "fpga": None,
  83. "mechanical": False,
  84. "electrical": True,
  85. "reserved": False,
  86. "function_category": "unknown",
  87. "evidence_tier": "board_database",
  88. "programming": {
  89. "status": "board_only",
  90. "conclusion": f"Board-only {reference}.{number}",
  91. "network_explanation": f"Raw network {reference}_{number}",
  92. "hdl_guidance": "No verified FPGA path",
  93. "connection_guidance": ["Verify before connecting"],
  94. "constraints": [],
  95. "risks": ["Name is not proof"],
  96. "evidence_tier": "board_database",
  97. "sources": ["fixture"],
  98. },
  99. "recommendation": {"eligible": False, "reasons": ["pin_evidence_not_verified"]},
  100. }
  101. )
  102. pins.extend(
  103. {
  104. "id": f"{reference}.shield-{number}",
  105. "number": number,
  106. "pad_role": "shield",
  107. "row": None,
  108. "column": None,
  109. "board_order": None,
  110. "net": "GND",
  111. "path": [],
  112. "fpga": None,
  113. "mechanical": False,
  114. "electrical": True,
  115. "reserved": False,
  116. "function_category": "ground",
  117. "evidence_tier": "board_database",
  118. "programming": {
  119. "status": "not_programmable",
  120. "conclusion": "Shield pad",
  121. "network_explanation": "Grounded shell",
  122. "hdl_guidance": "No ADC",
  123. "connection_guidance": ["Not an external contact"],
  124. "constraints": [],
  125. "risks": ["Do not count as a pin"],
  126. "evidence_tier": "board_database",
  127. "sources": ["fixture"],
  128. },
  129. "recommendation": {"eligible": False, "reasons": ["not_connector_contact"]},
  130. }
  131. for number in shields
  132. )
  133. pins.extend(
  134. {
  135. "id": f"{reference}.mechanical-{index}",
  136. "number": "",
  137. "pad_role": "mechanical",
  138. "row": None,
  139. "column": None,
  140. "board_order": None,
  141. "net": None,
  142. "path": [],
  143. "fpga": None,
  144. "mechanical": True,
  145. "electrical": False,
  146. "reserved": False,
  147. "function_category": "unknown",
  148. "evidence_tier": "board_database",
  149. "programming": {
  150. "status": "not_programmable",
  151. "conclusion": "Mechanical hole",
  152. "network_explanation": "No electrical net",
  153. "hdl_guidance": "No ADC",
  154. "connection_guidance": ["Do not wire"],
  155. "constraints": [],
  156. "risks": ["Mechanical only"],
  157. "evidence_tier": "board_database",
  158. "sources": ["fixture"],
  159. },
  160. "recommendation": {"eligible": False, "reasons": ["mechanical_or_non_electrical"]},
  161. }
  162. for index in range(1, mechanical_count + 1)
  163. )
  164. return {
  165. "reference": reference,
  166. "side": "front",
  167. "connector": {
  168. "profile": profile,
  169. "review_status": "cross_verified",
  170. "view": "board_front",
  171. "contact_count": len(contact_order),
  172. "auxiliary_pad_count": len(shields) + mechanical_count,
  173. "rows": len(grid),
  174. "columns": len(grid[0]),
  175. "contact_grid": grid,
  176. "contact_order": contact_order,
  177. "sources": ["test cross-check"],
  178. },
  179. "pins": pins,
  180. }
  181. def j3_fixture() -> dict[str, object]:
  182. order = [number for row in J3_GRID for number in row]
  183. pins: list[dict[str, object]] = []
  184. for board_order, number in enumerate(order, start=1):
  185. row = next(index for index, values in enumerate(J3_GRID, start=1) if number in values)
  186. signal = J3_SIGNALS.get(number)
  187. fpga = None
  188. if signal is not None:
  189. board_signal, ball, direction, function_category, series_resistor = signal
  190. fpga = {
  191. "ball": ball,
  192. "board_signal": board_signal,
  193. "io_standard": "Dedicated JTAG (VREF 3.3V)",
  194. "capabilities": ["jtag", function_category],
  195. "evidence_tier": "cross_verified",
  196. "sources": ["fixture schematic and PCB"],
  197. }
  198. programming = {
  199. "status": "verified_fpga",
  200. "conclusion": f"{board_signal} dedicated JTAG path to U3.{ball}",
  201. "network_explanation": f"J3.{number} reaches {board_signal} through reviewed protection and series parts",
  202. "hdl_guidance": "Dedicated FPGA configuration pin; do not declare it as a normal RTL GPIO or ADC pin.",
  203. "connection_guidance": ["Connect only to the matching JTAG probe signal."],
  204. "constraints": ["No user ADC assignment"],
  205. "risks": ["Check cable orientation and target VREF before programming."],
  206. "evidence_tier": "cross_verified",
  207. "sources": ["fixture schematic and PCB"],
  208. }
  209. summary = board_signal.removeprefix("FPGA_")
  210. path = [f"J3.{number}", f"{series_resistor} 22R", board_signal, f"U3.{ball}"]
  211. elif number in {"2", "10"}:
  212. direction, function_category, summary = "passive", "ground", "GND"
  213. path = [f"J3.{number}", "GND"]
  214. programming = {
  215. "status": "not_programmable",
  216. "conclusion": "JTAG ground reference",
  217. "network_explanation": f"J3.{number} is board GND",
  218. "hdl_guidance": "No RTL or ADC assignment",
  219. "connection_guidance": ["Connect to probe ground."],
  220. "constraints": [],
  221. "risks": ["Maintain a common reference."],
  222. "evidence_tier": "cross_verified",
  223. "sources": ["fixture schematic and PCB"],
  224. }
  225. elif number == "4":
  226. direction, function_category, summary = "passive", "reference_voltage", "VREF"
  227. path = ["J3.4", "N9532034", "R61 0R", "+3V3"]
  228. programming = {
  229. "status": "not_programmable",
  230. "conclusion": "VREF is a 3.3V target reference, not board power.",
  231. "network_explanation": "J3.4 reaches +3V3 through R61 0R and local decoupling.",
  232. "hdl_guidance": "No RTL or ADC assignment",
  233. "connection_guidance": ["Probe senses this voltage; do not use it to power the board."],
  234. "constraints": [],
  235. "risks": ["Back-powering can damage hardware."],
  236. "evidence_tier": "cross_verified",
  237. "sources": ["fixture schematic and PCB"],
  238. }
  239. else:
  240. direction, function_category, summary = "passive", "not_connected", "NC"
  241. path = [f"J3.{number}", "NC"]
  242. programming = {
  243. "status": "not_programmable",
  244. "conclusion": "Unconnected JTAG header position",
  245. "network_explanation": f"J3.{number} has no path beyond the connector pad.",
  246. "hdl_guidance": "No RTL or ADC assignment",
  247. "connection_guidance": ["Leave unconnected."],
  248. "constraints": [],
  249. "risks": ["Do not repurpose without a board revision."],
  250. "evidence_tier": "cross_verified",
  251. "sources": ["fixture schematic and PCB"],
  252. }
  253. pins.append(
  254. {
  255. "id": f"J3.pad-{number}",
  256. "number": number,
  257. "pad_role": "contact",
  258. "row": row,
  259. "column": J3_GRID[row - 1].index(number) + 1,
  260. "board_order": board_order,
  261. "net": J3_NETS[number],
  262. "path": path,
  263. "fpga": fpga,
  264. "mechanical": False,
  265. "electrical": True,
  266. "direction": direction,
  267. "external_level": "0V" if function_category == "ground" else "3.3V JTAG",
  268. "reserved": True,
  269. "fixed_load_conflict": False,
  270. "function_category": function_category,
  271. "evidence_tier": "cross_verified",
  272. "programming": programming,
  273. "recommendation": {"eligible": False, "reasons": ["reserved"]},
  274. "summary": summary,
  275. }
  276. )
  277. return {
  278. "reference": "J3",
  279. "side": "front",
  280. "summary": "FPGA JTAG 调试/配置接口(专用配置脚)",
  281. "connector": {
  282. "profile": "J3_FPGA_JTAG_2X5",
  283. "review_status": "cross_verified",
  284. "view": "board_front",
  285. "contact_count": 10,
  286. "auxiliary_pad_count": 0,
  287. "rows": 5,
  288. "columns": 2,
  289. "contact_grid": J3_GRID,
  290. "contact_order": order,
  291. "sources": ["fixture schematic and PCB"],
  292. },
  293. "pins": pins,
  294. }
  295. def touchpoint(payload: dict[str, object], reference: str) -> dict[str, object]:
  296. return next(item for item in payload["touchpoints"] if item["reference"] == reference)
  297. def pin(payload: dict[str, object], reference: str, number: str) -> dict[str, object]:
  298. return next(item for item in touchpoint(payload, reference)["pins"] if item["number"] == number)
  299. def product_payload() -> dict[str, object]:
  300. connector_references = sorted(
  301. FOUR_CONTACT_REFS | THREE_CONTACT_REFS | FOURTEEN_CONTACT_REFS | POWER_CONTACT_REFS | FAN_CONTACT_REFS
  302. )
  303. touchpoints = [connector_fixture(reference) for reference in connector_references]
  304. con78 = next(item for item in touchpoints if item["reference"] == "CON78")
  305. pins = {pin["number"]: pin for pin in con78["pins"] if pin["number"]}
  306. pins["1"].update(
  307. {
  308. "net": "RS232_TX2",
  309. "path": ["CON78.1 RS232_TX2", "U23 TRSF3232EIPWR", "UART2_TX", "FPGA M10"],
  310. "fpga": {"ball": "M10", "evidence_tier": "cross_verified"},
  311. "reserved": True,
  312. "function_category": "uart_tx",
  313. "evidence_tier": "cross_verified",
  314. "recommendation": {"eligible": False, "reasons": ["reserved"]},
  315. "programming": {
  316. "status": "verified_fpga",
  317. "conclusion": "FPGA output UART2_TX M10 through U23",
  318. "network_explanation": "RS232_TX2 through U23 to UART2_TX",
  319. "hdl_guidance": "output LVCMOS33",
  320. "connection_guidance": ["Connect to peer RX", "Do not connect to 3.3V TTL"],
  321. "constraints": ["LOCATION = M10", "IOSTANDARD = LVCMOS33"],
  322. "risks": ["reserved", "check current constraints"],
  323. "evidence_tier": "cross_verified",
  324. "sources": ["fixture"],
  325. },
  326. }
  327. )
  328. pins["2"].update(
  329. {
  330. "net": "RS232_RX2",
  331. "path": ["CON78.2 RS232_RX2", "U23 TRSF3232EIPWR", "UART2_RX", "FPGA N11"],
  332. "fpga": {"ball": "N11", "evidence_tier": "cross_verified"},
  333. "reserved": True,
  334. "function_category": "uart_rx",
  335. "evidence_tier": "cross_verified",
  336. "recommendation": {"eligible": False, "reasons": ["reserved"]},
  337. "programming": {
  338. "status": "verified_fpga",
  339. "conclusion": "FPGA input UART2_RX N11 through U23",
  340. "network_explanation": "RS232_RX2 through U23 to UART2_RX",
  341. "hdl_guidance": "input LVCMOS33",
  342. "connection_guidance": ["Connect to peer TX", "Do not connect to 3.3V TTL"],
  343. "constraints": ["LOCATION = N11", "IOSTANDARD = LVCMOS33"],
  344. "risks": ["reserved", "check current constraints"],
  345. "evidence_tier": "cross_verified",
  346. "sources": ["fixture"],
  347. },
  348. }
  349. )
  350. for number in ("3", "4"):
  351. pins[number].update({"net": "GND", "path": [f"CON78.{number} GND", "Board ground"], "function_category": "ground"})
  352. con30 = next(item for item in touchpoints if item["reference"] == "CON30")
  353. con30_pin4 = next(pin for pin in con30["pins"] if pin["number"] == "4")
  354. con30_pin4.update(
  355. {
  356. "net": "FAN_GPIO4",
  357. "summary": "MOTOR_EN_N",
  358. "direction": "output",
  359. "external_level": "3.3V LVCMOS",
  360. "active_level": "low",
  361. "board_pull": "R937 4.7K to +3V3",
  362. "evidence_tier": "cross_verified",
  363. "fpga": {"ball": "A10", "board_signal": "MOTOR_EN_N", "io_standard": "LVCMOS33", "evidence_tier": "cross_verified"},
  364. "programming": {
  365. "status": "verified_fpga",
  366. "conclusion": "FPGA output MOTOR_EN_N A10",
  367. "network_explanation": "FAN_GPIO4 maps to MOTOR_EN_N",
  368. "hdl_guidance": "output LVCMOS33 low active",
  369. "connection_guidance": ["board output"],
  370. "constraints": ["LOCATION = A10", "IOSTANDARD = LVCMOS33", "有效电平:低电平"],
  371. "risks": ["reserved", "check current constraints"],
  372. "evidence_tier": "cross_verified",
  373. "sources": ["fixture"],
  374. },
  375. }
  376. )
  377. con31 = next(item for item in touchpoints if item["reference"] == "CON31")
  378. con31_pin4 = next(pin for pin in con31["pins"] if pin["number"] == "4")
  379. con31_pin4.update(
  380. {
  381. "net": "N9971986",
  382. "summary": "fan PWM open-collector output",
  383. "path": ["CON31.4 N9971986", "Q105 collector", "Q105 base = FAN_GPIO6", "R665", "U3.E10"],
  384. "evidence_tier": "cross_verified",
  385. "external_level": "open-collector fan control",
  386. "function_category": "pwm",
  387. "reserved": False,
  388. "fixed_load_conflict": False,
  389. "polarity": "FPGA high -> Q105 on -> connector low",
  390. "fpga": {
  391. "ball": "E10",
  392. "board_signal": "FAN_GPIO6",
  393. "io_standard": "LVCMOS33",
  394. "capabilities": ["gpio", "pwm_output", "fan_pwm"],
  395. "evidence_tier": "cross_verified",
  396. },
  397. "programming": {
  398. "status": "verified_fpga",
  399. "conclusion": "FPGA E10 drives FAN_GPIO6 through Q105 to CON31.4",
  400. "network_explanation": "N9971986 is the Q105 collector side, not the FPGA logic net",
  401. "hdl_guidance": "output LVCMOS33; FPGA high pulls connector low",
  402. "connection_guidance": ["use as open-collector fan PWM"],
  403. "constraints": ["LOCATION = E10", "IOSTANDARD = LVCMOS33"],
  404. "risks": ["inverted at Q105", "check current constraints"],
  405. "evidence_tier": "cross_verified",
  406. "sources": ["fixture"],
  407. },
  408. }
  409. )
  410. con58 = next(item for item in touchpoints if item["reference"] == "CON58")
  411. con58_pin4 = next(pin for pin in con58["pins"] if pin["number"] == "4")
  412. con58_pin4.update(
  413. {
  414. "net": "FAN_GPIO38",
  415. "summary": "MOTOR_STEP rising-edge pulse output",
  416. "direction": "output",
  417. "external_level": "3.3V LVCMOS",
  418. "function_category": "motor_step",
  419. "active_level": "rising_edge",
  420. "reserved": True,
  421. "fixed_load_conflict": True,
  422. "evidence_tier": "cross_verified",
  423. "fpga": {
  424. "ball": "D15",
  425. "board_signal": "MOTOR_STEP",
  426. "io_standard": "LVCMOS33",
  427. "evidence_tier": "cross_verified",
  428. },
  429. "programming": {
  430. "status": "verified_fpga",
  431. "conclusion": "MOTOR_STEP D15 is a pulse output, not a level enable",
  432. "network_explanation": "FAN_GPIO38 maps to MOTOR_STEP through R698",
  433. "hdl_guidance": "output pulses; each 上升沿 is one step event",
  434. "connection_guidance": ["connect to STEP input"],
  435. "constraints": ["LOCATION = D15", "IOSTANDARD = LVCMOS33"],
  436. "risks": ["verify pulse timing"],
  437. "evidence_tier": "cross_verified",
  438. "sources": ["fixture"],
  439. },
  440. }
  441. )
  442. con65 = next(item for item in touchpoints if item["reference"] == "CON65")
  443. con65_pin4 = next(pin for pin in con65["pins"] if pin["number"] == "4")
  444. con65_pin4.update(
  445. {
  446. "net": "FAN_GPIO32",
  447. "summary": "MOTOR_DIR direction state output",
  448. "direction": "output",
  449. "external_level": "3.3V LVCMOS",
  450. "function_category": "motor_direction",
  451. "active_level": "state",
  452. "reserved": True,
  453. "fixed_load_conflict": True,
  454. "evidence_tier": "cross_verified",
  455. "fpga": {
  456. "ball": "H14",
  457. "board_signal": "MOTOR_DIR",
  458. "io_standard": "LVCMOS33",
  459. "evidence_tier": "cross_verified",
  460. },
  461. "programming": {
  462. "status": "verified_fpga",
  463. "conclusion": "MOTOR_DIR H14 selects a direction state",
  464. "network_explanation": "FAN_GPIO32 maps to MOTOR_DIR through R692",
  465. "hdl_guidance": "output 方向状态; stabilize before STEP",
  466. "connection_guidance": ["connect to DIR input"],
  467. "constraints": ["LOCATION = H14", "IOSTANDARD = LVCMOS33"],
  468. "risks": ["0/1 mechanical direction depends on wiring"],
  469. "evidence_tier": "cross_verified",
  470. "sources": ["fixture"],
  471. },
  472. }
  473. )
  474. con53 = next(item for item in touchpoints if item["reference"] == "CON53")
  475. con53_pin1 = next(pin for pin in con53["pins"] if pin["number"] == "1")
  476. con53_pin1.update(
  477. {
  478. "function_category": "remote_temperature",
  479. "reserved": True,
  480. "fixed_load_conflict": True,
  481. "evidence_tier": "cross_verified",
  482. "programming": {
  483. "status": "board_only",
  484. "conclusion": "CT7428 remote-diode analog input",
  485. "network_explanation": "temperature is read through TEMP_SCL/TEMP_SDA",
  486. "hdl_guidance": "TEMP I2C must be open-drain and 只拉低或释放",
  487. "connection_guidance": ["connect a remote diode pair"],
  488. "constraints": [],
  489. "risks": ["R811/R812 and other option links require BOM review"],
  490. "evidence_tier": "cross_verified",
  491. "sources": ["fixture"],
  492. },
  493. }
  494. )
  495. j_touchpoints = [{"reference": f"J{number}", "side": "front", "pins": []} for number in range(1, 17)]
  496. j_touchpoints[2] = j3_fixture()
  497. touchpoints.extend(j_touchpoints)
  498. touchpoints.extend({"reference": f"PL{number}", "side": "front", "pins": []} for number in range(1, 4))
  499. touchpoints.extend(
  500. {"reference": f"TP{number}", "side": "front", "pins": []}
  501. for number in [*range(1, 8), *range(9, 31)]
  502. )
  503. tp9 = next(item for item in touchpoints if item["reference"] == "TP9")
  504. tp9["pins"] = [
  505. {
  506. "number": "1",
  507. "pad_role": "contact",
  508. "mechanical": False,
  509. "electrical": True,
  510. "function_category": "mcu_gpio",
  511. "evidence_tier": "cross_verified",
  512. "fpga": None,
  513. "mcu": {
  514. "device": "U27",
  515. "family": "GD32F303CGT6",
  516. "pin": "10",
  517. "signal": "PA0",
  518. "evidence_tier": "cross_verified",
  519. },
  520. "programming": {
  521. "status": "verified_mcu",
  522. "conclusion": "GD32F303CGT6 U27.10 PA0 test point",
  523. "network_explanation": "TP9 maps to U27.10 PA0",
  524. "hdl_guidance": "configure in GD32 firmware",
  525. "connection_guidance": ["use a high-impedance probe"],
  526. "constraints": [],
  527. "risks": ["check current MCU mux"],
  528. "evidence_tier": "cross_verified",
  529. "sources": ["fixture"],
  530. },
  531. "recommendation": {"eligible": False, "reasons": ["not_fpga"]},
  532. }
  533. ]
  534. return {
  535. "counts": {
  536. "footprints": 1052,
  537. "touchpoints": 110,
  538. "pads": 472,
  539. "connector_contacts": 288,
  540. "connector_auxiliary_pads": 116,
  541. "categories": {"CON": 62, "J": 16, "PL": 3, "TP": 29},
  542. "sides": {"front": 110, "back": 0},
  543. },
  544. "touchpoints": touchpoints,
  545. }
  546. def test_current_product_regression_accepts_verified_con78_anchor() -> None:
  547. validate_product_regression(product_payload())
  548. @pytest.mark.parametrize(
  549. "mutation, expected",
  550. [
  551. (lambda payload: payload["counts"].update({"connector_contacts": 287}), "connector_contacts=287"),
  552. (lambda payload: payload["touchpoints"][0]["connector"].update({"review_status": "unknown"}), "not cross-verified"),
  553. (lambda payload: payload["touchpoints"][0]["connector"]["contact_order"].reverse(), "contact order"),
  554. (lambda payload: payload["touchpoints"][0]["pins"][0].update({"pad_role": "shield"}), "contact pin role"),
  555. ],
  556. )
  557. def test_all_connector_profiles_and_board_front_orders_are_regression_anchors(mutation, expected: str) -> None:
  558. payload = copy.deepcopy(product_payload())
  559. mutation(payload)
  560. with pytest.raises(BoardRegressionError, match=expected):
  561. validate_product_regression(payload)
  562. @pytest.mark.parametrize(
  563. "mutation, expected",
  564. [
  565. (lambda payload: payload["counts"].update({"pads": 471}), "pads=471"),
  566. (lambda payload: payload["counts"]["categories"].update({"CON": 61}), "CON=61"),
  567. (lambda payload: payload["counts"]["sides"].update({"back": 1}), "back=1"),
  568. (lambda payload: payload["touchpoints"][1].update({"reference": "CON5"}), "CON5"),
  569. (lambda payload: pin(payload, "CON78", "1").update({"net": "WRONG"}), "CON78.1"),
  570. (lambda payload: pin(payload, "CON78", "2")["fpga"].update({"ball": "M10"}), "N11"),
  571. (lambda payload: pin(payload, "CON78", "1").update({"path": ["CON78.1", "FPGA M10"]}), "U23"),
  572. ],
  573. )
  574. def test_product_regression_fails_closed_on_anchor_drift(mutation, expected: str) -> None:
  575. payload = copy.deepcopy(product_payload())
  576. mutation(payload)
  577. with pytest.raises(BoardRegressionError, match=expected):
  578. validate_product_regression(payload)
  579. def test_any_recommendable_pin_must_satisfy_fail_closed_contract() -> None:
  580. payload = product_payload()
  581. pin = payload["touchpoints"][0]["pins"][2]
  582. pin["recommendation"] = {"eligible": True, "reasons": []}
  583. with pytest.raises(BoardRegressionError, match="recommendable pin violates contract"):
  584. validate_product_regression(payload)
  585. @pytest.mark.parametrize(
  586. "mutation, expected",
  587. [
  588. (lambda payload: pin(payload, "CON78", "1")["programming"].update({"status": "board_only"}), "CON78.1 programming"),
  589. (lambda payload: pin(payload, "CON30", "4")["fpga"].update({"board_signal": "FAN_GPIO4"}), "MOTOR_EN_N"),
  590. (lambda payload: pin(payload, "CON30", "4").update({"active_level": "high"}), "low active"),
  591. (lambda payload: pin(payload, "CON31", "4")["programming"].update({"status": "board_only"}), "CON31.4 programming"),
  592. (lambda payload: pin(payload, "CON58", "4").update({"active_level": "high"}), "MOTOR_STEP"),
  593. (lambda payload: pin(payload, "CON65", "4").update({"active_level": "high"}), "MOTOR_DIR"),
  594. (lambda payload: pin(payload, "CON53", "1")["programming"].update({"hdl_guidance": "push-pull"}), "CON53.1"),
  595. (lambda payload: pin(payload, "TP9", "1")["mcu"].update({"family": "GD32F303CCT6"}), "TP9.1"),
  596. ],
  597. )
  598. def test_programming_guidance_regression_anchors_fail_closed(mutation, expected: str) -> None:
  599. payload = product_payload()
  600. mutation(payload)
  601. with pytest.raises(BoardRegressionError, match=expected):
  602. validate_product_regression(payload)
  603. @pytest.mark.parametrize(
  604. "mutation",
  605. [
  606. lambda payload: touchpoint(payload, "J3")["connector"].update(
  607. {"contact_grid": [["1", "6"], ["2", "7"], ["3", "8"], ["4", "9"], ["5", "10"]]}
  608. ),
  609. lambda payload: pin(payload, "J3", "1")["fpga"].update({"ball": "A6"}),
  610. lambda payload: pin(payload, "J3", "4")["programming"].update(
  611. {"conclusion": "Generic 3.3V power pin"}
  612. ),
  613. lambda payload: pin(payload, "J3", "6").update({"function_category": "gpio"}),
  614. ],
  615. )
  616. def test_j3_jtag_pinout_and_programming_semantics_are_regression_anchors(mutation) -> None:
  617. payload = product_payload()
  618. mutation(payload)
  619. with pytest.raises(BoardRegressionError, match="J3"):
  620. validate_product_regression(payload)