test_provenance_binding.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from __future__ import annotations
  2. import copy
  3. import importlib.util
  4. import json
  5. from pathlib import Path
  6. import pytest
  7. RUNNER_PATH = Path(__file__).with_name("run_hthd_6400_pty_rtl.py")
  8. SPEC = importlib.util.spec_from_file_location("hth_6400_rtl_runner", RUNNER_PATH)
  9. assert SPEC is not None and SPEC.loader is not None
  10. RUNNER = importlib.util.module_from_spec(SPEC)
  11. SPEC.loader.exec_module(RUNNER)
  12. BUILD_PATH = RUNNER.HOST / "tools" / "build_amd64_release.py"
  13. BUILD_SPEC = importlib.util.spec_from_file_location("hth_amd64_release_builder", BUILD_PATH)
  14. assert BUILD_SPEC is not None and BUILD_SPEC.loader is not None
  15. BUILD = importlib.util.module_from_spec(BUILD_SPEC)
  16. BUILD_SPEC.loader.exec_module(BUILD)
  17. def imported() -> dict[str, object]:
  18. return json.loads(RUNNER.IMPORT_META.read_text(encoding="utf-8"))
  19. def test_v11_commit_binds_functional_and_package_sources() -> None:
  20. provenance = imported()
  21. assert provenance["source_commit"] == "4a140b10e4227bf426d9cc5a3ae8617330f728a7"
  22. assert provenance["package_commit"] == "4a140b10e4227bf426d9cc5a3ae8617330f728a7"
  23. assert provenance["contract_sha256"] == (
  24. "9b2df5161fb37e4b84af8337c5e99a78e27b6058934a245068afd2d533468def"
  25. )
  26. assert provenance["source_commit"] == provenance["package_commit"]
  27. sources = RUNNER._bound_sources_from_import(provenance)
  28. assert any(path.name == "prod2u_6400_v1_top.v" for path in sources)
  29. assert any(path.name == "prod2u_6400_rs232_only_top.v" for path in sources)
  30. def test_exact_source_hash_gate_rejects_drift() -> None:
  31. provenance = copy.deepcopy(imported())
  32. file_hashes = provenance["source_input_file_sha256"]
  33. assert isinstance(file_hashes, dict)
  34. file_hashes["src/top/prod2u_6400_v1_top.v"] = "0" * 64
  35. with pytest.raises(RuntimeError, match="CPLD source input .* SHA"):
  36. RUNNER._bound_sources_from_import(provenance)
  37. def test_release_metadata_binds_current_v11_rebuild_commit() -> None:
  38. value = BUILD.cpld_provenance(RUNNER.HOST)
  39. assert value["functional_source_commit"] == (
  40. "4a140b10e4227bf426d9cc5a3ae8617330f728a7"
  41. )
  42. assert value["package_commit"] == "4a140b10e4227bf426d9cc5a3ae8617330f728a7"
  43. assert value["td_bitstream_source_commit"] == value["functional_source_commit"]
  44. assert value["td_bitstream_rebuilt_from_package_commit"] is True
  45. assert value["firmware_artifact_included"] is False