run_6400_v1.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/usr/bin/env python3
  2. """Current-run software verification entrypoint for 6400-front-rear-v1."""
  3. from __future__ import annotations
  4. import argparse
  5. import json
  6. import os
  7. from pathlib import Path
  8. import subprocess
  9. import sys
  10. import tempfile
  11. ROOT = Path(__file__).resolve().parents[1]
  12. CLOSURE = ROOT / "products/6400-front-rear/source-closure.json"
  13. TESTBENCHES = (
  14. "frame_rx_tb",
  15. "host_port_selector_tb",
  16. "bmc_ascii_snapshot_tb",
  17. )
  18. PWM_TESTBENCH = "pwm_bitmap_engine_tb"
  19. UART_CANDIDATE_SOURCES = (
  20. "src/common/uart_rx_byte.v",
  21. "src/common/uart_tx_byte.v",
  22. "src/common/uart_rx_byte_fractional.v",
  23. "src/common/uart_tx_byte_fractional.v",
  24. )
  25. def closure() -> dict[str, object]:
  26. return json.loads(CLOSURE.read_text(encoding="utf-8"))
  27. def sources() -> list[str]:
  28. value = closure()
  29. return [item for item in value["sources"] if item.endswith(".v")]
  30. def top_module() -> str:
  31. return str(closure()["top_module"])
  32. def run(argv: list[str]) -> None:
  33. print("+ " + " ".join(argv), flush=True)
  34. env = os.environ.copy()
  35. env.setdefault("PYTHONDONTWRITEBYTECODE", "1")
  36. env.setdefault(
  37. "PYTHONPYCACHEPREFIX",
  38. str(Path(tempfile.gettempdir()) / "prod2u-6400-v1-pycache"),
  39. )
  40. subprocess.run(argv, cwd=ROOT, check=True, env=env)
  41. def generate(check: bool = True) -> None:
  42. argv = [sys.executable, "-B", "tools/generate_6400_manual.py"]
  43. if check:
  44. argv.append("--check")
  45. run(argv)
  46. def lint() -> None:
  47. top = top_module()
  48. run([
  49. "verilator", "--lint-only", "--Wall", "-Wno-fatal", "-Wno-MULTITOP",
  50. "-I.", "--top-module", top, *sources(),
  51. ])
  52. script = (
  53. "read_verilog -I. " + " ".join(sources())
  54. + f"; hierarchy -check -top {top}; "
  55. "select -assert-none t:stimulus_atomic_bank; "
  56. "flatten; proc; opt_clean -purge; check"
  57. )
  58. run(["yosys", "-q", "-p", script])
  59. def simulation() -> None:
  60. with tempfile.TemporaryDirectory(prefix="prod2u-6400-sim-") as directory:
  61. temp = Path(directory)
  62. for name in TESTBENCHES:
  63. output = temp / f"{name}.vvp"
  64. run([
  65. "iverilog", "-g2012", "-Wall", "-I.", "-s", name,
  66. "-o", str(output), *sources(), f"tests/sim/{name}.v",
  67. ])
  68. run(["vvp", str(output)])
  69. run([
  70. "iverilog", "-g2012", "-Wall", "-I.", "-s", top_module(),
  71. "-o", str(temp / "top.vvp"), *sources(),
  72. ])
  73. output = temp / "uart_baud_candidates_tb.vvp"
  74. run([
  75. "iverilog", "-g2012", "-Wall", "-I.", "-s", "uart_baud_candidates_tb",
  76. "-o", str(output), *UART_CANDIDATE_SOURCES, "tests/sim/uart_baud_candidates_tb.v",
  77. ])
  78. run(["vvp", str(output)])
  79. def pwm_acceptance() -> None:
  80. with tempfile.TemporaryDirectory(prefix="prod2u-6400-pwm-") as directory:
  81. output = Path(directory) / f"{PWM_TESTBENCH}.vvp"
  82. run([
  83. "iverilog", "-g2012", "-Wall", "-I.", "-s", PWM_TESTBENCH,
  84. "-o", str(output), *sources(), f"tests/sim/{PWM_TESTBENCH}.v",
  85. ])
  86. run(["vvp", str(output)])
  87. def unit() -> None:
  88. run([
  89. sys.executable, "-B", "-m", "pytest", "-p", "no:cacheprovider", "-q",
  90. "tests/historical/test_6400_v1_contract.py",
  91. "tests/historical/test_6400_v1_source_closure.py",
  92. "tests/historical/test_encode_6400_hex.py",
  93. "tests/unit/test_fw_6400_v1_entrypoint.py",
  94. "tests/unit/test_6400_hex_gui_v2.py",
  95. ])
  96. def cocotb_integration() -> None:
  97. run([sys.executable, "-B", "tests/cocotb/run_6400_v1_integration.py"])
  98. def bmc_fuzz() -> None:
  99. run([sys.executable, "-B", "tests/cocotb/run_6400_bmc_fuzz.py"])
  100. def pi_differential() -> None:
  101. run([sys.executable, "-B", "tests/cocotb/run_6400_pi_differential.py"])
  102. def main(argv: list[str] | None = None) -> int:
  103. parser = argparse.ArgumentParser()
  104. parser.add_argument(
  105. "action",
  106. choices=("generate", "lint", "sim", "cocotb", "bmc", "pwm", "pi", "unit", "all"),
  107. )
  108. args = parser.parse_args(argv)
  109. if args.action in ("generate", "all"):
  110. generate()
  111. if args.action in ("lint", "all"):
  112. lint()
  113. if args.action in ("sim", "all"):
  114. simulation()
  115. if args.action in ("pwm", "all"):
  116. pwm_acceptance()
  117. if args.action in ("cocotb", "all"):
  118. cocotb_integration()
  119. if args.action in ("bmc", "all"):
  120. bmc_fuzz()
  121. if args.action in ("pi", "all"):
  122. pi_differential()
  123. if args.action in ("unit", "all"):
  124. unit()
  125. return 0
  126. if __name__ == "__main__":
  127. try:
  128. sys.exit(main())
  129. except subprocess.CalledProcessError as exc:
  130. sys.exit(exc.returncode)