test_codex_harness.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_normal_v3_build
  8. class CodexHarnessTests(unittest.TestCase):
  9. def test_run_id_is_lowercase_32_hex(self):
  10. value = codex_harness.new_run_id()
  11. self.assertRegex(value, r"^[0-9a-f]{32}$")
  12. def test_source_manifest_is_project_bound_and_excludes_legacy_protocol_sources(self):
  13. manifest = codex_harness.build_source_manifest(Path.cwd())
  14. paths = manifest["sources"]
  15. self.assertIn("src/top/prod2u_p4_normal_v3_top.v", paths)
  16. self.assertIn("src/common/frame_rx.v", paths)
  17. self.assertNotIn("src/rtl/binary921_crc16.v", paths)
  18. self.assertNotIn("src/rtl/binary921_frame_tx.v", paths)
  19. self.assertEqual(manifest["project_id"], "prod2u-door-temp")
  20. self.assertRegex(manifest["project_sha256"], r"^[0-9a-f]{64}$")
  21. def test_unverified_package_binds_commit_project_and_bitstream_hash(self):
  22. with tempfile.TemporaryDirectory() as directory:
  23. root = Path(directory)
  24. bitstream = root / "candidate.bit"
  25. bitstream.write_bytes(b"candidate-bitstream")
  26. project = root / "project.json"
  27. project.write_text('{"project_id":"prod2u-door-temp"}\n', encoding="utf-8")
  28. package = codex_harness.create_unverified_package(
  29. bitstream=bitstream,
  30. project=project,
  31. commit="0123abcd",
  32. run_id="a" * 32,
  33. output_root=root / "dist",
  34. )
  35. manifest = json.loads((package / "package_manifest.json").read_text(encoding="utf-8"))
  36. self.assertEqual(manifest["status"], "UNVERIFIED")
  37. self.assertEqual(manifest["commit"], "0123abcd")
  38. self.assertEqual(manifest["run_id"], "a" * 32)
  39. self.assertEqual(
  40. manifest["bitstream_sha256"],
  41. hashlib.sha256(b"candidate-bitstream").hexdigest(),
  42. )
  43. self.assertTrue((package / "candidate.bit").is_file())
  44. def test_build_source_list_and_build_info_use_only_the_new_contract(self):
  45. sources = prod2u_p4_normal_v3_build.PRODUCTION_RTL_SOURCES
  46. self.assertIn("src/common/frame_rx.v", sources)
  47. self.assertIn("src/top/prod2u_p4_normal_v3_top.v", sources)
  48. self.assertNotIn("src/rtl/binary921_crc16.v", sources)
  49. self.assertNotIn("src/rtl/prod2u_p4_normal_v3_watchdog.v", sources)
  50. with tempfile.TemporaryDirectory() as directory:
  51. bitstream = Path(directory) / "candidate.bit"
  52. bitstream.write_bytes(b"candidate")
  53. info = prod2u_p4_normal_v3_build.create_build_info(
  54. bitstream=bitstream,
  55. commit="0123abcd",
  56. )
  57. self.assertEqual(info["serial"], {"baud": 115200, "format": "8N1", "flow_control": "none"})
  58. self.assertEqual(
  59. info["hardware_access"],
  60. {"com": False, "jtag": False, "programming": False, "drivers": False},
  61. )
  62. if __name__ == "__main__":
  63. unittest.main()