|
| bool | _get_env_bool (str var_name, bool default) |
| |
| Optional[Path] | _get_env_path (str var_name) |
| |
| str | _get_pytest_run_id () |
| |
| Optional[str] | _get_xdist_worker_id () |
| |
| str | _get_test_dir_name (CosimPytestConfig config) |
| |
| | _chdir (Path path) |
| |
| bool | _line_matches (LogMatcher matcher, str line, str stream) |
| |
| tuple[list[str], list[str]] | _scan_logs (Sequence[str] stdout_lines, Sequence[str] stderr_lines, CosimPytestConfig config) |
| |
| list[str] | _render_args (Sequence[str] args, Path tmp_dir) |
| |
| Path | _generate_sources (CosimPytestConfig config, Path tmp_dir) |
| |
| Simulator | _create_simulator (CosimPytestConfig config, Path sources_dir, Path run_dir) |
| |
| Path | _run_hw_script (Union[str, Path] script_path, CosimPytestConfig config, Path tmp_dir) |
| |
| bool | _is_injected_param (str name, Any annotation) |
| |
| Dict[str, Any] | _resolve_injected_params (Callable[..., Any] target, Dict[str, Any] kwargs, str host, int port, Optional[Path] sources_dir=None) |
| |
| inspect.Signature | _visible_signature (Callable[..., Any] target) |
| |
| | _copy_compiled_artifacts (Optional[Path] compile_dir, Path run_dir) |
| |
| _ClassCompileCache | _compile_once_for_class (CosimPytestConfig config) |
| |
| | _run_child (multiprocessing.connection.Connection result_pipe, Callable[..., Any] target, CosimPytestConfig config, Sequence[Any] args, Dict[str, Any] kwargs, Optional[_ClassCompileCache] class_cache) |
| |
| | _run_isolated (Callable[..., Any] target, CosimPytestConfig config, Sequence[Any] args, Dict[str, Any] kwargs, Optional[_ClassCompileCache] class_cache=None) |
| |
| Callable[..., Any] | _decorate_function (Callable[..., Any] target, CosimPytestConfig config, Optional[Callable[[], _ClassCompileCache]] class_cache_getter=None) |
| |
| type | _decorate_class (type target_cls, CosimPytestConfig config) |
| |
| | cosim_test (SourceGeneratorArg source_generator, Sequence[str] args=("{tmp_dir}",), str simulator="verilator", str top="ESI_Cosim_Top", Optional[bool] debug=None, float timeout_s=_DEFAULT_TIMEOUT_S, Optional[LogMatcher] failure_matcher=_DEFAULT_FAILURE_PATTERN, Optional[LogMatcher] warning_matcher=_DEFAULT_WARN_PATTERN, Optional[Path] tmp_dir_root=None, Optional[bool] delete_tmp_dir=None, Optional[bool] save_waveform=None) |
| |
Pytest integration for ESI cosimulation tests.
Provides the ``@cosim_test`` decorator which automates the full lifecycle of a
cosimulation test: running a PyCDE hardware script, compiling the design with
a simulator (e.g. Verilator), launching the simulator, injecting connection
parameters into the test function, and tearing everything down afterwards.
Decorated functions run in an isolated child process (via ``fork``) so that
simulator state never leaks between tests. When applied to a class, the
hardware compilation is performed once and shared across all ``test_*`` methods.
Typical usage::
from esiaccel.cosim.pytest import cosim_test
@cosim_test("path/to/hw_script.py")
def test_my_design(conn: AcceleratorConnection):
# conn is already connected to the running simulator
...
| Dict[str, Any] pytest._resolve_injected_params |
( |
Callable[..., Any] |
target, |
|
|
Dict[str, Any] |
kwargs, |
|
|
str |
host, |
|
|
int |
port, |
|
|
Optional[Path] |
sources_dir = None |
|
) |
| |
|
protected |
Build the keyword arguments to inject into the test function.
Inspects the target's signature and automatically supplies ``host``,
``port``, ``sources_dir``, ``AcceleratorConnection``, or ``Accelerator``
parameters that the test declares but the caller did not provide.
Definition at line 330 of file pytest.py.
References esiaccel.connect().
Referenced by _run_child().
| pytest._run_child |
( |
multiprocessing.connection.Connection |
result_pipe, |
|
|
Callable[..., Any] |
target, |
|
|
CosimPytestConfig |
config, |
|
|
Sequence[Any] |
args, |
|
|
Dict[str, Any] |
kwargs, |
|
|
Optional[_ClassCompileCache] |
class_cache |
|
) |
| |
|
protected |
Entry point for the forked child process.
Compiles (or reuses cached compilation), starts the simulator, injects
connection parameters, calls the test function, scans logs for failures,
and sends a ``_ChildResult`` through *result_pipe*.
Definition at line 427 of file pytest.py.
References _copy_compiled_artifacts(), _create_simulator(), _generate_sources(), _get_test_dir_name(), _resolve_injected_params(), and _scan_logs().
| inspect.Signature pytest._visible_signature |
( |
Callable[..., Any] |
target | ) |
|
|
protected |
Return a signature with injected parameters removed.
Pytest uses function signatures to determine fixture requirements. This
hides the parameters that the decorator injects (``host``, ``port``,
``conn``, etc.) so pytest does not try to resolve them as fixtures.
Uses :func:`_is_injected_param` as the single source of truth.
Definition at line 364 of file pytest.py.
References _is_injected_param().
Referenced by _decorate_function().
| pytest.cosim_test |
( |
SourceGeneratorArg |
source_generator, |
|
|
Sequence[str] |
args = ("{tmp_dir}",), |
|
|
str |
simulator = "verilator", |
|
|
str |
top = "ESI_Cosim_Top", |
|
|
Optional[bool] |
debug = None, |
|
|
float |
timeout_s = _DEFAULT_TIMEOUT_S, |
|
|
Optional[LogMatcher] |
failure_matcher = _DEFAULT_FAILURE_PATTERN, |
|
|
Optional[LogMatcher] |
warning_matcher = _DEFAULT_WARN_PATTERN, |
|
|
Optional[Path] |
tmp_dir_root = None, |
|
|
Optional[bool] |
delete_tmp_dir = None, |
|
|
Optional[bool] |
save_waveform = None |
|
) |
| |
Decorator that turns a function or class into a cosimulation test.
The decorated target is executed in a forked child process with a freshly
compiled and running simulator. Connection parameters (``host``, ``port``,
``acc``, etc.) are injected automatically based on the function signature.
When applied to a class, the hardware script is run and compiled once;
each ``test_*`` method gets its own simulator process but skips
recompilation.
Args:
source_generator: Path to the PyCDE script that generates the hardware, or
a callable ``(config, tmp_dir) -> sources_dir`` that generates
sources directly.
args: Arguments forwarded to the script; ``{tmp_dir}`` is interpolated
with the temporary build directory.
simulator: Simulator backend (default ``"verilator"``).
top: Top-level module name.
debug: Enable verbose simulator output. Defaults to the value of the
``ESIACCEL_PYTEST_DEBUG`` environment variable if set, otherwise False.
timeout_s: Wall-clock timeout in seconds (default 120).
failure_matcher: Pattern to detect errors in simulator output.
warning_matcher: Pattern to detect warnings in simulator output.
tmp_dir_root: Root directory for temporary test files. Defaults to the value
of the ``ESIACCEL_PYTEST_TMP_DIR`` environment variable if set, otherwise
uses the system temporary directory. Run directories are organized in a
hierarchy to avoid collisions during parallel execution:
- Normal run: ``pytest-{pid}/ClassName/test_method/`` or
``pytest-{pid}/test_function/``
- xdist parallel: ``pytest-{pid}/gw0/ClassName/test_method/`` (gw0, gw1, etc.
for different workers)
delete_tmp_dir: Whether to delete temporary directories after test
completion. When tmp_dir_root is set (custom debugging directory),
directories are kept by default; set ``ESIACCEL_PYTEST_DELETE_TMP_DIR=true``
to delete them. When using the system temp directory, defaults to True
(delete to avoid clutter). Always False when debug mode is enabled.
save_waveform: Whether to save waveform dumps (format depends on the
simulator backend, e.g. FST for Verilator, VCD for Questa). Requires
debug mode to be enabled. Defaults to the value of the
``ESIACCEL_PYTEST_SAVE_WAVEFORM`` environment variable if set, otherwise
False.
Definition at line 649 of file pytest.py.
References _decorate_class(), _decorate_function(), _get_env_bool(), _get_env_path(), _get_pytest_run_id(), and _get_xdist_worker_id().