run_6400_v1.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. "host_port_selector_tb",
  14. "bmc_ascii_snapshot_tb",
  15. "thermal_control_core_tb",
  16. )
  17. PWM_TESTBENCH = "pwm_bitmap_engine_tb"
  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 pwm_acceptance() -> None:
  63. with tempfile.TemporaryDirectory(prefix="prod2u-6400-pwm-") as directory:
  64. output = Path(directory) / f"{PWM_TESTBENCH}.vvp"
  65. run([
  66. "iverilog", "-g2012", "-Wall", "-I.", "-s", PWM_TESTBENCH,
  67. "-o", str(output), *sources(), f"tests/sim/{PWM_TESTBENCH}.v",
  68. ])
  69. run(["vvp", str(output)])
  70. def unit() -> None:
  71. run([
  72. "pytest", "-q",
  73. "tests/unit/test_6400_v1_contract.py",
  74. "tests/unit/test_6400_v1_source_closure.py",
  75. ])
  76. def cocotb_integration() -> None:
  77. run(["python3", "tests/cocotb/run_6400_v1_integration.py"])
  78. def bmc_fuzz() -> None:
  79. run(["python3", "tests/cocotb/run_6400_bmc_fuzz.py"])
  80. def pi_differential() -> None:
  81. run(["python3", "tests/cocotb/run_6400_pi_differential.py"])
  82. def main() -> int:
  83. parser = argparse.ArgumentParser()
  84. parser.add_argument(
  85. "action",
  86. choices=("generate", "lint", "sim", "cocotb", "bmc", "pwm", "pi", "unit", "all"),
  87. )
  88. args = parser.parse_args()
  89. if args.action in ("generate", "all"):
  90. generate()
  91. if args.action in ("lint", "all"):
  92. lint()
  93. if args.action in ("sim", "all"):
  94. simulation()
  95. if args.action in ("pwm", "all"):
  96. pwm_acceptance()
  97. if args.action in ("cocotb", "all"):
  98. cocotb_integration()
  99. if args.action in ("bmc", "all"):
  100. bmc_fuzz()
  101. if args.action in ("pi", "all"):
  102. pi_differential()
  103. if args.action in ("unit", "all"):
  104. unit()
  105. return 0
  106. if __name__ == "__main__":
  107. try:
  108. sys.exit(main())
  109. except subprocess.CalledProcessError as exc:
  110. sys.exit(exc.returncode)