test_codex_harness.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import hashlib
  2. import json
  3. import tempfile
  4. import unittest
  5. from pathlib import Path
  6. from tools import codex_harness
  7. from tools import prod2u_p4_harness
  8. from tools import prod2u_p4_normal_v3_build
  9. class CodexHarnessTests(unittest.TestCase):
  10. def test_run_id_is_lowercase_32_hex(self):
  11. value = codex_harness.new_run_id()
  12. self.assertRegex(value, r"^[0-9a-f]{32}$")
  13. def test_source_manifest_is_project_bound_and_excludes_legacy_protocol_sources(self):
  14. manifest = codex_harness.build_source_manifest(Path.cwd())
  15. paths = manifest["sources"]
  16. self.assertIn("src/top/prod2u_p4_normal_v3_top.v", paths)
  17. self.assertIn("src/common/frame_rx.v", paths)
  18. self.assertNotIn("src/rtl/binary921_crc16.v", paths)
  19. self.assertNotIn("src/rtl/binary921_frame_tx.v", paths)
  20. self.assertEqual(manifest["project_id"], "prod2u-door-temp")
  21. self.assertRegex(manifest["project_sha256"], r"^[0-9a-f]{64}$")
  22. def test_unverified_package_binds_commit_project_and_bitstream_hash(self):
  23. with tempfile.TemporaryDirectory() as directory:
  24. root = Path(directory)
  25. bitstream = root / "candidate.bit"
  26. bitstream.write_bytes(b"candidate-bitstream")
  27. project = root / "project.json"
  28. project.write_text('{"project_id":"prod2u-door-temp"}\n', encoding="utf-8")
  29. package = codex_harness.create_unverified_package(
  30. bitstream=bitstream,
  31. project=project,
  32. commit="0123abcd",
  33. run_id="a" * 32,
  34. output_root=root / "dist",
  35. )
  36. manifest = json.loads((package / "package_manifest.json").read_text(encoding="utf-8"))
  37. self.assertEqual(manifest["status"], "UNVERIFIED")
  38. self.assertEqual(manifest["commit"], "0123abcd")
  39. self.assertEqual(manifest["run_id"], "a" * 32)
  40. self.assertEqual(
  41. manifest["bitstream_sha256"],
  42. hashlib.sha256(b"candidate-bitstream").hexdigest(),
  43. )
  44. self.assertTrue((package / "candidate.bit").is_file())
  45. def test_build_source_list_and_build_info_use_only_the_new_contract(self):
  46. sources = prod2u_p4_normal_v3_build.PRODUCTION_RTL_SOURCES
  47. self.assertIn("src/common/frame_rx.v", sources)
  48. self.assertIn("src/top/prod2u_p4_normal_v3_top.v", sources)
  49. self.assertNotIn("src/rtl/binary921_crc16.v", sources)
  50. self.assertNotIn("src/rtl/prod2u_p4_normal_v3_watchdog.v", sources)
  51. with tempfile.TemporaryDirectory() as directory:
  52. bitstream = Path(directory) / "candidate.bit"
  53. bitstream.write_bytes(b"candidate")
  54. info = prod2u_p4_normal_v3_build.create_build_info(
  55. bitstream=bitstream,
  56. commit="0123abcd",
  57. )
  58. self.assertEqual(info["serial"], {"baud": 115200, "format": "8N1", "flow_control": "none"})
  59. self.assertEqual(
  60. info["hardware_access"],
  61. {"com": False, "jtag": False, "programming": False, "drivers": False},
  62. )
  63. def test_runtime_profile_is_the_new_115200_contract(self):
  64. self.assertEqual(
  65. prod2u_p4_harness.RUNTIME_PROFILE,
  66. "prod2u-door-temp-115200-v1",
  67. )
  68. def test_qor_attribute_count_accepts_td_gate_qor_name(self):
  69. with tempfile.TemporaryDirectory() as directory:
  70. root = Path(directory)
  71. (root / "gate.qor").write_text(
  72. "| #async_reg | 6 |\n",
  73. encoding="ascii",
  74. )
  75. observed = prod2u_p4_harness.parse_qor_attribute_count(
  76. root / "prod2u_p4_normal_v3_gate.qor",
  77. "async_reg",
  78. )
  79. self.assertEqual(observed, 6)
  80. def test_verification_inventory_uses_only_the_current_manifest(self):
  81. manifest = prod2u_p4_harness.load_target_manifest()
  82. self.assertEqual(
  83. manifest["schema"],
  84. "prod2u-simple-verification-target-manifest-v1",
  85. )
  86. self.assertEqual(
  87. [target["name"] for target in prod2u_p4_harness.cocotb_tests()],
  88. ["prod2u_door_temp_uart_e2e"],
  89. )
  90. self.assertEqual(
  91. [target["name"] for target in prod2u_p4_harness.formal_targets()],
  92. ["simple_frame_contract", "simple_motor_temperature_contract"],
  93. )
  94. icarus_names = [target["name"] for target in prod2u_p4_harness.hdl_testbenches()]
  95. self.assertEqual(
  96. icarus_names,
  97. sorted(manifest["layers"]["icarus"]),
  98. )
  99. if __name__ == "__main__":
  100. unittest.main()