run_6400_v1.py 4.7 KB

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