run_6400_v1.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. from pathlib import Path
  7. import subprocess
  8. import sys
  9. import tempfile
  10. ROOT = Path(__file__).resolve().parents[1]
  11. CLOSURE = ROOT / "products/6400-control/source-closure.json"
  12. TESTBENCHES = (
  13. "pwm_bitmap_engine_tb",
  14. "host_port_selector_tb",
  15. "bmc_ascii_snapshot_tb",
  16. "thermal_control_core_tb",
  17. )
  18. UART_CANDIDATE_SOURCES = (
  19. "src/common/uart_rx_byte.v",
  20. "src/common/uart_tx_byte.v",
  21. "src/common/uart_rx_byte_fractional.v",
  22. "src/common/uart_tx_byte_fractional.v",
  23. )
  24. def sources() -> list[str]:
  25. value = json.loads(CLOSURE.read_text(encoding="utf-8"))
  26. return [item for item in value["sources"] if item.endswith(".v")]
  27. def run(argv: list[str]) -> None:
  28. print("+ " + " ".join(argv), flush=True)
  29. subprocess.run(argv, cwd=ROOT, check=True)
  30. def generate(check: bool = True) -> None:
  31. argv = ["python3", "tools/generate_6400_v1.py"]
  32. if check:
  33. argv.append("--check")
  34. run(argv)
  35. def lint() -> None:
  36. run([
  37. "verilator", "--lint-only", "--Wall", "-Wno-fatal", "-Wno-MULTITOP",
  38. "-I.", "--top-module", "prod2u_6400_v1_top", *sources(),
  39. ])
  40. script = "read_verilog -I. " + " ".join(sources()) + "; hierarchy -check -top prod2u_6400_v1_top; proc; check"
  41. run(["yosys", "-q", "-p", script])
  42. def simulation() -> None:
  43. with tempfile.TemporaryDirectory(prefix="prod2u-6400-sim-") as directory:
  44. temp = Path(directory)
  45. for name in TESTBENCHES:
  46. output = temp / f"{name}.vvp"
  47. run([
  48. "iverilog", "-g2012", "-Wall", "-I.", "-s", name,
  49. "-o", str(output), *sources(), f"tests/sim/{name}.v",
  50. ])
  51. run(["vvp", str(output)])
  52. run([
  53. "iverilog", "-g2012", "-Wall", "-I.", "-s", "prod2u_6400_v1_top",
  54. "-o", str(temp / "top.vvp"), *sources(),
  55. ])
  56. output = temp / "uart_baud_candidates_tb.vvp"
  57. run([
  58. "iverilog", "-g2012", "-Wall", "-I.", "-s", "uart_baud_candidates_tb",
  59. "-o", str(output), *UART_CANDIDATE_SOURCES, "tests/sim/uart_baud_candidates_tb.v",
  60. ])
  61. run(["vvp", str(output)])
  62. def unit() -> None:
  63. run([
  64. "pytest", "-q",
  65. "tests/unit/test_6400_v1_contract.py",
  66. "tests/unit/test_6400_v1_source_closure.py",
  67. ])
  68. def main() -> int:
  69. parser = argparse.ArgumentParser()
  70. parser.add_argument("action", choices=("generate", "lint", "sim", "unit", "all"))
  71. args = parser.parse_args()
  72. if args.action in ("generate", "all"):
  73. generate()
  74. if args.action in ("lint", "all"):
  75. lint()
  76. if args.action in ("sim", "all"):
  77. simulation()
  78. if args.action in ("unit", "all"):
  79. unit()
  80. return 0
  81. if __name__ == "__main__":
  82. try:
  83. sys.exit(main())
  84. except subprocess.CalledProcessError as exc:
  85. sys.exit(exc.returncode)