regression_v2.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. """Product-specific regression checks for FCB V2.0 and FCB_FAN V2.0."""
  2. from __future__ import annotations
  3. from collections.abc import Mapping
  4. from .data import validate_resistor_index
  5. from .regression import BoardRegressionError, _pin_index
  6. V20_EXPECTED_COUNTS = {
  7. "footprints": 1457,
  8. "touchpoints": 74,
  9. "pads": 493,
  10. "resistors": 730,
  11. "resistor_pads": 1460,
  12. }
  13. V20_EXPECTED_CATEGORIES = {"CON": 41, "J": 18, "PL": 3, "TP": 12}
  14. V20_EXPECTED_RESISTORS = 730
  15. def validate_v20_mainboard_regression(payload: Mapping[str, object]) -> None:
  16. """Regression checks for FCB FPGA+MCU V2.0 (6400 20260914)."""
  17. counts = payload.get("counts")
  18. if not isinstance(counts, Mapping):
  19. raise BoardRegressionError("counts missing")
  20. for name, expected in V20_EXPECTED_COUNTS.items():
  21. if counts.get(name) != expected:
  22. raise BoardRegressionError(f"{name}={counts.get(name)} expected {expected}")
  23. categories = counts.get("categories")
  24. if not isinstance(categories, Mapping):
  25. raise BoardRegressionError("category counts missing")
  26. for name, expected in V20_EXPECTED_CATEGORIES.items():
  27. if categories.get(name) != expected:
  28. raise BoardRegressionError(f"{name}={categories.get(name)} expected {expected}")
  29. if categories.get("R") != V20_EXPECTED_RESISTORS:
  30. raise BoardRegressionError(f"R={categories.get('R')} expected {V20_EXPECTED_RESISTORS}")
  31. raw_touchpoints = payload.get("touchpoints", [])
  32. touchpoints = [item for item in raw_touchpoints if isinstance(item, Mapping)] if isinstance(raw_touchpoints, list) else []
  33. by_reference = {str(item.get("reference")): item for item in touchpoints}
  34. for required in ("CON12", "CON134", "CON77", "CON147", "CON148", "CON149", "CON150", "CON154", "CON155", "CON165"):
  35. if required not in by_reference:
  36. raise BoardRegressionError(f"{required} missing on V2.0 board")
  37. # Check CON12 (Host TTL)
  38. con12 = by_reference["CON12"]
  39. pins = _pin_index(con12)
  40. if "3" not in pins or (pins["3"].get("fpga") or {}).get("ball") != "K2":
  41. raise BoardRegressionError("CON12.3 must map to CPLD ball K2 (TX)")
  42. if "4" not in pins or (pins["4"].get("fpga") or {}).get("ball") != "J4":
  43. raise BoardRegressionError("CON12.4 must map to CPLD ball J4 (RX)")
  44. # Check CON134 (Host RS232)
  45. con134 = by_reference["CON134"]
  46. pins134 = _pin_index(con134)
  47. if "1" not in pins134 or (pins134["1"].get("fpga") or {}).get("ball") != "T14":
  48. raise BoardRegressionError("CON134.1 must map to CPLD ball T14 (TX)")
  49. if "2" not in pins134 or (pins134["2"].get("fpga") or {}).get("ball") != "R13":
  50. raise BoardRegressionError("CON134.2 must map to CPLD ball R13 (RX)")
  51. # Check CON77 (BMC RS232)
  52. con77 = by_reference["CON77"]
  53. pins77 = _pin_index(con77)
  54. if "1" not in pins77 or (pins77["1"].get("fpga") or {}).get("ball") != "L10":
  55. raise BoardRegressionError("CON77.1 must map to CPLD ball L10 (TX)")
  56. if "2" not in pins77 or (pins77["2"].get("fpga") or {}).get("ball") != "M9":
  57. raise BoardRegressionError("CON77.2 must map to CPLD ball M9 (RX)")
  58. try:
  59. validate_resistor_index(payload)
  60. except ValueError as exc:
  61. raise BoardRegressionError(str(exc)) from exc
  62. V20_FAN_EXPECTED_COUNTS = {
  63. "footprints": 33,
  64. "touchpoints": 7,
  65. "pads": 66,
  66. "resistors": 0,
  67. "resistor_pads": 0,
  68. }
  69. V20_FAN_EXPECTED_CATEGORIES = {"CON": 7, "J": 0, "PL": 0, "TP": 0}
  70. def validate_v20_fan_regression(payload: Mapping[str, object]) -> None:
  71. """Regression checks for FCB_FAN V2.0 (20260914)."""
  72. counts = payload.get("counts")
  73. if not isinstance(counts, Mapping):
  74. raise BoardRegressionError("counts missing")
  75. for name, expected in V20_FAN_EXPECTED_COUNTS.items():
  76. if counts.get(name) != expected:
  77. raise BoardRegressionError(f"{name}={counts.get(name)} expected {expected}")
  78. categories = counts.get("categories")
  79. if not isinstance(categories, Mapping):
  80. raise BoardRegressionError("category counts missing")
  81. for name, expected in V20_FAN_EXPECTED_CATEGORIES.items():
  82. if categories.get(name) != expected:
  83. raise BoardRegressionError(f"{name}={categories.get(name)} expected {expected}")
  84. if categories.get("R") != 0:
  85. raise BoardRegressionError(f"R={categories.get('R')} expected 0")
  86. raw_touchpoints = payload.get("touchpoints", [])
  87. touchpoints = [item for item in raw_touchpoints if isinstance(item, Mapping)] if isinstance(raw_touchpoints, list) else []
  88. by_reference = {str(item.get("reference")): item for item in touchpoints}
  89. for required in ("CON168", "CON8", "CON169", "CON170", "CON171", "CON2", "CON172"):
  90. if required not in by_reference:
  91. raise BoardRegressionError(f"{required} missing on FCB_FAN V2.0 board")
  92. try:
  93. validate_resistor_index(payload)
  94. except ValueError as exc:
  95. raise BoardRegressionError(str(exc)) from exc
  96. def validate_v2_product_regression(payload: Mapping[str, object]) -> None:
  97. board = payload.get("board")
  98. identity = f"{(board.get('id') if isinstance(board, Mapping) else '')} {(board.get('name') if isinstance(board, Mapping) else '')}".lower()
  99. if "fan" in identity:
  100. validate_v20_fan_regression(payload)
  101. else:
  102. validate_v20_mainboard_regression(payload)