|
|
@@ -3,6 +3,7 @@
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
+import hashlib
|
|
|
import json
|
|
|
import shutil
|
|
|
import subprocess
|
|
|
@@ -11,27 +12,52 @@ import tempfile
|
|
|
import unittest
|
|
|
import zipfile
|
|
|
from pathlib import Path
|
|
|
+from unittest import mock
|
|
|
|
|
|
TOOLS = Path(__file__).resolve().parents[2] / "tools"
|
|
|
if str(TOOLS) not in sys.path:
|
|
|
sys.path.insert(0, str(TOOLS))
|
|
|
|
|
|
import build_firmware_package as builder
|
|
|
-
|
|
|
+import package_provenance as pkg_prov
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
+FAKE_BITS = b"FAKEBITS"
|
|
|
+FAKE_BIT_SHA = hashlib.sha256(FAKE_BITS).hexdigest()
|
|
|
+FAKE_TD_RUN_ID = "td-run-123"
|
|
|
|
|
|
|
|
|
def _current_project_sha() -> str:
|
|
|
return builder._sha256_file(ROOT / "projects" / "prod2u-door-temp" / "project.json")
|
|
|
|
|
|
|
|
|
+def _patch_canonical_td_for_fake(*, bits: bytes = FAKE_BITS, run_id: str = FAKE_TD_RUN_ID):
|
|
|
+ """Unit fixtures use fake bits; align shared identity to those bytes."""
|
|
|
+ sha = hashlib.sha256(bits).hexdigest()
|
|
|
+ fields = {
|
|
|
+ "artifact_source_commit": "fe1a0a2a19622b6f290905ec14795bb6cce6899d",
|
|
|
+ "td_bound_commit": "fe1a0a2a19622b6f290905ec14795bb6cce6899d",
|
|
|
+ "bitstream_sha256": sha,
|
|
|
+ "td_artifact_run_id": run_id,
|
|
|
+ "td_verification_run_id": "88888888888888888888888888888888",
|
|
|
+ "td_receipt_path": "receipts/mse-r4-td-a1-ff44128.json",
|
|
|
+ "td_receipt_sha256": "c" * 64,
|
|
|
+ "td_binding_status": "pass",
|
|
|
+ "production_binding": "37/37/0/0",
|
|
|
+ "lut": 1113,
|
|
|
+ "mslice": 570,
|
|
|
+ "dsp": 0,
|
|
|
+ "status": "pass",
|
|
|
+ }
|
|
|
+ return mock.patch.object(pkg_prov, "load_canonical_td_a1_fields", return_value=fields)
|
|
|
+
|
|
|
+
|
|
|
def _write_report(path: Path, *, bitstream_sha256: str | None = None, project_sha: str | None = None) -> None:
|
|
|
project_sha = project_sha or _current_project_sha()
|
|
|
if bitstream_sha256 is None:
|
|
|
- bitstream_sha256 = "2ce6b1913b339453da963d4528ceb09ff93a26e61c9c14626d316bbd91f7243f"
|
|
|
+ bitstream_sha256 = FAKE_BIT_SHA
|
|
|
report = {
|
|
|
- "run_id": "td-run-123",
|
|
|
+ "run_id": FAKE_TD_RUN_ID,
|
|
|
"verification_run_id": "88888888888888888888888888888888",
|
|
|
"commit_full": "fe1a0a2a19622b6f290905ec14795bb6cce6899d",
|
|
|
"project_config_sha256": project_sha,
|
|
|
@@ -69,7 +95,7 @@ class BuildFirmwarePackageTests(unittest.TestCase):
|
|
|
td_root = tmp_path / "td_root"
|
|
|
bitstream = td_root / "td" / "prod2u_p4_normal_v3" / "bitgen" / "prod2u_p4_normal_v3.bit"
|
|
|
bitstream.parent.mkdir(parents=True, exist_ok=True)
|
|
|
- bitstream.write_bytes(b"FAKEBITS")
|
|
|
+ bitstream.write_bytes(FAKE_BITS)
|
|
|
report = td_root / "report.json"
|
|
|
_write_report(report, bitstream_sha256=bitstream_sha256, project_sha=project_sha)
|
|
|
# Add a fake stage log to verify allowlist
|
|
|
@@ -88,17 +114,18 @@ class BuildFirmwarePackageTests(unittest.TestCase):
|
|
|
td_root, bitstream, report = self._make_td_root(tmp_path)
|
|
|
output_dir = tmp_path / "dist"
|
|
|
artifact, matrix, final_dev = self._commits()
|
|
|
- package, sidecar = builder.build_firmware_package(
|
|
|
- output_dir=output_dir,
|
|
|
- package_name="test-firmware-package",
|
|
|
- td_root=td_root,
|
|
|
- bitstream_path=bitstream,
|
|
|
- td_report_path=report,
|
|
|
- artifact_commit=artifact,
|
|
|
- matrix_commit=matrix,
|
|
|
- final_dev_commit=final_dev,
|
|
|
- source_closure_unchanged=True,
|
|
|
- )
|
|
|
+ with _patch_canonical_td_for_fake():
|
|
|
+ package, sidecar = builder.build_firmware_package(
|
|
|
+ output_dir=output_dir,
|
|
|
+ package_name="test-firmware-package",
|
|
|
+ td_root=td_root,
|
|
|
+ bitstream_path=bitstream,
|
|
|
+ td_report_path=report,
|
|
|
+ artifact_commit=artifact,
|
|
|
+ matrix_commit=matrix,
|
|
|
+ final_dev_commit=final_dev,
|
|
|
+ source_closure_unchanged=True,
|
|
|
+ )
|
|
|
self.assertTrue(package.is_file())
|
|
|
with zipfile.ZipFile(package, "r") as zipf:
|
|
|
names = set(zipf.namelist())
|
|
|
@@ -171,17 +198,18 @@ class BuildFirmwarePackageTests(unittest.TestCase):
|
|
|
(ROOT / "td" / "td_20260630_134648.log").write_text("stale", encoding="utf-8")
|
|
|
try:
|
|
|
artifact, matrix, final_dev = self._commits()
|
|
|
- package, _ = builder.build_firmware_package(
|
|
|
- output_dir=tmp_path / "dist",
|
|
|
- package_name="no-stale",
|
|
|
- td_root=td_root,
|
|
|
- bitstream_path=bitstream,
|
|
|
- td_report_path=report,
|
|
|
- artifact_commit=artifact,
|
|
|
- matrix_commit=matrix,
|
|
|
- final_dev_commit=final_dev,
|
|
|
- source_closure_unchanged=True,
|
|
|
- )
|
|
|
+ with _patch_canonical_td_for_fake():
|
|
|
+ package, _ = builder.build_firmware_package(
|
|
|
+ output_dir=tmp_path / "dist",
|
|
|
+ package_name="no-stale",
|
|
|
+ td_root=td_root,
|
|
|
+ bitstream_path=bitstream,
|
|
|
+ td_report_path=report,
|
|
|
+ artifact_commit=artifact,
|
|
|
+ matrix_commit=matrix,
|
|
|
+ final_dev_commit=final_dev,
|
|
|
+ source_closure_unchanged=True,
|
|
|
+ )
|
|
|
with zipfile.ZipFile(package, "r") as zipf:
|
|
|
self.assertNotIn("td/td_20260630_134648.log", set(zipf.namelist()))
|
|
|
finally:
|