5from __future__
import annotations
8from pathlib
import Path
14_TRACE_SEP =
";" if os.name ==
"nt" else ":"
18from esiaccel.cosim.pytest
import cosim_test
20from .conftest
import (HW_DIR, SW_DIR, build_cpp_test, check_lines,
21 get_runtime_root, require_tool, run_probe)
24 (
"depth_constant", [
"depth: 0x5",
"depth_constant ok"]),
25 (
"loopback_i8", [
"loopback_i8 ok: 0x5a"]),
26 (
"struct_func", [
"struct_func ok: b=-7 x=-6 y=-7"]),
28 [
"odd_struct_func ok: a=2749 b=-20 p=10 q=-5 r0=4 r1=6"]),
29 (
"array_func", [
"array_func ok: -3 -2"]),
30 (
"serial_coord_translate", [
"serial_coord_translate ok"]),
33LOOPBACK_TYPED_PROBES = [
34 (
"depth_constant", [
"depth: 0x5",
"depth_constant ok"]),
35 (
"loopback_i8", [
"loopback_i8 ok: 0x5a"]),
36 (
"sint4_loopback", [
"sint4_loopback ok: pos=5 neg=-3"]),
37 (
"struct_func", [
"struct_func ok: b=-7 x=-6 y=-7"]),
39 [
"odd_struct_func ok: a=2749 b=-20 p=10 q=-5 r0=4 r1=6"]),
40 (
"array_func", [
"array_func ok: -3 -2"]),
41 (
"serial_coord_translate", [
"serial_coord_translate ok"]),
46 """Run live-connection codegen and build the loopback_test binary.
48 This test deliberately uses ``esiaccel.codegen --platform cosim`` (live
49 connection) rather than ``--file`` (offline manifest) to exercise that
55 runtime_root = get_runtime_root()
57 include_dir = tmp_path /
"include"
58 generated_dir = include_dir /
"loopback"
59 generated_dir.mkdir(parents=
True, exist_ok=
True)
77 header_path = generated_dir /
"LoopbackIP.h"
78 assert header_path.exists(),
"Generated header LoopbackIP.h not found"
79 header_content = header_path.read_text()
80 check_lines(header_content, [
81 "/// Generated header for esi_system module LoopbackIP.",
84 "namespace esi_system {",
86 "static constexpr uint32_t depth = 0x5;",
87 "} // namespace esi_system",
90 build_dir = tmp_path /
"loopback-build"
91 result = subprocess.run(
100 "-DCMAKE_BUILD_TYPE=Release",
101 f
"-DLOOPBACK_GENERATED_DIR={include_dir}",
102 f
"-DESI_RUNTIME_ROOT={runtime_root}",
107 assert result.returncode == 0, (
108 f
"cmake configure failed (rc={result.returncode}):\n"
109 f
"--- stdout ---\n{result.stdout}\n"
110 f
"--- stderr ---\n{result.stderr}")
112 result = subprocess.run(
115 str(build_dir),
"--target",
"loopback_test",
"--config",
"Release"
120 assert result.returncode == 0, (
121 f
"cmake build failed (rc={result.returncode}):\n"
122 f
"--- stdout ---\n{result.stdout}\n"
123 f
"--- stderr ---\n{result.stderr}")
125 return build_dir /
"loopback_test"
128@cosim_test(HW_DIR / "loopback.py")
130 """Tests for esiquery against the loopback design."""
134 """Build against live-connection codegen and run all probes."""
136 for probe, expected
in LOOPBACK_PROBES:
137 run_probe(binary, host, port, probe, expected)
140 sources_dir: Path) ->
None:
141 binary = build_cpp_test(sources_dir,
"loopback_typed_test",
"loopback")
142 for probe, expected
in LOOPBACK_TYPED_PROBES:
143 run_probe(binary, host, port, probe, expected)
146 """Verify esiquery info output against the generated manifest
147 (QUERY-INFO checks)."""
148 require_tool(
"esiquery")
149 manifest = sources_dir /
"esi_system_manifest.json"
150 assert manifest.exists(),
"Manifest not found"
151 result = subprocess.run(
152 [
"esiquery",
"trace", f
"w{_TRACE_SEP}{manifest}",
"info"],
157 check_lines(result.stdout, [
159 "* Module information",
161 "IP which simply echos bytes",
169 """Verify esiquery hier output against the generated manifest
170 (QUERY-HIER checks)."""
171 require_tool(
"esiquery")
172 manifest = sources_dir /
"esi_system_manifest.json"
173 assert manifest.exists(),
"Manifest not found"
174 result = subprocess.run(
175 [
"esiquery",
"trace", f
"w{_TRACE_SEP}{manifest}",
"hier"],
180 check_lines(result.stdout, [
181 "* Design hierarchy",
182 "func1: function uint16(uint16)",
183 "structFunc: function ResultStruct(ArgStruct)",
184 "arrayFunc: function ResultArray(sint8[1])",
185 "* Instance: loopback_inst[0]",
194 "* Instance: loopback_inst[1]",
None test_loopback_typed_cpp_codegen(self, str host, int port, Path sources_dir)
None test_loopback_cpp_codegen(self, Path tmp_path, str host, int port)
None test_loopback_query_hier(self, Path sources_dir)
None test_loopback_query_info(self, Path sources_dir)
Path _build_loopback_codegen(Path tmp_path, str host, int port)