test_mse_r9_cross_package.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """Unit smoke for Round-9 cross-package verifier helpers."""
  2. from __future__ import annotations
  3. import io
  4. import json
  5. import zipfile
  6. from pathlib import Path
  7. from tools.cross_package_verify import verify_cross_package
  8. def _zip_with(identity: dict, bit: bytes, *, role: str, name: str) -> Path:
  9. import tempfile
  10. td = Path(tempfile.mkdtemp())
  11. path = td / name
  12. with zipfile.ZipFile(path, "w") as zf:
  13. zf.writestr("meta/release-set-identity.json", json.dumps(identity))
  14. zf.writestr(
  15. "meta/release-set-sibling.json",
  16. json.dumps({"this_role": role, "release_set_id": identity["release_set_id"]}),
  17. )
  18. if role == "review-compact":
  19. zf.writestr("evidence/bitstream/prod2u_p4_normal_v3.bit", bit)
  20. else:
  21. zf.writestr("fw.bit", bit)
  22. return path
  23. def test_cross_package_pass_and_mismatch():
  24. ident = {
  25. "release_set_id": "set-1",
  26. "base_dev_commit": "d4f3df",
  27. "matrix_verification_tip": "abc",
  28. "software_verification_run_id": "mse-r9",
  29. "td_bound_commit": "ff44128a",
  30. "artifact_source_commit": "ff44128a",
  31. "delivery_commit": "deadbeef",
  32. "bitstream_sha256": "0" * 64, # will mismatch unless we set correctly
  33. "td_verification_run_id": "v",
  34. "td_artifact_run_id": "dd4179c5e7ae4a0190f29d8a476cb157",
  35. "td_receipt_sha256": "c" * 64,
  36. "production_binding": "37/37/0/0",
  37. "reference_set_fingerprint": "r" * 64,
  38. "package_stage": "final-review",
  39. "hardware_validation": "not_run",
  40. "production_polarity_fingerprint": "p" * 64,
  41. "production_polarity_config": {"dir_close_level": [1, 1, 1]},
  42. "lut": 4320,
  43. "mslice": 1089,
  44. "dsp": 1,
  45. }
  46. bit = b"bitstream-bytes-demo"
  47. import hashlib
  48. ident["bitstream_sha256"] = hashlib.sha256(bit).hexdigest()
  49. review = _zip_with(ident, bit, role="review-compact", name="r.zip")
  50. firmware = _zip_with(ident, bit, role="firmware", name="f.zip")
  51. ok = verify_cross_package(review, firmware)
  52. assert ok["status"] == "pass", ok
  53. bad = dict(ident)
  54. bad["release_set_id"] = "other"
  55. firmware_bad = _zip_with(bad, bit, role="firmware", name="f2.zip")
  56. fail = verify_cross_package(review, firmware_bad)
  57. assert fail["status"] == "fail"
  58. assert "release_set_id_mismatch" in fail["failures"]