|
|
@@ -5,7 +5,9 @@ from __future__ import annotations
|
|
|
|
|
|
import argparse
|
|
|
import copy
|
|
|
+import hashlib
|
|
|
import json
|
|
|
+import re
|
|
|
import subprocess
|
|
|
import tempfile
|
|
|
import unittest
|
|
|
@@ -41,6 +43,53 @@ EXPECTED_SOURCES = (
|
|
|
"src/top/prod2u_p4_normal_v3_top.v",
|
|
|
)
|
|
|
|
|
|
+REQUIRED_MOTOR_LIMIT_PINS = {
|
|
|
+ "motor_en_n": {"location": "A10", "direction": "OUTPUT", "pull_type": "NONE"},
|
|
|
+ "x_step": {"location": "C11", "direction": "OUTPUT", "pull_type": "NONE"},
|
|
|
+ "x_dir": {"location": "B12", "direction": "OUTPUT", "pull_type": "NONE"},
|
|
|
+ "y_step": {"location": "D15", "direction": "OUTPUT", "pull_type": "NONE"},
|
|
|
+ "y_dir": {"location": "H14", "direction": "OUTPUT", "pull_type": "NONE"},
|
|
|
+ "x_limit_raw": {"location": "B9", "direction": "INPUT", "pull_type": "PULLUP"},
|
|
|
+ "y_limit_raw": {"location": "A11", "direction": "INPUT", "pull_type": "PULLUP"},
|
|
|
+}
|
|
|
+
|
|
|
+UART_ONLY_CDC_REGISTERS = frozenset(
|
|
|
+ {
|
|
|
+ "u_uart_rx/rx_sync_pipe[0]",
|
|
|
+ "u_uart_rx/rx_sync_pipe[1]",
|
|
|
+ }
|
|
|
+)
|
|
|
+UART_ONLY_CDC_ENDPOINTS = frozenset({"u_uart_rx/rx_sync_pipe[0]"})
|
|
|
+
|
|
|
+
|
|
|
+def valid_io_rows() -> list[dict[str, str]]:
|
|
|
+ rows = [
|
|
|
+ {
|
|
|
+ "name": f"dummy_{index}",
|
|
|
+ "direction": "OUTPUT",
|
|
|
+ "location": f"DUMMY{index}",
|
|
|
+ "io_standard": "LVCMOS33",
|
|
|
+ "io_type": "PAD",
|
|
|
+ "drive_strength": "8",
|
|
|
+ "pull_type": "NONE",
|
|
|
+ "pack_reg": "NONE",
|
|
|
+ "diff_resistor": "NONE",
|
|
|
+ }
|
|
|
+ for index in range(41 - len(REQUIRED_MOTOR_LIMIT_PINS))
|
|
|
+ ]
|
|
|
+ template = rows[0]
|
|
|
+ rows.extend(
|
|
|
+ {
|
|
|
+ **template,
|
|
|
+ "name": name,
|
|
|
+ "location": expected["location"],
|
|
|
+ "direction": expected["direction"],
|
|
|
+ "pull_type": expected["pull_type"],
|
|
|
+ }
|
|
|
+ for name, expected in REQUIRED_MOTOR_LIMIT_PINS.items()
|
|
|
+ )
|
|
|
+ return rows
|
|
|
+
|
|
|
|
|
|
def valid_resources() -> dict[str, object]:
|
|
|
return {
|
|
|
@@ -61,6 +110,11 @@ def valid_resources() -> dict[str, object]:
|
|
|
|
|
|
def valid_td_receipt(bitstream: Path, *, commit: str = "a" * 40) -> dict[str, object]:
|
|
|
digest = harness.sha256_file(bitstream)
|
|
|
+ observed_pins = {
|
|
|
+ row["name"]: row
|
|
|
+ for row in valid_io_rows()
|
|
|
+ if row["name"] in REQUIRED_MOTOR_LIMIT_PINS
|
|
|
+ }
|
|
|
return {
|
|
|
"schema": harness.TD_RECEIPT_SCHEMA,
|
|
|
"status": "pass",
|
|
|
@@ -73,18 +127,7 @@ def valid_td_receipt(bitstream: Path, *, commit: str = "a" * 40) -> dict[str, ob
|
|
|
"post_route_pin_gate": {
|
|
|
"status": "pass",
|
|
|
"row_count": 41,
|
|
|
- "observed": {
|
|
|
- "x_limit_raw": {
|
|
|
- "location": "B9",
|
|
|
- "io_standard": "LVCMOS33",
|
|
|
- "pull_type": "PULLUP",
|
|
|
- },
|
|
|
- "y_limit_raw": {
|
|
|
- "location": "A11",
|
|
|
- "io_standard": "LVCMOS33",
|
|
|
- "pull_type": "PULLUP",
|
|
|
- },
|
|
|
- },
|
|
|
+ "observed": observed_pins,
|
|
|
},
|
|
|
"binding_gate": {"status": "pass"},
|
|
|
"timing_gate": {"status": "pass"},
|
|
|
@@ -114,7 +157,11 @@ def valid_td_receipt(bitstream: Path, *, commit: str = "a" * 40) -> dict[str, ob
|
|
|
"log_has_error": False,
|
|
|
"critical_warning_count": 0,
|
|
|
},
|
|
|
- "bitstream": {"path": str(bitstream), "size": bitstream.stat().st_size},
|
|
|
+ "bitstream": {
|
|
|
+ "path": str(bitstream),
|
|
|
+ "size": bitstream.stat().st_size,
|
|
|
+ "sha256": digest,
|
|
|
+ },
|
|
|
"run_id": "1" * 32,
|
|
|
"work_root": "C:/td-a",
|
|
|
"td_tool": {"sha256": "c" * 64},
|
|
|
@@ -150,11 +197,168 @@ def valid_package_receipt(
|
|
|
"commit": commit,
|
|
|
"bitstream_sha256": digest,
|
|
|
"package_dir": str(package),
|
|
|
+ "delivery_mode": "normal_dual_td",
|
|
|
+ "verification_complete": True,
|
|
|
+ "confirmation_td_present": True,
|
|
|
+ "validation_status": "pass",
|
|
|
+ "packaged_selftest_status": "pass",
|
|
|
"failures": [],
|
|
|
"selftest": {"status": "pass", "returncode": 0},
|
|
|
}
|
|
|
|
|
|
|
|
|
+def materialize_valid_package(
|
|
|
+ package: Path,
|
|
|
+ *,
|
|
|
+ bitstream_bytes: bytes = b"package-final-gate",
|
|
|
+ commit: str = "a" * 40,
|
|
|
+) -> tuple[dict[str, object], dict[str, object], dict[str, object]]:
|
|
|
+ package.mkdir(parents=True)
|
|
|
+ bitstream = package / "fw.bit"
|
|
|
+ bitstream.write_bytes(bitstream_bytes)
|
|
|
+ digest = harness.sha256_file(bitstream)
|
|
|
+ primary = valid_td_receipt(bitstream, commit=commit)
|
|
|
+ confirmation = copy.deepcopy(primary)
|
|
|
+ confirmation["run_id"] = "2" * 32
|
|
|
+ confirmation["work_root"] = "C:/td-b"
|
|
|
+
|
|
|
+ for relative in harness.package_required_files(confirmation_td_present=True):
|
|
|
+ path = package / relative
|
|
|
+ path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
+ if not path.exists():
|
|
|
+ path.write_text(f"fixture:{relative}\n", encoding="utf-8")
|
|
|
+
|
|
|
+ primary_path = package / "evidence" / "td-primary-receipt.json"
|
|
|
+ confirmation_path = package / "evidence" / "td-confirmation-receipt.json"
|
|
|
+ primary_path.write_text(json.dumps(primary), encoding="utf-8")
|
|
|
+ confirmation_path.write_text(json.dumps(confirmation), encoding="utf-8")
|
|
|
+ validation = {
|
|
|
+ "schema": "prod2u-p4-normal-v3-validation-summary-v1",
|
|
|
+ "commit": commit,
|
|
|
+ "bitstream_sha256": digest,
|
|
|
+ "delivery_mode": "normal_dual_td",
|
|
|
+ "verification_complete": True,
|
|
|
+ "confirmation_td_present": True,
|
|
|
+ "layers": {
|
|
|
+ name: {"status": "pass"}
|
|
|
+ for name in (
|
|
|
+ "python",
|
|
|
+ "icarus",
|
|
|
+ "verilator",
|
|
|
+ "cocotb",
|
|
|
+ "formal",
|
|
|
+ "td_primary",
|
|
|
+ "td_confirmation",
|
|
|
+ "td_primary_artifacts",
|
|
|
+ "td_confirmation_artifacts",
|
|
|
+ "td_confirmation_bitstream",
|
|
|
+ "td_confirmation_synthesis",
|
|
|
+ "td_confirmation_manifest",
|
|
|
+ "resource_primary",
|
|
|
+ "resource_confirmation",
|
|
|
+ "package_selftest",
|
|
|
+ )
|
|
|
+ },
|
|
|
+ }
|
|
|
+ validation_path = package / "evidence" / "validation-summary.json"
|
|
|
+ validation_path.write_text(json.dumps(validation), encoding="utf-8")
|
|
|
+ packaged_selftest_path = package / "evidence" / "package-selftest-result.json"
|
|
|
+ packaged_selftest_path.write_text(
|
|
|
+ json.dumps(
|
|
|
+ {
|
|
|
+ "schema": "prod2u-p4-normal-v3-package-selftest-result-v1",
|
|
|
+ "status": "pass",
|
|
|
+ "returncode": 0,
|
|
|
+ }
|
|
|
+ ),
|
|
|
+ encoding="utf-8",
|
|
|
+ )
|
|
|
+ info_path = package / "package-info.json"
|
|
|
+ actual_files = {
|
|
|
+ path.relative_to(package).as_posix(): harness.sha256_file(path)
|
|
|
+ for path in sorted(package.rglob("*"))
|
|
|
+ if path.is_file() and path not in {info_path, packaged_selftest_path}
|
|
|
+ }
|
|
|
+ info = {
|
|
|
+ "schema": "prod2u-p4-normal-v3-folder-package-info-v3",
|
|
|
+ "profile": harness.RUNTIME_PROFILE,
|
|
|
+ "commit": commit,
|
|
|
+ "bitstream_sha256": digest,
|
|
|
+ "delivery_mode": "normal_dual_td",
|
|
|
+ "verification_complete": True,
|
|
|
+ "confirmation_td_present": True,
|
|
|
+ "confirmation_bitstream_sha256": digest,
|
|
|
+ "td_receipt_sha256": harness.sha256_file(primary_path),
|
|
|
+ "confirmation_td_receipt_sha256": harness.sha256_file(confirmation_path),
|
|
|
+ "validation_summary_sha256": harness.sha256_file(validation_path),
|
|
|
+ "package_selftest_result_sha256": harness.sha256_file(packaged_selftest_path),
|
|
|
+ "synthesis_input_hash": primary["synthesis_input_hash"],
|
|
|
+ "confirmation_synthesis_input_hash": confirmation["synthesis_input_hash"],
|
|
|
+ "file_sha256": actual_files,
|
|
|
+ }
|
|
|
+ info_path.write_text(json.dumps(info), encoding="utf-8")
|
|
|
+ receipt = valid_package_receipt(package, digest=digest, commit=commit)
|
|
|
+ receipt.update(
|
|
|
+ {
|
|
|
+ "package_info_sha256": harness.sha256_file(info_path),
|
|
|
+ "td_receipt_sha256": harness.sha256_file(primary_path),
|
|
|
+ "confirmation_td_receipt_sha256": harness.sha256_file(confirmation_path),
|
|
|
+ "validation_summary_sha256": harness.sha256_file(validation_path),
|
|
|
+ "package_selftest_result_sha256": harness.sha256_file(packaged_selftest_path),
|
|
|
+ "package_file_sha256": actual_files,
|
|
|
+ "package_file_manifest_sha256": harness.canonical_sha256(actual_files),
|
|
|
+ }
|
|
|
+ )
|
|
|
+ return receipt, primary, confirmation
|
|
|
+
|
|
|
+
|
|
|
+def refresh_package_bindings(package: Path, receipt: dict[str, object]) -> None:
|
|
|
+ info_path = package / "package-info.json"
|
|
|
+ primary_path = package / "evidence" / "td-primary-receipt.json"
|
|
|
+ confirmation_path = package / "evidence" / "td-confirmation-receipt.json"
|
|
|
+ validation_path = package / "evidence" / "validation-summary.json"
|
|
|
+ packaged_selftest_path = package / "evidence" / "package-selftest-result.json"
|
|
|
+ info = json.loads(info_path.read_text(encoding="utf-8"))
|
|
|
+ info["td_receipt_sha256"] = harness.sha256_file(primary_path)
|
|
|
+ info["confirmation_td_receipt_sha256"] = (
|
|
|
+ harness.sha256_file(confirmation_path) if confirmation_path.is_file() else None
|
|
|
+ )
|
|
|
+ info["validation_summary_sha256"] = harness.sha256_file(validation_path)
|
|
|
+ info["package_selftest_result_sha256"] = harness.sha256_file(packaged_selftest_path)
|
|
|
+ actual_files = {
|
|
|
+ path.relative_to(package).as_posix(): harness.sha256_file(path)
|
|
|
+ for path in sorted(package.rglob("*"))
|
|
|
+ if path.is_file() and path not in {info_path, packaged_selftest_path}
|
|
|
+ }
|
|
|
+ info["file_sha256"] = actual_files
|
|
|
+ info_path.write_text(json.dumps(info), encoding="utf-8")
|
|
|
+ receipt.update(
|
|
|
+ {
|
|
|
+ "delivery_mode": info["delivery_mode"],
|
|
|
+ "verification_complete": info["verification_complete"],
|
|
|
+ "confirmation_td_present": info["confirmation_td_present"],
|
|
|
+ "package_info_sha256": harness.sha256_file(info_path),
|
|
|
+ "td_receipt_sha256": info["td_receipt_sha256"],
|
|
|
+ "confirmation_td_receipt_sha256": info[
|
|
|
+ "confirmation_td_receipt_sha256"
|
|
|
+ ],
|
|
|
+ "validation_summary_sha256": info["validation_summary_sha256"],
|
|
|
+ "package_selftest_result_sha256": info[
|
|
|
+ "package_selftest_result_sha256"
|
|
|
+ ],
|
|
|
+ "package_file_sha256": actual_files,
|
|
|
+ "package_file_manifest_sha256": harness.canonical_sha256(actual_files),
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def update_package_info(package: Path, **updates: object) -> None:
|
|
|
+ info_path = package / "package-info.json"
|
|
|
+ info = json.loads(info_path.read_text(encoding="utf-8"))
|
|
|
+ info.update(updates)
|
|
|
+ info_path.write_text(json.dumps(info), encoding="utf-8")
|
|
|
+
|
|
|
+
|
|
|
class Prod2UP4HarnessTests(unittest.TestCase):
|
|
|
def test_cdc_report_preserves_advisory_failures_and_source_only_paths(self) -> None:
|
|
|
with tempfile.TemporaryDirectory(dir=ROOT.parent) as temporary:
|
|
|
@@ -193,6 +397,51 @@ class Prod2UP4HarnessTests(unittest.TestCase):
|
|
|
)
|
|
|
self.assertIn("source_only_false_paths_used:host_uart_rx", gate["failures"])
|
|
|
|
|
|
+ def test_cdc_gate_accepts_uart_only_synchronizers(self) -> None:
|
|
|
+ uart_only_report = {
|
|
|
+ "retained_sync_registers": sorted(UART_ONLY_CDC_REGISTERS),
|
|
|
+ "false_path_endpoints": sorted(UART_ONLY_CDC_ENDPOINTS),
|
|
|
+ "source_only_false_paths": [],
|
|
|
+ "structural_failures": [],
|
|
|
+ }
|
|
|
+ accepted = harness.structural_cdc_gate(
|
|
|
+ uart_only_report,
|
|
|
+ async_reg_count=2,
|
|
|
+ input_register_count=0,
|
|
|
+ )
|
|
|
+ self.assertEqual(accepted["status"], "pass", accepted["failures"])
|
|
|
+
|
|
|
+ def test_cdc_gate_rejects_legacy_limit_synchronizers(self) -> None:
|
|
|
+ legacy_registers = sorted(
|
|
|
+ UART_ONLY_CDC_REGISTERS
|
|
|
+ | {
|
|
|
+ "u_core/u_motors/u_x_axis/limit_sync_pipe[0]",
|
|
|
+ "u_core/u_motors/u_x_axis/limit_sync_pipe[1]",
|
|
|
+ "u_core/u_motors/u_x_axis/limit_sync_pipe[2]",
|
|
|
+ "u_core/u_motors/u_y_axis/limit_sync_pipe[0]",
|
|
|
+ "u_core/u_motors/u_y_axis/limit_sync_pipe[1]",
|
|
|
+ "u_core/u_motors/u_y_axis/limit_sync_pipe[2]",
|
|
|
+ }
|
|
|
+ )
|
|
|
+ legacy_report = {
|
|
|
+ "retained_sync_registers": legacy_registers,
|
|
|
+ "false_path_endpoints": sorted(
|
|
|
+ UART_ONLY_CDC_ENDPOINTS
|
|
|
+ | {
|
|
|
+ "u_core/u_motors/u_x_axis/limit_sync_pipe[0]",
|
|
|
+ "u_core/u_motors/u_y_axis/limit_sync_pipe[0]",
|
|
|
+ }
|
|
|
+ ),
|
|
|
+ "source_only_false_paths": [],
|
|
|
+ "structural_failures": [],
|
|
|
+ }
|
|
|
+ rejected = harness.structural_cdc_gate(
|
|
|
+ legacy_report,
|
|
|
+ async_reg_count=8,
|
|
|
+ input_register_count=0,
|
|
|
+ )
|
|
|
+ self.assertEqual(rejected["status"], "fail")
|
|
|
+
|
|
|
def test_fsm_report_preserves_advisory_discovery_failures(self) -> None:
|
|
|
with tempfile.TemporaryDirectory(dir=ROOT.parent) as temporary:
|
|
|
report_path = Path(temporary) / "fsm.rpt"
|
|
|
@@ -224,6 +473,28 @@ class Prod2UP4HarnessTests(unittest.TestCase):
|
|
|
gate["failures"],
|
|
|
)
|
|
|
|
|
|
+ def test_fsm_gate_accepts_two_bit_simplified_axes(self) -> None:
|
|
|
+ accepted = harness.structural_fsm_gate(
|
|
|
+ {
|
|
|
+ "axes": {"x": 2, "y": 2},
|
|
|
+ "encodings": {"x": "sequential", "y": "sequential"},
|
|
|
+ "structural_failures": [],
|
|
|
+ },
|
|
|
+ syn_log="FSM_ENCODING_GATE_PASS=sequential",
|
|
|
+ )
|
|
|
+ self.assertEqual(accepted["status"], "pass", accepted["failures"])
|
|
|
+
|
|
|
+ def test_fsm_gate_rejects_legacy_three_bit_axes(self) -> None:
|
|
|
+ rejected = harness.structural_fsm_gate(
|
|
|
+ {
|
|
|
+ "axes": {"x": 3, "y": 3},
|
|
|
+ "encodings": {"x": "sequential", "y": "sequential"},
|
|
|
+ "structural_failures": [],
|
|
|
+ },
|
|
|
+ syn_log="FSM_ENCODING_GATE_PASS=sequential",
|
|
|
+ )
|
|
|
+ self.assertEqual(rejected["status"], "fail")
|
|
|
+
|
|
|
def test_bitgen_eligibility_depends_only_on_successful_route(self) -> None:
|
|
|
self.assertTrue(
|
|
|
harness.td_bitgen_eligible(
|
|
|
@@ -374,40 +645,101 @@ class Prod2UP4HarnessTests(unittest.TestCase):
|
|
|
with self.assertRaisesRegex(ValueError, "outside the repository"):
|
|
|
harness.resolve_report_file(ROOT / "receipt.json")
|
|
|
|
|
|
- def test_pin_binding_gate_requires_b9_a11_and_rejects_a5(self) -> None:
|
|
|
+ def test_pin_binding_gate_blocks_every_motor_and_limit_ball_mutation(self) -> None:
|
|
|
evidence = harness.pin_binding_gate()
|
|
|
|
|
|
self.assertEqual(evidence["status"], "pass", evidence["failures"])
|
|
|
self.assertEqual(evidence["pad_count"], 41)
|
|
|
|
|
|
- def test_post_route_pin_gate_requires_41_unique_rows_and_verified_limits(self) -> None:
|
|
|
- rows = [
|
|
|
- {
|
|
|
- "name": f"dummy_{index}",
|
|
|
- "direction": "Output",
|
|
|
- "location": f"DUMMY{index}",
|
|
|
- "io_standard": "LVCMOS33",
|
|
|
- "io_type": "single",
|
|
|
- "drive_strength": "8",
|
|
|
- "pull_type": "NONE",
|
|
|
- "pack_reg": "OFF",
|
|
|
- "diff_resistor": "OFF",
|
|
|
- }
|
|
|
- for index in range(39)
|
|
|
- ]
|
|
|
- rows.extend(
|
|
|
- [
|
|
|
- {**rows[0], "name": "x_limit_raw", "location": "B9", "pull_type": "PULLUP"},
|
|
|
- {**rows[0], "name": "y_limit_raw", "location": "A11", "pull_type": "PULLUP"},
|
|
|
- ]
|
|
|
+ original = (ROOT / "constraints" / "prod2u_p4_normal_v3.adc").read_text(
|
|
|
+ encoding="ascii"
|
|
|
)
|
|
|
- evidence = harness.post_route_pin_gate(rows)
|
|
|
+ with tempfile.TemporaryDirectory(dir=ROOT.parent) as temporary:
|
|
|
+ temporary_root = Path(temporary)
|
|
|
+ constraints = temporary_root / "constraints"
|
|
|
+ constraints.mkdir()
|
|
|
+ target = constraints / "prod2u_p4_normal_v3.adc"
|
|
|
+ for signal, expected in REQUIRED_MOTOR_LIMIT_PINS.items():
|
|
|
+ with self.subTest(signal=signal):
|
|
|
+ pattern = re.compile(
|
|
|
+ rf"(set_pin_assignment\s+\{{\s*{re.escape(signal)}\s*\}}\s+"
|
|
|
+ rf"\{{\s*LOCATION\s*=\s*){re.escape(expected['location'])}(;)"
|
|
|
+ )
|
|
|
+ mutated, count = pattern.subn(r"\1WRONG_BALL\2", original)
|
|
|
+ self.assertEqual(count, 1)
|
|
|
+ target.write_text(mutated, encoding="ascii")
|
|
|
+ with mock.patch.object(harness, "ROOT", temporary_root):
|
|
|
+ rejected = harness.pin_binding_gate()
|
|
|
+ self.assertEqual(rejected["status"], "fail", rejected)
|
|
|
+
|
|
|
+ target.write_text(
|
|
|
+ original.replace("LOCATION = A10;", "LOCATION = A5;", 1),
|
|
|
+ encoding="ascii",
|
|
|
+ )
|
|
|
+ with mock.patch.object(harness, "ROOT", temporary_root):
|
|
|
+ forbidden = harness.pin_binding_gate()
|
|
|
+ self.assertEqual(forbidden["status"], "fail")
|
|
|
+ self.assertIn("forbidden_ball_assigned:A5", forbidden["failures"])
|
|
|
+
|
|
|
+ def test_post_route_pin_gate_blocks_motor_limit_a5_and_io_count_mutations(self) -> None:
|
|
|
+ rows = valid_io_rows()
|
|
|
+ with tempfile.TemporaryDirectory(dir=ROOT.parent) as temporary:
|
|
|
+ report_path = Path(temporary) / "prod2u_p4_normal_v3_phy.area"
|
|
|
+ report_path.write_text(
|
|
|
+ "\n".join(
|
|
|
+ [
|
|
|
+ "Detailed IO Report",
|
|
|
+ (
|
|
|
+ "Name Direction Location IOStandard IOType "
|
|
|
+ "DriveStrength PullType PackReg DiffResistor"
|
|
|
+ ),
|
|
|
+ *(
|
|
|
+ " ".join(
|
|
|
+ row[field]
|
|
|
+ for field in (
|
|
|
+ "name",
|
|
|
+ "direction",
|
|
|
+ "location",
|
|
|
+ "io_standard",
|
|
|
+ "io_type",
|
|
|
+ "drive_strength",
|
|
|
+ "pull_type",
|
|
|
+ "pack_reg",
|
|
|
+ "diff_resistor",
|
|
|
+ )
|
|
|
+ )
|
|
|
+ for row in rows
|
|
|
+ ),
|
|
|
+ "",
|
|
|
+ ]
|
|
|
+ ),
|
|
|
+ encoding="ascii",
|
|
|
+ )
|
|
|
+ parsed_rows = harness.parse_td_io_report(report_path)
|
|
|
+
|
|
|
+ self.assertIsNotNone(parsed_rows)
|
|
|
+ assert parsed_rows is not None
|
|
|
+ self.assertEqual(len(parsed_rows), 41)
|
|
|
+ evidence = harness.post_route_pin_gate(parsed_rows)
|
|
|
self.assertEqual(evidence["status"], "pass", evidence["failures"])
|
|
|
|
|
|
- rows[-1]["location"] = "A5"
|
|
|
- rejected = harness.post_route_pin_gate(rows)
|
|
|
- self.assertEqual(rejected["status"], "fail")
|
|
|
- self.assertIn("forbidden_location_assigned:A5", rejected["failures"])
|
|
|
+ for signal in REQUIRED_MOTOR_LIMIT_PINS:
|
|
|
+ with self.subTest(signal=signal):
|
|
|
+ changed = copy.deepcopy(parsed_rows)
|
|
|
+ row = next(item for item in changed if item["name"] == signal)
|
|
|
+ row["location"] = "WRONG_BALL"
|
|
|
+ rejected = harness.post_route_pin_gate(changed)
|
|
|
+ self.assertEqual(rejected["status"], "fail", rejected)
|
|
|
+
|
|
|
+ forbidden_rows = copy.deepcopy(parsed_rows)
|
|
|
+ forbidden_rows[0]["location"] = "A5"
|
|
|
+ forbidden = harness.post_route_pin_gate(forbidden_rows)
|
|
|
+ self.assertEqual(forbidden["status"], "fail")
|
|
|
+ self.assertIn("forbidden_location_assigned:A5", forbidden["failures"])
|
|
|
+
|
|
|
+ missing_row = harness.post_route_pin_gate(parsed_rows[:-1])
|
|
|
+ self.assertEqual(missing_row["status"], "fail")
|
|
|
+ self.assertIn("io_row_count:40", missing_row["failures"])
|
|
|
|
|
|
def test_structural_resource_gate_requires_all_bram_zero_dsp_zero_io_41(self) -> None:
|
|
|
accepted = harness.structural_resource_gate(valid_resources())
|
|
|
@@ -442,6 +774,21 @@ class Prod2UP4HarnessTests(unittest.TestCase):
|
|
|
timing[field] = 0
|
|
|
self.assertEqual(harness.timing_gate(timing)["status"], "fail")
|
|
|
|
|
|
+ def test_td_bitstream_binding_requires_existing_hash_matching_file(self) -> None:
|
|
|
+ digest = "a" * 64
|
|
|
+ receipt = {
|
|
|
+ "bitstream_sha256": digest,
|
|
|
+ "bitstream": {
|
|
|
+ "path": str(ROOT.parent / "definitely-missing-final-gate.bit"),
|
|
|
+ "sha256": digest,
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ self.assertEqual(
|
|
|
+ harness.td_receipt_bitstream_binding_status(receipt),
|
|
|
+ "fail",
|
|
|
+ )
|
|
|
+
|
|
|
def test_final_td_semantic_recheck_rejects_forged_pass_fields(self) -> None:
|
|
|
with tempfile.TemporaryDirectory(dir=ROOT.parent) as temporary:
|
|
|
bitstream = Path(temporary) / "fw.bit"
|
|
|
@@ -466,6 +813,7 @@ class Prod2UP4HarnessTests(unittest.TestCase):
|
|
|
mutations = {
|
|
|
"timing": lambda value: value["timing"].__setitem__("worst_setup_slack_ns", 0),
|
|
|
"pins": lambda value: value["post_route_pin_gate"]["observed"]["y_limit_raw"].__setitem__("location", "A5"),
|
|
|
+ "motor_pin": lambda value: value["post_route_pin_gate"]["observed"]["x_step"].__setitem__("location", "WRONG_BALL"),
|
|
|
"source": lambda value: value["source_state"].__setitem__("clean", False),
|
|
|
"phase": lambda value: value["phy"].__setitem__("status", "fail"),
|
|
|
}
|
|
|
@@ -492,65 +840,225 @@ class Prod2UP4HarnessTests(unittest.TestCase):
|
|
|
def test_final_package_semantic_recheck_binds_info_and_firmware_hash(self) -> None:
|
|
|
with tempfile.TemporaryDirectory(dir=ROOT.parent) as temporary:
|
|
|
package = Path(temporary) / "package"
|
|
|
- package.mkdir(parents=True)
|
|
|
- bitstream = package / "fw.bit"
|
|
|
- bitstream.write_bytes(b"package-final-gate")
|
|
|
- digest = harness.sha256_file(bitstream)
|
|
|
- info = {"commit": "a" * 40, "bitstream_sha256": digest}
|
|
|
- (package / "package-info.json").write_text(json.dumps(info), encoding="utf-8")
|
|
|
- receipt = valid_package_receipt(package, digest=digest)
|
|
|
+ receipt, _, _ = materialize_valid_package(package)
|
|
|
+ digest = str(receipt["bitstream_sha256"])
|
|
|
+ primary_sha = str(receipt["td_receipt_sha256"])
|
|
|
+ confirmation_sha = str(receipt["confirmation_td_receipt_sha256"])
|
|
|
|
|
|
self.assertEqual(
|
|
|
harness._package_final_failures(
|
|
|
receipt,
|
|
|
expected_commit="a" * 40,
|
|
|
expected_bitstream_sha256=digest,
|
|
|
+ expected_primary_td_receipt_sha256=primary_sha,
|
|
|
+ expected_confirmation_td_receipt_sha256=confirmation_sha,
|
|
|
),
|
|
|
[],
|
|
|
)
|
|
|
|
|
|
+ info_path = package / "package-info.json"
|
|
|
+ info = json.loads(info_path.read_text(encoding="utf-8"))
|
|
|
info["commit"] = "b" * 40
|
|
|
- (package / "package-info.json").write_text(json.dumps(info), encoding="utf-8")
|
|
|
+ info_path.write_text(json.dumps(info), encoding="utf-8")
|
|
|
self.assertIn(
|
|
|
"package:info_binding",
|
|
|
harness._package_final_failures(
|
|
|
receipt,
|
|
|
expected_commit="a" * 40,
|
|
|
expected_bitstream_sha256=digest,
|
|
|
+ expected_primary_td_receipt_sha256=primary_sha,
|
|
|
+ expected_confirmation_td_receipt_sha256=confirmation_sha,
|
|
|
),
|
|
|
)
|
|
|
info["commit"] = "a" * 40
|
|
|
- (package / "package-info.json").write_text(json.dumps(info), encoding="utf-8")
|
|
|
- bitstream.write_bytes(b"tampered")
|
|
|
+ info_path.write_text(json.dumps(info), encoding="utf-8")
|
|
|
+ (package / "fw.bit").write_bytes(b"tampered")
|
|
|
self.assertIn(
|
|
|
"package:file_hash",
|
|
|
harness._package_final_failures(
|
|
|
receipt,
|
|
|
expected_commit="a" * 40,
|
|
|
expected_bitstream_sha256=digest,
|
|
|
+ expected_primary_td_receipt_sha256=primary_sha,
|
|
|
+ expected_confirmation_td_receipt_sha256=confirmation_sha,
|
|
|
+ ),
|
|
|
+ )
|
|
|
+
|
|
|
+ incomplete = valid_package_receipt(package, digest=digest)
|
|
|
+ incomplete["verification_complete"] = False
|
|
|
+ self.assertIn(
|
|
|
+ "package:verification_incomplete",
|
|
|
+ harness._package_final_failures(
|
|
|
+ incomplete,
|
|
|
+ expected_commit="a" * 40,
|
|
|
+ expected_bitstream_sha256=digest,
|
|
|
+ expected_primary_td_receipt_sha256=primary_sha,
|
|
|
+ expected_confirmation_td_receipt_sha256=confirmation_sha,
|
|
|
),
|
|
|
)
|
|
|
|
|
|
+ def test_final_package_rechecks_closed_normal_package_and_external_td_bindings(self) -> None:
|
|
|
+ mutations = (
|
|
|
+ ("urgent_receipt", "package:delivery_mode", lambda package, receipt: receipt.__setitem__("delivery_mode", "urgent_single_td")),
|
|
|
+ ("urgent_info", "package:info_delivery_mode", lambda package, receipt: update_package_info(package, delivery_mode="urgent_single_td")),
|
|
|
+ ("false_info_verification", "package:info_verification_incomplete", lambda package, receipt: update_package_info(package, verification_complete=False)),
|
|
|
+ ("false_info_confirmation", "package:info_confirmation_td_missing", lambda package, receipt: update_package_info(package, confirmation_td_present=False)),
|
|
|
+ ("missing_confirmation", "package:required_file", lambda package, receipt: (package / "evidence" / "td-confirmation-receipt.json").unlink()),
|
|
|
+ ("missing_validation", "package:required_file", lambda package, receipt: (package / "evidence" / "validation-summary.json").unlink()),
|
|
|
+ ("missing_selftest", "package:required_file", lambda package, receipt: (package / "evidence" / "package-selftest-result.json").unlink()),
|
|
|
+ )
|
|
|
+ for name, expected, mutate in mutations:
|
|
|
+ with self.subTest(name=name), tempfile.TemporaryDirectory(dir=ROOT.parent) as temporary:
|
|
|
+ package = Path(temporary) / "package"
|
|
|
+ receipt, _, _ = materialize_valid_package(package)
|
|
|
+ mutate(package, receipt)
|
|
|
+ failures = harness._package_final_failures(
|
|
|
+ receipt,
|
|
|
+ expected_commit="a" * 40,
|
|
|
+ expected_bitstream_sha256=str(receipt["bitstream_sha256"]),
|
|
|
+ expected_primary_td_receipt_sha256=str(receipt["td_receipt_sha256"]),
|
|
|
+ expected_confirmation_td_receipt_sha256=str(
|
|
|
+ receipt["confirmation_td_receipt_sha256"]
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ self.assertTrue(
|
|
|
+ any(item.startswith(expected) for item in failures),
|
|
|
+ failures,
|
|
|
+ )
|
|
|
+
|
|
|
+ with tempfile.TemporaryDirectory(dir=ROOT.parent) as temporary:
|
|
|
+ package = Path(temporary) / "package"
|
|
|
+ receipt, _, _ = materialize_valid_package(package)
|
|
|
+ failures = harness._package_final_failures(
|
|
|
+ receipt,
|
|
|
+ expected_commit="a" * 40,
|
|
|
+ expected_bitstream_sha256=str(receipt["bitstream_sha256"]),
|
|
|
+ expected_primary_td_receipt_sha256="0" * 64,
|
|
|
+ expected_confirmation_td_receipt_sha256="1" * 64,
|
|
|
+ )
|
|
|
+ self.assertIn("package:primary_td_external_binding", failures)
|
|
|
+ self.assertIn("package:confirmation_td_external_binding", failures)
|
|
|
+
|
|
|
+ def test_package_validator_preserves_running_but_final_gate_rejects_it(self) -> None:
|
|
|
+ bitstream_bytes = b"running-validation-package"
|
|
|
+ digest = hashlib.sha256(bitstream_bytes).hexdigest()
|
|
|
+ commit = "a" * 40
|
|
|
+ with tempfile.TemporaryDirectory(dir=ROOT.parent) as temporary:
|
|
|
+ package = (
|
|
|
+ Path(temporary)
|
|
|
+ / commit
|
|
|
+ / f"prod2u-p4-normal-{commit}-{digest[:16]}"
|
|
|
+ )
|
|
|
+ receipt, _, _ = materialize_valid_package(
|
|
|
+ package,
|
|
|
+ bitstream_bytes=bitstream_bytes,
|
|
|
+ commit=commit,
|
|
|
+ )
|
|
|
+ validation_path = package / "evidence" / "validation-summary.json"
|
|
|
+ validation = json.loads(validation_path.read_text(encoding="utf-8"))
|
|
|
+ validation["layers"]["td_confirmation"]["status"] = "running"
|
|
|
+ validation_path.write_text(json.dumps(validation), encoding="utf-8")
|
|
|
+ refresh_package_bindings(package, receipt)
|
|
|
+
|
|
|
+ completed = subprocess.CompletedProcess(
|
|
|
+ ["powershell.exe"], 0, stdout="selftest pass", stderr=""
|
|
|
+ )
|
|
|
+ with mock.patch.object(harness.subprocess, "run", return_value=completed):
|
|
|
+ observed = harness.package_selftest_payload(package)
|
|
|
+
|
|
|
+ self.assertEqual(observed["status"], "pass", observed["failures"])
|
|
|
+ self.assertEqual(observed["validation_status"], "running")
|
|
|
+ receipt.update(observed)
|
|
|
+ failures = harness._package_final_failures(
|
|
|
+ receipt,
|
|
|
+ expected_commit=commit,
|
|
|
+ expected_bitstream_sha256=digest,
|
|
|
+ expected_primary_td_receipt_sha256=str(receipt["td_receipt_sha256"]),
|
|
|
+ expected_confirmation_td_receipt_sha256=str(
|
|
|
+ receipt["confirmation_td_receipt_sha256"]
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ self.assertIn("package:validation_incomplete", failures)
|
|
|
+
|
|
|
+ def test_urgent_validator_allows_running_td_confirmation_only(self) -> None:
|
|
|
+ bitstream_bytes = b"urgent-running-confirmation"
|
|
|
+ digest = hashlib.sha256(bitstream_bytes).hexdigest()
|
|
|
+ commit = "a" * 40
|
|
|
+ with tempfile.TemporaryDirectory(dir=ROOT.parent) as temporary:
|
|
|
+ package = (
|
|
|
+ Path(temporary)
|
|
|
+ / commit
|
|
|
+ / f"prod2u-p4-normal-{commit}-{digest[:16]}"
|
|
|
+ )
|
|
|
+ receipt, _, _ = materialize_valid_package(
|
|
|
+ package,
|
|
|
+ bitstream_bytes=bitstream_bytes,
|
|
|
+ commit=commit,
|
|
|
+ )
|
|
|
+ (package / "evidence" / "td-confirmation-receipt.json").unlink()
|
|
|
+ info_path = package / "package-info.json"
|
|
|
+ info = json.loads(info_path.read_text(encoding="utf-8"))
|
|
|
+ info.update(
|
|
|
+ {
|
|
|
+ "delivery_mode": "urgent_single_td",
|
|
|
+ "verification_complete": False,
|
|
|
+ "confirmation_td_present": False,
|
|
|
+ "confirmation_bitstream_sha256": None,
|
|
|
+ "confirmation_synthesis_input_hash": None,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ info_path.write_text(json.dumps(info), encoding="utf-8")
|
|
|
+ validation_path = package / "evidence" / "validation-summary.json"
|
|
|
+ validation = json.loads(validation_path.read_text(encoding="utf-8"))
|
|
|
+ validation.update(
|
|
|
+ {
|
|
|
+ "delivery_mode": "urgent_single_td",
|
|
|
+ "verification_complete": False,
|
|
|
+ "confirmation_td_present": False,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ validation["layers"]["td_confirmation"]["status"] = "running"
|
|
|
+ for name in (
|
|
|
+ "td_confirmation_artifacts",
|
|
|
+ "td_confirmation_bitstream",
|
|
|
+ "td_confirmation_synthesis",
|
|
|
+ "td_confirmation_manifest",
|
|
|
+ "resource_confirmation",
|
|
|
+ ):
|
|
|
+ validation["layers"][name]["status"] = "not_run"
|
|
|
+ validation_path.write_text(json.dumps(validation), encoding="utf-8")
|
|
|
+ refresh_package_bindings(package, receipt)
|
|
|
+
|
|
|
+ completed = subprocess.CompletedProcess(
|
|
|
+ ["powershell.exe"], 0, stdout="selftest pass", stderr=""
|
|
|
+ )
|
|
|
+ with mock.patch.object(harness.subprocess, "run", return_value=completed):
|
|
|
+ observed = harness.package_selftest_payload(package)
|
|
|
+
|
|
|
+ self.assertEqual(observed["status"], "pass", observed["failures"])
|
|
|
+ self.assertEqual(observed["validation_status"], "running")
|
|
|
+
|
|
|
def test_final_gate_rejects_two_td_receipts_from_same_run_or_work_root(self) -> None:
|
|
|
with tempfile.TemporaryDirectory(dir=ROOT.parent) as temporary:
|
|
|
root = Path(temporary)
|
|
|
bitstream = root / "td.bit"
|
|
|
bitstream.write_bytes(b"two-build-final-gate")
|
|
|
digest = harness.sha256_file(bitstream)
|
|
|
- primary = valid_td_receipt(bitstream)
|
|
|
- confirmation = copy.deepcopy(primary)
|
|
|
package = root / "package"
|
|
|
- package.mkdir(parents=True)
|
|
|
- (package / "fw.bit").write_bytes(bitstream.read_bytes())
|
|
|
- (package / "package-info.json").write_text(
|
|
|
- json.dumps({"commit": "a" * 40, "bitstream_sha256": digest}),
|
|
|
- encoding="utf-8",
|
|
|
+ package_receipt, packaged_primary, packaged_confirmation = (
|
|
|
+ materialize_valid_package(
|
|
|
+ package,
|
|
|
+ bitstream_bytes=bitstream.read_bytes(),
|
|
|
+ )
|
|
|
)
|
|
|
+ primary = packaged_primary
|
|
|
+ confirmation = copy.deepcopy(packaged_primary)
|
|
|
+ packaged_confirmation = confirmation
|
|
|
receipts = {
|
|
|
"offline": valid_offline_receipt(),
|
|
|
"td": primary,
|
|
|
"td_confirmation": confirmation,
|
|
|
- "package": valid_package_receipt(package, digest=digest),
|
|
|
+ "package": package_receipt,
|
|
|
}
|
|
|
paths = {}
|
|
|
for name, payload in receipts.items():
|
|
|
@@ -582,6 +1090,20 @@ class Prod2UP4HarnessTests(unittest.TestCase):
|
|
|
|
|
|
confirmation["run_id"] = "2" * 32
|
|
|
confirmation["work_root"] = "C:/td-b"
|
|
|
+ packaged_confirmation["run_id"] = confirmation["run_id"]
|
|
|
+ packaged_confirmation["work_root"] = confirmation["work_root"]
|
|
|
+ packaged_primary_path = package / "evidence" / "td-primary-receipt.json"
|
|
|
+ packaged_confirmation_path = (
|
|
|
+ package / "evidence" / "td-confirmation-receipt.json"
|
|
|
+ )
|
|
|
+ packaged_primary_path.write_text(
|
|
|
+ json.dumps(packaged_primary), encoding="utf-8"
|
|
|
+ )
|
|
|
+ packaged_confirmation_path.write_text(
|
|
|
+ json.dumps(packaged_confirmation), encoding="utf-8"
|
|
|
+ )
|
|
|
+ refresh_package_bindings(package, package_receipt)
|
|
|
+ paths["package"].write_text(json.dumps(package_receipt), encoding="utf-8")
|
|
|
paths["td_confirmation"].write_text(json.dumps(confirmation), encoding="utf-8")
|
|
|
with (
|
|
|
mock.patch.object(
|