run_6400_v1.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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-control/source-closure.json"
  13. TESTBENCHES = (
  14. "host_port_selector_tb",
  15. "bmc_ascii_snapshot_tb",
  16. "thermal_control_core_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_v1.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}; proc; check"
  55. )
  56. run(["yosys", "-q", "-p", script])
  57. def simulation() -> None:
  58. with tempfile.TemporaryDirectory(prefix="prod2u-6400-sim-") as directory:
  59. temp = Path(directory)
  60. for name in TESTBENCHES:
  61. output = temp / f"{name}.vvp"
  62. run([
  63. "iverilog", "-g2012", "-Wall", "-I.", "-s", name,
  64. "-o", str(output), *sources(), f"tests/sim/{name}.v",
  65. ])
  66. run(["vvp", str(output)])
  67. run([
  68. "iverilog", "-g2012", "-Wall", "-I.", "-s", top_module(),
  69. "-o", str(temp / "top.vvp"), *sources(),
  70. ])
  71. output = temp / "uart_baud_candidates_tb.vvp"
  72. run([
  73. "iverilog", "-g2012", "-Wall", "-I.", "-s", "uart_baud_candidates_tb",
  74. "-o", str(output), *UART_CANDIDATE_SOURCES, "tests/sim/uart_baud_candidates_tb.v",
  75. ])
  76. run(["vvp", str(output)])
  77. def pwm_acceptance() -> None:
  78. with tempfile.TemporaryDirectory(prefix="prod2u-6400-pwm-") as directory:
  79. output = Path(directory) / f"{PWM_TESTBENCH}.vvp"
  80. run([
  81. "iverilog", "-g2012", "-Wall", "-I.", "-s", PWM_TESTBENCH,
  82. "-o", str(output), *sources(), f"tests/sim/{PWM_TESTBENCH}.v",
  83. ])
  84. run(["vvp", str(output)])
  85. def unit() -> None:
  86. run([
  87. sys.executable, "-B", "-m", "pytest", "-p", "no:cacheprovider", "-q",
  88. "tests/unit/test_6400_v1_contract.py",
  89. "tests/unit/test_6400_v1_source_closure.py",
  90. "tests/unit/test_encode_6400_hex.py",
  91. "tests/unit/test_fw_6400_v1_entrypoint.py",
  92. ])
  93. def cocotb_integration() -> None:
  94. run([sys.executable, "-B", "tests/cocotb/run_6400_v1_integration.py"])
  95. def bmc_fuzz() -> None:
  96. run([sys.executable, "-B", "tests/cocotb/run_6400_bmc_fuzz.py"])
  97. def pi_differential() -> None:
  98. run([sys.executable, "-B", "tests/cocotb/run_6400_pi_differential.py"])
  99. def main(argv: list[str] | None = None) -> int:
  100. parser = argparse.ArgumentParser()
  101. parser.add_argument(
  102. "action",
  103. choices=("generate", "lint", "sim", "cocotb", "bmc", "pwm", "pi", "unit", "all"),
  104. )
  105. args = parser.parse_args(argv)
  106. if args.action in ("generate", "all"):
  107. generate()
  108. if args.action in ("lint", "all"):
  109. lint()
  110. if args.action in ("sim", "all"):
  111. simulation()
  112. if args.action in ("pwm", "all"):
  113. pwm_acceptance()
  114. if args.action in ("cocotb", "all"):
  115. cocotb_integration()
  116. if args.action in ("bmc", "all"):
  117. bmc_fuzz()
  118. if args.action in ("pi", "all"):
  119. pi_differential()
  120. if args.action in ("unit", "all"):
  121. unit()
  122. return 0
  123. if __name__ == "__main__":
  124. try:
  125. sys.exit(main())
  126. except subprocess.CalledProcessError as exc:
  127. sys.exit(exc.returncode)