| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- """Unit smoke for Round-9 cross-package verifier helpers."""
- from __future__ import annotations
- import io
- import json
- import zipfile
- from pathlib import Path
- from tools.cross_package_verify import verify_cross_package
- def _zip_with(identity: dict, bit: bytes, *, role: str, name: str) -> Path:
- import tempfile
- td = Path(tempfile.mkdtemp())
- path = td / name
- with zipfile.ZipFile(path, "w") as zf:
- zf.writestr("meta/release-set-identity.json", json.dumps(identity))
- zf.writestr(
- "meta/release-set-sibling.json",
- json.dumps({"this_role": role, "release_set_id": identity["release_set_id"]}),
- )
- if role == "review-compact":
- zf.writestr("evidence/bitstream/prod2u_p4_normal_v3.bit", bit)
- else:
- zf.writestr("fw.bit", bit)
- return path
- def test_cross_package_pass_and_mismatch():
- ident = {
- "release_set_id": "set-1",
- "base_dev_commit": "d4f3df",
- "matrix_verification_tip": "abc",
- "software_verification_run_id": "mse-r9",
- "td_bound_commit": "ff44128a",
- "artifact_source_commit": "ff44128a",
- "delivery_commit": "deadbeef",
- "bitstream_sha256": "0" * 64, # will mismatch unless we set correctly
- "td_verification_run_id": "v",
- "td_artifact_run_id": "dd4179c5e7ae4a0190f29d8a476cb157",
- "td_receipt_sha256": "c" * 64,
- "production_binding": "37/37/0/0",
- "reference_set_fingerprint": "r" * 64,
- "package_stage": "final-review",
- "hardware_validation": "not_run",
- "production_polarity_fingerprint": "p" * 64,
- "production_polarity_config": {"dir_close_level": [1, 1, 1]},
- "lut": 4320,
- "mslice": 1089,
- "dsp": 1,
- }
- bit = b"bitstream-bytes-demo"
- import hashlib
- ident["bitstream_sha256"] = hashlib.sha256(bit).hexdigest()
- review = _zip_with(ident, bit, role="review-compact", name="r.zip")
- firmware = _zip_with(ident, bit, role="firmware", name="f.zip")
- ok = verify_cross_package(review, firmware)
- assert ok["status"] == "pass", ok
- bad = dict(ident)
- bad["release_set_id"] = "other"
- firmware_bad = _zip_with(bad, bit, role="firmware", name="f2.zip")
- fail = verify_cross_package(review, firmware_bad)
- assert fail["status"] == "fail"
- assert "release_set_id_mismatch" in fail["failures"]
|