Skip to content

Runners API

Public runners

fpga_verification.sim.runners

run_component_test(*, project_root, component_file, hdl_toplevel, test_module, config=None, parameter_presets=None, component_parameters=None, derived_parameters=None, sources=('../../src', '../../../common'), project_directory='../../..', python_paths=('..', '../../../common'), debug=None, argv=None, generate_only=False, retain_generated=False, clean_build=True, enable_questa_acc=False, artifacts_root=None, **kwargs)

Run a generated Altera component through the common RTL backend.

derived_parameters may be a mapping or a callable receiving the final resolved config. Use it for lower-level HDL parameters calculated from independent configuration fields; do not duplicate those values in the ComponentConfig dataclass.

Source code in src/fpga_verification/sim/runners/component.py
def run_component_test(
    *,
    project_root,
    component_file,
    hdl_toplevel,
    test_module,
    config=None,
    parameter_presets=None,
    component_parameters=None,
    derived_parameters=None,
    sources=("../../src", "../../../common"),
    project_directory="../../..",
    python_paths=("..", "../../../common"),
    debug=None,
    argv=None,
    generate_only=False,
    retain_generated=False,
    clean_build=True,
    enable_questa_acc=False,
    artifacts_root=None,
    **kwargs,
):
    """Run a generated Altera component through the common RTL backend.

    ``derived_parameters`` may be a mapping or a callable receiving the final
    resolved ``config``. Use it for lower-level HDL parameters calculated from
    independent configuration fields; do not duplicate those values in the
    ``ComponentConfig`` dataclass.
    """
    project_root = Path(project_root)
    run_args = _parse_run_args(argv)
    config = resolve_parameter_config(
        config,
        parameter_presets,
        run_args.param_preset,
    )
    if run_args.matrix:
        return _run_component_matrix(
            project_root=project_root,
            config=config,
            test_module=test_module,
            python_paths=python_paths,
            run_args=run_args,
            debug=debug,
            generate_only=generate_only,
            enable_questa_acc=enable_questa_acc,
        )

    config = resolve_matrix_config(config)
    artifacts_root = (
        matrix_artifact_root(project_root)
        if artifacts_root is None
        else Path(artifacts_root)
    )
    resolved_debug = run_args.debug if debug is None else debug
    debug, sim = prepare_test_run(
        project_root=project_root,
        artifacts_root=artifacts_root,
        python_paths=python_paths,
        debug=resolved_debug,
        argv=(),
        clean_build=clean_build,
        enable_questa_acc=enable_questa_acc,
    )

    component_parameters, extra_env = resolve_test_config(
        config,
        parameters=component_parameters,
        extra_env=kwargs.pop("extra_env", None),
    )
    coverage_enabled = run_args.coverage or functional_coverage_enabled()
    extra_env = functional_coverage_environment(
        coverage_enabled,
        extra_env,
        artifacts_root=artifacts_root,
        defer=(
            bool(run_args.test_patterns)
            or os.environ.get(FUNCTIONAL_COVERAGE_DEFER_ENV) == "1"
        ),
    )
    if component_parameters is None:
        component_parameters = {}
    if derived_parameters is not None:
        resolved_derived = (
            derived_parameters(config)
            if callable(derived_parameters)
            else derived_parameters
        )
        resolved_derived = dict(resolved_derived)
        overlap = set(component_parameters) & set(resolved_derived)
        if overlap:
            raise ValueError(
                "derived_parameters may not override independent HDL parameters: "
                + ", ".join(sorted(overlap))
            )
        component_parameters.update(resolved_derived)
    if extra_env is not None:
        kwargs["extra_env"] = extra_env

    log_dir = artifacts_root / "logs"

    return _component_test_cocotb(
        project_root=project_root,
        component_file=component_file,
        hdl_toplevel=hdl_toplevel,
        test_module=test_module,
        sources=sources,
        component_parameters=component_parameters,
        project_directory=project_directory,
        debug=debug,
        generate_only=generate_only,
        ip_generate_log=log_dir / "ip_generate.log",
        compile_log=log_dir / f"{sim}_compile.log",
        retain_generated=retain_generated,
        test_filter=_test_filter_from_patterns(run_args.test_patterns),
        artifacts_root=artifacts_root,
        **kwargs,
    )

run_rtl_test(*, project_root, hdl_toplevel, test_module, config=None, parameter_presets=None, parameters=None, extra_env=None, sources=('src',), intel_libraries=(), quartus_sim_lib=None, apply_simulation_fixes=True, python_paths=('.',), debug=None, argv=None, clean_build=True, enable_questa_acc=False, artifacts_root=None, **kwargs)

Run RTL with optional prepared Intel simulation libraries.

Source code in src/fpga_verification/sim/runners/rtl.py
def run_rtl_test(
    *,
    project_root,
    hdl_toplevel,
    test_module,
    config=None,
    parameter_presets=None,
    parameters=None,
    extra_env=None,
    sources=("src",),
    intel_libraries=(),
    quartus_sim_lib=None,
    apply_simulation_fixes=True,
    python_paths=(".",),
    debug=None,
    argv=None,
    clean_build=True,
    enable_questa_acc=False,
    artifacts_root=None,
    **kwargs,
):
    """Run RTL with optional prepared Intel simulation libraries."""
    project_root = Path(project_root)
    run_args = _parse_run_args(argv)
    config = resolve_parameter_config(
        config,
        parameter_presets,
        run_args.param_preset,
    )
    if run_args.matrix:
        return _run_rtl_matrix(
            project_root=project_root,
            config=config,
            test_module=test_module,
            python_paths=python_paths,
            run_args=run_args,
            debug=debug,
            enable_questa_acc=enable_questa_acc,
        )

    config = resolve_matrix_config(config)
    artifacts_root = (
        matrix_artifact_root(project_root)
        if artifacts_root is None
        else Path(artifacts_root)
    )
    resolved_debug = run_args.debug if debug is None else debug
    debug, sim = prepare_test_run(
        project_root=project_root,
        artifacts_root=artifacts_root,
        python_paths=python_paths,
        debug=resolved_debug,
        argv=(),
        clean_build=clean_build,
        enable_questa_acc=enable_questa_acc,
    )

    parameters, extra_env = resolve_test_config(
        config,
        parameters=parameters,
        extra_env=extra_env,
    )
    coverage_enabled = run_args.coverage or functional_coverage_enabled()
    extra_env = functional_coverage_environment(
        coverage_enabled,
        extra_env,
        artifacts_root=artifacts_root,
        defer=(
            bool(run_args.test_patterns)
            or os.environ.get(FUNCTIONAL_COVERAGE_DEFER_ENV) == "1"
        ),
    )

    return _rtl_test_cocotb(
        project_root=project_root,
        hdl_toplevel=hdl_toplevel,
        test_module=test_module,
        sources=sources,
        intel_libraries=intel_libraries,
        quartus_sim_lib=quartus_sim_lib,
        apply_simulation_fixes=apply_simulation_fixes,
        debug=debug,
        compile_log=artifacts_root / "logs" / f"{sim}_compile.log",
        parameters=parameters,
        extra_env=extra_env,
        test_filter=_test_filter_from_patterns(run_args.test_patterns),
        artifacts_root=artifacts_root,
        **kwargs,
    )

Quartus helpers

fpga_verification.altera.quartus

Helpers for Quartus component generation and simulation models.

prepare_intel_libraries(libraries, *, project_root, quartus_sim_lib, simulator, output_dir, apply_simulation_fixes=True)

Return requested Altera models in caller order, ready for compilation.

Source code in src/fpga_verification/altera/quartus/simulation.py
def prepare_intel_libraries(
    libraries,
    *,
    project_root,
    quartus_sim_lib,
    simulator,
    output_dir,
    apply_simulation_fixes=True,
):
    """Return requested Altera models in caller order, ready for compilation."""
    if libraries is None:
        return []
    if isinstance(libraries, str):
        raise TypeError("intel_libraries must be a sequence of library names")

    library_names = list(dict.fromkeys(libraries))
    if not library_names:
        return []

    unknown = [name for name in library_names if name not in _INTEL_LIBRARY_FILES]
    if unknown:
        supported = ", ".join(sorted(_INTEL_LIBRARY_FILES))
        raise ValueError(
            f"Unknown Altera simulation library {unknown[0]!r}; supported libraries: "
            f"{supported}"
        )

    sim_lib = resolve_quartus_sim_lib(project_root, quartus_sim_lib)
    sources = [sim_lib / _INTEL_LIBRARY_FILES[name] for name in library_names]
    missing = [source for source in sources if not source.is_file()]
    if missing:
        raise FileNotFoundError(f"Missing Quartus simulation model: {missing[0]}")

    return prepare_simulation_models(
        sources,
        simulator=simulator,
        output_dir=output_dir,
        enabled=apply_simulation_fixes,
    )

resolve_quartus_sim_lib(project_root, quartus_sim_lib=None)

Resolve an explicit, configured, or PATH-discovered Quartus model tree.

Source code in src/fpga_verification/altera/quartus/simulation.py
def resolve_quartus_sim_lib(project_root, quartus_sim_lib=None):
    """Resolve an explicit, configured, or PATH-discovered Quartus model tree."""
    if quartus_sim_lib is not None:
        return _validate_sim_lib(
            _resolve_path(project_root, quartus_sim_lib),
            source="quartus_sim_lib",
        )

    configured_sim_lib = os.getenv("QUARTUS_SIM_LIB")
    if configured_sim_lib:
        return _validate_sim_lib(configured_sim_lib, source="QUARTUS_SIM_LIB")

    quartus_root = os.getenv("QUARTUS_ROOTDIR")
    if quartus_root:
        return _validate_sim_lib(
            Path(quartus_root) / "eda" / "sim_lib",
            source="QUARTUS_ROOTDIR",
        )

    for executable_name in ("quartus_sh", "ip-generate"):
        executable = shutil.which(executable_name)
        if executable is not None:
            candidate = _sim_lib_from_installation(executable)
            if candidate is not None:
                return candidate

    raise FileNotFoundError(
        "Quartus simulation libraries were requested but eda/sim_lib could not "
        "be found; pass quartus_sim_lib, set QUARTUS_SIM_LIB or QUARTUS_ROOTDIR, "
        "or add Quartus tools to PATH"
    )