CIRCT 23.0.0git
Loading...
Searching...
No Matches
test_codegen_cpp.py
Go to the documentation of this file.
1# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2# See https://llvm.org/LICENSE.txt for license information.
3# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4"""Pytest harness for the codegen + port-kind coverage tests.
5
6Where ``test_serialization_probes`` exercises wire-format invariants, this
7suite exercises the *port-kind* surface area of the ESI runtime + facade
8codegen end-to-end. It builds the C++ driver under ``sw/test_codegen.cpp``
9against generated ESI facade headers and runs each probe individually
10against a cosim-driven instance of ``hw/test_codegen.py``.
11
12Two test classes are generated — one for the default ``cosim`` BSP and one
13for ``cosim_dma`` — so every probe is exercised through both channel
14transport paths.
15"""
16
17from __future__ import annotations
18
19from pathlib import Path
20
21import pytest
22
23from esiaccel.cosim.pytest import cosim_test
24
25from .conftest import HW_DIR, build_cpp_test, run_probe
26
27PROBES = [
28 "typed_func_multi_arg",
29 "typed_func_void_arg",
30 "typed_func_void_result",
31 "call_service_callback",
32 "typed_read_channel_struct",
33 "typed_write_channel_byte",
34 "mmio_read_write",
35 "telemetry_metric",
36 "indexed_func_group",
37 "custom_service_decl_channel_0",
38 "custom_service_decl_channel_1",
39 "typed_func_struct",
40 "typed_func_nested_struct",
41 "typed_func_subbyte_signed",
42 "typed_func_array_result",
43 "typed_func_windowed_list",
44 "channel_windowed_list_read",
45 "channel_windowed_list_write",
46 "callback_windowed_list",
47]
48
49
50def _build(sources_dir: Path) -> Path:
51 return build_cpp_test(sources_dir, "test_codegen_test", "test_codegen")
52
53
54def _make_probe_test(probe: str):
55 """Create a test method that runs a single probe."""
56
57 def test_method(self, host: str, port: int, sources_dir: Path) -> None:
58 run_probe(_build(sources_dir), host, port, probe)
59
60 test_method.__name__ = f"test_{probe}"
61 test_method.__qualname__ = f"<dynamic>.test_{probe}"
62 return test_method
63
64
65def _make_codegen_class(name: str, bsp_args):
66 """Build a test class with one method per probe, decorated with cosim_test."""
67 ns = {f"test_{p}": _make_probe_test(p) for p in PROBES}
68 cls = type(name, (), ns)
69 return cosim_test(HW_DIR / "test_codegen.py", args=bsp_args)(cls)
70
71
72TestCodegen = _make_codegen_class("TestCodegen", ("{tmp_dir}",))
73TestCodegenDma = _make_codegen_class("TestCodegenDma",
74 ("{tmp_dir}", "cosim_dma"))