test_product_functional_annotations.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. from __future__ import annotations
  2. import json
  3. from pathlib import Path
  4. ROOT = Path(__file__).resolve().parents[2]
  5. BOARD_DATA = ROOT / "tools" / "board-viewer" / "generated" / "board-data.json"
  6. def load_board_data() -> dict[str, object]:
  7. return json.loads(BOARD_DATA.read_text(encoding="utf-8"))
  8. def by_reference(payload: dict[str, object]) -> dict[str, dict[str, object]]:
  9. return {item["reference"]: item for item in payload["touchpoints"]}
  10. def pins(touchpoint: dict[str, object]) -> dict[str, dict[str, object]]:
  11. return {item["number"]: item for item in touchpoint["pins"] if item["number"]}
  12. def test_every_connector_and_testpoint_has_reviewed_functional_copy() -> None:
  13. payload = load_board_data()
  14. targets = [
  15. item
  16. for item in payload["touchpoints"]
  17. if item["category"] in {"CON", "TP"}
  18. ]
  19. # V1.2 FCB_FPGA+MCU: 88 CON + 8 TP (TP1–TP7, TP31). V1.1 had 91 with TP9+ / CON58/65.
  20. assert len(targets) == 96
  21. assert all("用途未注释" not in item["summary"] for item in targets)
  22. for touchpoint in targets:
  23. reviewed_pins = [
  24. pin
  25. for pin in touchpoint["pins"]
  26. if touchpoint["category"] == "TP" or pin["pad_role"] == "contact"
  27. ]
  28. assert reviewed_pins, touchpoint["reference"]
  29. assert all(not pin["summary"].startswith("板内网络 ") for pin in reviewed_pins), touchpoint["reference"]
  30. def test_power_bmc_rs485_and_fan_connector_semantics_are_anchored() -> None:
  31. refs = by_reference(load_board_data())
  32. con2 = pins(refs["CON2"])
  33. assert "+12V 主电源输入 1" in refs["CON2"]["summary"]
  34. assert all(con2[number]["function_category"] == "ground" for number in ("1", "2", "3", "4"))
  35. assert all("+12V" in con2[number]["summary"] for number in ("5", "6", "7", "8"))
  36. assert con2["5"]["programming"]["evidence_tier"] == "cross_verified"
  37. assert "板端电源输入" in con2["5"]["programming"]["network_explanation"]
  38. assert "CON2.5 +12V_VIN" in con2["5"]["programming"]["network_explanation"]
  39. con31 = pins(refs["CON31"])
  40. assert "+12V_FAN7" in refs["CON31"]["summary"]
  41. assert con31["3"]["fpga"]["ball"] == "D10"
  42. assert con31["3"]["function_category"] == "fan_tach"
  43. assert con31["4"]["fpga"]["ball"] == "E10"
  44. assert con31["4"]["function_category"] == "pwm"
  45. assert "Q105" in " ".join(con31["4"]["path"])
  46. assert "FPGA high" in con31["4"]["polarity"]
  47. con54 = pins(refs["CON54"])
  48. assert "BMC" in refs["CON54"]["summary"]
  49. assert con54["1"]["fpga"]["ball"] == "B14"
  50. assert con54["2"]["fpga"]["ball"] == "A15"
  51. assert con54["3"]["fpga"]["ball"] == "B16"
  52. assert "open-drain" in con54["1"]["programming"]["hdl_guidance"]
  53. con70 = pins(refs["CON70"])
  54. assert "RS-485" in refs["CON70"]["summary"]
  55. assert con70["1"]["summary"].startswith("RS-485 A")
  56. assert con70["2"]["summary"].startswith("RS-485 B")
  57. assert "U13" in " ".join(con70["1"]["path"])
  58. assert all("R736 0R" in " ".join(con70[number]["path"]) for number in ("3", "4"))
  59. con8 = pins(refs["CON8"])
  60. assert "双风扇" in refs["CON8"]["summary"]
  61. assert con8["4"]["fpga"]["ball"] == "D2"
  62. assert con8["5"]["fpga"]["ball"] == "D3"
  63. assert con8["7"]["fpga"]["ball"] == "C4"
  64. assert con8["8"]["fpga"]["ball"] == "N10"
  65. def test_four_wire_fan_and_direct_gpio_connector_families_do_not_cross() -> None:
  66. refs = by_reference(load_board_data())
  67. # CON12 is the LS1/HS1/LS2/HS2 limit header (not dual-gpio-12v).
  68. con12 = pins(refs["CON12"])
  69. assert refs["CON12"]["summary"].startswith("限位")
  70. assert con12["1"]["fpga"]["ball"] == "A5"
  71. assert con12["2"]["fpga"]["ball"] == "B6"
  72. assert con12["3"]["fpga"]["ball"] == "C8"
  73. assert con12["4"]["fpga"]["ball"] == "A8"
  74. assert con12["3"]["function_category"] == "limit"
  75. assert "限位" in con12["3"]["programming"]["hdl_guidance"]
  76. open_collector_refs = {"CON31", "CON32", "CON33", "CON34", "CON35", "CON68"}
  77. for reference in open_collector_refs:
  78. pin4 = pins(refs[reference])["4"]
  79. assert pin4["function_category"] == "pwm"
  80. assert any(item.startswith("Q") for item in pin4["path"]), reference
  81. assert "FPGA high" in pin4["polarity"], reference
  82. con33_pin4 = pins(refs["CON33"])["4"]
  83. assert con33_pin4["fpga"]["ball"] == "C7"
  84. assert "Q107" in " ".join(con33_pin4["path"])
  85. # V1.1 CON58/CON65 (MOTOR_STEP/DIR) are absent on V1.2; motor family is CON104+.
  86. assert "CON58" not in refs
  87. assert "CON65" not in refs
  88. motor_refs = [ref for ref in refs if ref.startswith("CON") and "电机" in refs[ref]["summary"]]
  89. assert "CON104" in motor_refs
  90. con104 = pins(refs["CON104"])
  91. assert con104["2"]["fpga"]["ball"] == "C12"
  92. assert con104["3"]["fpga"]["ball"] == "B12"
  93. assert con104["2"]["function_category"] == "motor"
  94. assert any(item.startswith("Q") for item in con104["2"]["path"])
  95. def test_remote_temperature_ptc_and_mcu_testpoint_paths_are_anchored() -> None:
  96. refs = by_reference(load_board_data())
  97. con53 = pins(refs["CON53"])
  98. assert "CT7428 U6" in refs["CON53"]["summary"]
  99. assert con53["1"]["path"][-1] == "U6.6 DP1"
  100. assert con53["3"]["path"][-1] == "U6.7 DN"
  101. assert con53["1"]["fpga"] is None
  102. assert con53["1"]["programming"]["status"] == "board_only"
  103. assert "open-drain" in con53["1"]["programming"]["hdl_guidance"]
  104. assert "只拉低或释放" in con53["1"]["programming"]["hdl_guidance"]
  105. assert "R811/R812" in " ".join(con53["1"]["programming"]["risks"])
  106. con84 = pins(refs["CON84"])
  107. con85 = pins(refs["CON85"])
  108. assert con84["1"]["path"][-1] == "U24.2 DP5"
  109. assert con85["1"]["path"][-1] == "U24.5 DP2"
  110. con18 = pins(refs["CON18"])
  111. assert "PTC1-PTC6" in refs["CON18"]["summary"]
  112. assert con18["1"]["fpga"]["ball"] == "F16"
  113. assert con18["1"]["fpga"]["board_signal"] == "HEAT1"
  114. assert "Q52" in " ".join(con18["1"]["path"])
  115. assert con18["11"]["net"] == "PTC6"
  116. assert con18["13"]["net"] == "PTC6"
  117. assert con18["11"]["fpga"]["ball"] == "R7"
  118. assert all(con18[number]["function_category"] == "ground" for number in ("2", "4", "6", "8", "10", "12", "14"))
  119. # V1.1 TP9 (GD32 PA0) is absent on V1.2; keep power TPs and LCD 3V3 TP31.
  120. assert "TP9" not in refs
  121. tp31 = pins(refs["TP31"])["1"]
  122. assert "3V3_LCD" in refs["TP31"]["summary"] or "LCD" in refs["TP31"]["summary"]
  123. assert tp31["net"] == "3V3_LCD"
  124. assert tp31["fpga"] is None
  125. assert tp31["recommendation"]["eligible"] is False
  126. tp2 = pins(refs["TP2"])["1"]
  127. tp7 = pins(refs["TP7"])["1"]
  128. assert tp2["net"] == "+3V3"
  129. assert tp7["net"] == "+3.3V"
  130. assert "+3V3" in refs["TP2"]["summary"]
  131. assert "+3.3V" in refs["TP7"]["summary"]
  132. def test_unverified_or_non_fpga_items_never_become_candidates_or_adc_sources() -> None:
  133. payload = load_board_data()
  134. for touchpoint in payload["touchpoints"]:
  135. for pin in touchpoint["pins"]:
  136. if (
  137. pin["evidence_tier"] != "cross_verified"
  138. or pin["fpga"] is None
  139. or pin["function_category"] in {"power", "ground"}
  140. or pin["pad_role"] != "contact"
  141. or pin["reserved"] is True
  142. or pin["fixed_load_conflict"] is True
  143. ):
  144. assert pin["recommendation"]["eligible"] is False, f"{touchpoint['reference']}.{pin['number']}"