| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- #!/usr/bin/env python3
- """Current-run software verification entrypoint for 6400-front-rear-v1."""
- from __future__ import annotations
- import argparse
- import json
- import os
- from pathlib import Path
- import subprocess
- import sys
- import tempfile
- ROOT = Path(__file__).resolve().parents[1]
- CLOSURE = ROOT / "products/6400-front-rear/source-closure.json"
- TESTBENCHES = (
- "host_port_selector_tb",
- "bmc_ascii_snapshot_tb",
- "thermal_control_core_tb",
- "thermal_host_command_v2_tb",
- )
- PWM_TESTBENCH = "pwm_bitmap_engine_tb"
- UART_CANDIDATE_SOURCES = (
- "src/common/uart_rx_byte.v",
- "src/common/uart_tx_byte.v",
- "src/common/uart_rx_byte_fractional.v",
- "src/common/uart_tx_byte_fractional.v",
- )
- def closure() -> dict[str, object]:
- return json.loads(CLOSURE.read_text(encoding="utf-8"))
- def sources() -> list[str]:
- value = closure()
- return [item for item in value["sources"] if item.endswith(".v")]
- def top_module() -> str:
- return str(closure()["top_module"])
- def run(argv: list[str]) -> None:
- print("+ " + " ".join(argv), flush=True)
- env = os.environ.copy()
- env.setdefault("PYTHONDONTWRITEBYTECODE", "1")
- env.setdefault(
- "PYTHONPYCACHEPREFIX",
- str(Path(tempfile.gettempdir()) / "prod2u-6400-v1-pycache"),
- )
- subprocess.run(argv, cwd=ROOT, check=True, env=env)
- def generate(check: bool = True) -> None:
- argv = [sys.executable, "-B", "tools/generate_6400_manual.py"]
- if check:
- argv.append("--check")
- run(argv)
- def lint() -> None:
- top = top_module()
- run([
- "verilator", "--lint-only", "--Wall", "-Wno-fatal", "-Wno-MULTITOP",
- "-I.", "--top-module", top, *sources(),
- ])
- script = (
- "read_verilog -I. " + " ".join(sources())
- + f"; hierarchy -check -top {top}; "
- "select -assert-none t:stimulus_atomic_bank; "
- "flatten; proc; opt_clean -purge; check"
- )
- run(["yosys", "-q", "-p", script])
- def simulation() -> None:
- with tempfile.TemporaryDirectory(prefix="prod2u-6400-sim-") as directory:
- temp = Path(directory)
- for name in TESTBENCHES:
- output = temp / f"{name}.vvp"
- run([
- "iverilog", "-g2012", "-Wall", "-I.", "-s", name,
- "-o", str(output), *sources(), f"tests/sim/{name}.v",
- ])
- run(["vvp", str(output)])
- run([
- "iverilog", "-g2012", "-Wall", "-I.", "-s", top_module(),
- "-o", str(temp / "top.vvp"), *sources(),
- ])
- output = temp / "uart_baud_candidates_tb.vvp"
- run([
- "iverilog", "-g2012", "-Wall", "-I.", "-s", "uart_baud_candidates_tb",
- "-o", str(output), *UART_CANDIDATE_SOURCES, "tests/sim/uart_baud_candidates_tb.v",
- ])
- run(["vvp", str(output)])
- def pwm_acceptance() -> None:
- with tempfile.TemporaryDirectory(prefix="prod2u-6400-pwm-") as directory:
- output = Path(directory) / f"{PWM_TESTBENCH}.vvp"
- run([
- "iverilog", "-g2012", "-Wall", "-I.", "-s", PWM_TESTBENCH,
- "-o", str(output), *sources(), f"tests/sim/{PWM_TESTBENCH}.v",
- ])
- run(["vvp", str(output)])
- def unit() -> None:
- run([
- sys.executable, "-B", "-m", "pytest", "-p", "no:cacheprovider", "-q",
- "tests/unit/test_6400_v1_contract.py",
- "tests/unit/test_6400_v1_source_closure.py",
- "tests/unit/test_encode_6400_hex.py",
- "tests/unit/test_fw_6400_v1_entrypoint.py",
- "tests/unit/test_6400_hex_gui_v2.py",
- ])
- def cocotb_integration() -> None:
- run([sys.executable, "-B", "tests/cocotb/run_6400_v1_integration.py"])
- def bmc_fuzz() -> None:
- run([sys.executable, "-B", "tests/cocotb/run_6400_bmc_fuzz.py"])
- def pi_differential() -> None:
- run([sys.executable, "-B", "tests/cocotb/run_6400_pi_differential.py"])
- def main(argv: list[str] | None = None) -> int:
- parser = argparse.ArgumentParser()
- parser.add_argument(
- "action",
- choices=("generate", "lint", "sim", "cocotb", "bmc", "pwm", "pi", "unit", "all"),
- )
- args = parser.parse_args(argv)
- if args.action in ("generate", "all"):
- generate()
- if args.action in ("lint", "all"):
- lint()
- if args.action in ("sim", "all"):
- simulation()
- if args.action in ("pwm", "all"):
- pwm_acceptance()
- if args.action in ("cocotb", "all"):
- cocotb_integration()
- if args.action in ("bmc", "all"):
- bmc_fuzz()
- if args.action in ("pi", "all"):
- pi_differential()
- if args.action in ("unit", "all"):
- unit()
- return 0
- if __name__ == "__main__":
- try:
- sys.exit(main())
- except subprocess.CalledProcessError as exc:
- sys.exit(exc.returncode)
|