test_mse_r10_td_resources.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. """Round-10: TD resource parser and production-source hash compare."""
  2. from __future__ import annotations
  3. import json
  4. from pathlib import Path
  5. from tools import package_provenance as pkg_prov
  6. ROOT = Path(__file__).resolve().parents[2]
  7. def test_parse_td_resources_keeps_explicit_mslice_1089():
  8. compact = {
  9. "lut": 3901,
  10. "mslice": 1089,
  11. "dsp": 1,
  12. "resources": {
  13. "utilization": {
  14. "lut": {"used": 4320},
  15. "dsp": {"used": 1},
  16. },
  17. "packing": {"mslice": 1089, "lslice": 1089, "total_slices": 2178},
  18. },
  19. }
  20. parsed = pkg_prov.parse_td_resource_fields(compact)
  21. assert parsed["lut"] == 4320
  22. assert parsed["mslice"] == 1089
  23. assert parsed["dsp"] == 1
  24. def test_parse_td_resources_never_falls_back_lut_to_mslice():
  25. compact = {
  26. "resources": {
  27. "utilization": {
  28. "lut": {"used": 4320},
  29. "le": {"used": 4320},
  30. "dsp": {"used": 1},
  31. }
  32. }
  33. }
  34. parsed = pkg_prov.parse_td_resource_fields(compact)
  35. assert parsed["lut"] == 4320
  36. assert parsed["mslice"] is None
  37. assert parsed["dsp"] == 1
  38. def test_canonical_identity_mslice_is_1089_not_4320():
  39. td = pkg_prov.load_canonical_td_a1_fields(ROOT)
  40. ident = pkg_prov.build_shared_release_identity(
  41. delivery_commit="d91a7b46a37371d9a03ae47c5245da2eb4561772",
  42. package_stage="intermediate-review",
  43. matrix_verification_tip="d126c3df0ceef3de4d559b60253fb5336da11922",
  44. software_verification_run_id="mse-r9-20260812T163229Z",
  45. config_fingerprint="x",
  46. reference_set_fingerprint="y",
  47. repo_root=ROOT,
  48. claim_bound_bitstream=True,
  49. )
  50. assert td["mslice"] == 1089
  51. assert ident["mslice"] == 1089
  52. assert ident["lut"] == 4320
  53. def test_artifact_to_delivery_hash_compare_not_commit_equality():
  54. artifact = "ff44128a540b7ffd9d82314093b242ac3aee92d7"
  55. delivery = "d91a7b46a37371d9a03ae47c5245da2eb4561772"
  56. assert artifact != delivery
  57. cmp_ = pkg_prov.compare_production_source_commits(
  58. from_commit=artifact,
  59. to_commit=delivery,
  60. repo_root=ROOT,
  61. )
  62. assert cmp_["unchanged"] is True
  63. assert cmp_["production_changed_paths"] == []
  64. rel = pkg_prov.build_source_closure_relations(
  65. old_baseline_commit=pkg_prov.BASE_DEV_COMMIT_DEFAULT,
  66. artifact_commit=artifact,
  67. delivery_commit=delivery,
  68. old_to_artifact_unchanged=False,
  69. artifact_to_delivery_unchanged=True,
  70. old_to_artifact_changed_paths=["projects/prod2u-door-temp/project.json"],
  71. artifact_to_delivery_changed_paths=[],
  72. comparison_mode="snapshot_hash",
  73. )
  74. check = pkg_prov.validate_source_closure_relations(rel)
  75. assert check["status"] == "pass", check
  76. def test_snapshot_hash_false_empty_paths_fails():
  77. rel = pkg_prov.build_source_closure_relations(
  78. old_baseline_commit=pkg_prov.BASE_DEV_COMMIT_DEFAULT,
  79. artifact_commit="aa",
  80. delivery_commit="bb",
  81. old_to_artifact_unchanged=False,
  82. artifact_to_delivery_unchanged=False,
  83. old_to_artifact_changed_paths=[],
  84. artifact_to_delivery_changed_paths=[],
  85. comparison_mode="snapshot_hash",
  86. )
  87. check = pkg_prov.validate_source_closure_relations(rel)
  88. assert check["status"] == "fail"
  89. assert any("empty_paths" in f for f in check["failures"])
  90. def test_load_td_identity_fields_fresh_not_canonical(tmp_path: Path):
  91. bitstream = "a" * 64
  92. bound = "c9e7e2b90d60b5018d859b67a55fb162ad0eca39"
  93. receipt = tmp_path / "td-receipt.json"
  94. doc = {
  95. "status": "pass",
  96. "run_id": "018969d8b4194ba285ca6dd18c1180bf",
  97. "verification_run_id": "e10d2026081301474900000000000000",
  98. "commit": bound,
  99. "commit_full": bound,
  100. "bitstream_sha256": bitstream,
  101. "mslice": 1089,
  102. "synthesis_input_manifest": {"inputs": {f"f{i}.v": "b" * 64 for i in range(37)}},
  103. "resources": {
  104. "utilization": {
  105. "lut": {"used": 4320},
  106. "dsp": {"used": 1},
  107. },
  108. "packing": {"mslice": 1089, "lslice": 1089, "total_slices": 2178},
  109. },
  110. }
  111. receipt.write_text(json.dumps(doc), encoding="utf-8")
  112. fields = pkg_prov.load_td_identity_fields(receipt, repo_root=ROOT)
  113. assert fields["bitstream_sha256"] == bitstream
  114. assert fields["bitstream_sha256"] != pkg_prov.CANONICAL_TD_A1_BITSTREAM
  115. assert fields["td_bound_commit"] == bound
  116. assert fields["td_artifact_run_id"] == "018969d8b4194ba285ca6dd18c1180bf"
  117. assert fields["lut"] == 4320
  118. assert fields["mslice"] == 1089
  119. assert fields["dsp"] == 1
  120. assert fields["td_policy"] == "fresh_td"
  121. assert fields["production_binding"] == "37/37/0/0"
  122. ident = pkg_prov.build_shared_release_identity(
  123. delivery_commit="d" * 40,
  124. package_stage="final-review",
  125. matrix_verification_tip="e" * 40,
  126. software_verification_run_id="mse-r10-test",
  127. config_fingerprint="x",
  128. reference_set_fingerprint="y",
  129. repo_root=ROOT,
  130. claim_bound_bitstream=True,
  131. td_fields=fields,
  132. )
  133. assert ident["bitstream_sha256"] == bitstream
  134. assert ident["artifact_source_commit"] == bound
  135. assert ident["lut"] == 4320
  136. assert ident["mslice"] == 1089
  137. assert ident["td_policy"] == "fresh_td"
  138. canonical = pkg_prov.load_canonical_td_a1_fields(ROOT)
  139. assert ident["release_set_id"] != pkg_prov.build_shared_release_identity(
  140. delivery_commit="d" * 40,
  141. package_stage="final-review",
  142. matrix_verification_tip="e" * 40,
  143. software_verification_run_id="mse-r10-test",
  144. config_fingerprint="x",
  145. reference_set_fingerprint="y",
  146. repo_root=ROOT,
  147. claim_bound_bitstream=True,
  148. )["release_set_id"]
  149. assert canonical["bitstream_sha256"] == pkg_prov.CANONICAL_TD_A1_BITSTREAM