| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import hashlib
- import json
- import tempfile
- import unittest
- from pathlib import Path
- from tools import codex_harness
- from tools import prod2u_p4_harness
- from tools import prod2u_p4_normal_v3_build
- class CodexHarnessTests(unittest.TestCase):
- def test_run_id_is_lowercase_32_hex(self):
- value = codex_harness.new_run_id()
- self.assertRegex(value, r"^[0-9a-f]{32}$")
- def test_source_manifest_is_project_bound_and_excludes_legacy_protocol_sources(self):
- manifest = codex_harness.build_source_manifest(Path.cwd())
- paths = manifest["sources"]
- self.assertIn("src/top/prod2u_p4_normal_v3_top.v", paths)
- self.assertIn("src/common/frame_rx.v", paths)
- self.assertNotIn("src/rtl/binary921_crc16.v", paths)
- self.assertNotIn("src/rtl/binary921_frame_tx.v", paths)
- self.assertEqual(manifest["project_id"], "prod2u-door-temp")
- self.assertRegex(manifest["project_sha256"], r"^[0-9a-f]{64}$")
- def test_unverified_package_binds_commit_project_and_bitstream_hash(self):
- with tempfile.TemporaryDirectory() as directory:
- root = Path(directory)
- bitstream = root / "candidate.bit"
- bitstream.write_bytes(b"candidate-bitstream")
- project = root / "project.json"
- project.write_text('{"project_id":"prod2u-door-temp"}\n', encoding="utf-8")
- package = codex_harness.create_unverified_package(
- bitstream=bitstream,
- project=project,
- commit="0123abcd",
- run_id="a" * 32,
- output_root=root / "dist",
- )
- manifest = json.loads((package / "package_manifest.json").read_text(encoding="utf-8"))
- self.assertEqual(manifest["status"], "UNVERIFIED")
- self.assertEqual(manifest["commit"], "0123abcd")
- self.assertEqual(manifest["run_id"], "a" * 32)
- self.assertEqual(
- manifest["bitstream_sha256"],
- hashlib.sha256(b"candidate-bitstream").hexdigest(),
- )
- self.assertTrue((package / "candidate.bit").is_file())
- def test_build_source_list_and_build_info_use_only_the_new_contract(self):
- sources = prod2u_p4_normal_v3_build.PRODUCTION_RTL_SOURCES
- self.assertIn("src/common/frame_rx.v", sources)
- self.assertIn("src/top/prod2u_p4_normal_v3_top.v", sources)
- self.assertNotIn("src/rtl/binary921_crc16.v", sources)
- self.assertNotIn("src/rtl/prod2u_p4_normal_v3_watchdog.v", sources)
- with tempfile.TemporaryDirectory() as directory:
- bitstream = Path(directory) / "candidate.bit"
- bitstream.write_bytes(b"candidate")
- info = prod2u_p4_normal_v3_build.create_build_info(
- bitstream=bitstream,
- commit="0123abcd",
- )
- self.assertEqual(info["serial"], {"baud": 115200, "format": "8N1", "flow_control": "none"})
- self.assertEqual(
- info["hardware_access"],
- {"com": False, "jtag": False, "programming": False, "drivers": False},
- )
- def test_runtime_profile_is_the_new_115200_contract(self):
- self.assertEqual(
- prod2u_p4_harness.RUNTIME_PROFILE,
- "prod2u-door-temp-115200-v1",
- )
- def test_qor_attribute_count_accepts_td_gate_qor_name(self):
- with tempfile.TemporaryDirectory() as directory:
- root = Path(directory)
- (root / "gate.qor").write_text(
- "| #async_reg | 6 |\n",
- encoding="ascii",
- )
- observed = prod2u_p4_harness.parse_qor_attribute_count(
- root / "prod2u_p4_normal_v3_gate.qor",
- "async_reg",
- )
- self.assertEqual(observed, 6)
- def test_verification_inventory_uses_only_the_current_manifest(self):
- manifest = prod2u_p4_harness.load_target_manifest()
- self.assertEqual(
- manifest["schema"],
- "prod2u-simple-verification-target-manifest-v1",
- )
- self.assertEqual(
- [target["name"] for target in prod2u_p4_harness.cocotb_tests()],
- ["prod2u_door_temp_uart_e2e"],
- )
- self.assertEqual(
- [target["name"] for target in prod2u_p4_harness.formal_targets()],
- ["simple_frame_contract", "simple_motor_temperature_contract"],
- )
- icarus_names = [target["name"] for target in prod2u_p4_harness.hdl_testbenches()]
- self.assertEqual(
- icarus_names,
- sorted(manifest["layers"]["icarus"]),
- )
- if __name__ == "__main__":
- unittest.main()
|