5from __future__
import annotations
7from pathlib
import Path
14from esiaccel.cosim.pytest
import cosim_test
16from .conftest
import (HW_DIR, SW_DIR, build_cpp_test, check_lines,
17 get_runtime_root, require_tool, run_probe)
20 (
"depth_constant", [
"depth: 0x5",
"depth_constant ok"]),
21 (
"loopback_i8", [
"loopback_i8 ok: 0x5a"]),
22 (
"struct_func", [
"struct_func ok: b=-7 x=-6 y=-7"]),
24 [
"odd_struct_func ok: a=2749 b=-20 p=10 q=-5 r0=4 r1=6"]),
25 (
"array_func", [
"array_func ok: -3 -2"]),
26 (
"serial_coord_translate", [
"serial_coord_translate ok"]),
29LOOPBACK_TYPED_PROBES = [
30 (
"depth_constant", [
"depth: 0x5",
"depth_constant ok"]),
31 (
"loopback_i8", [
"loopback_i8 ok: 0x5a"]),
32 (
"sint4_loopback", [
"sint4_loopback ok: pos=5 neg=-3"]),
33 (
"struct_func", [
"struct_func ok: b=-7 x=-6 y=-7"]),
35 [
"odd_struct_func ok: a=2749 b=-20 p=10 q=-5 r0=4 r1=6"]),
36 (
"array_func", [
"array_func ok: -3 -2"]),
37 (
"serial_coord_translate", [
"serial_coord_translate ok"]),
42 """Run live-connection codegen and build the loopback_test binary.
44 This test deliberately uses ``esiaccel.codegen --platform cosim`` (live
45 connection) rather than ``--file`` (offline manifest) to exercise that
50 runtime_root = get_runtime_root()
52 include_dir = tmp_path /
"include"
53 generated_dir = include_dir /
"loopback"
54 generated_dir.mkdir(parents=
True, exist_ok=
True)
72 header_path = generated_dir /
"LoopbackIP.h"
73 assert header_path.exists(),
"Generated header LoopbackIP.h not found"
74 header_content = header_path.read_text()
75 check_lines(header_content, [
76 "/// Generated header for esi_system module LoopbackIP.",
79 "namespace esi_system {",
81 "static constexpr uint32_t depth = 0x5;",
82 "} // namespace esi_system",
85 build_dir = tmp_path /
"loopback-build"
86 result = subprocess.run(
93 f
"-DLOOPBACK_GENERATED_DIR={include_dir}",
94 f
"-DESI_RUNTIME_ROOT={runtime_root}",
99 assert result.returncode == 0, (
100 f
"cmake configure failed (rc={result.returncode}):\n"
101 f
"--- stdout ---\n{result.stdout}\n"
102 f
"--- stderr ---\n{result.stderr}")
104 result = subprocess.run(
106 str(build_dir),
"--target",
"loopback_test"],
110 assert result.returncode == 0, (
111 f
"cmake build failed (rc={result.returncode}):\n"
112 f
"--- stdout ---\n{result.stdout}\n"
113 f
"--- stderr ---\n{result.stderr}")
115 return build_dir /
"loopback_test"
118@cosim_test(HW_DIR / "loopback.py")
120 """Tests for esiquery against the loopback design."""
124 """Build against live-connection codegen and run all probes."""
126 for probe, expected
in LOOPBACK_PROBES:
127 run_probe(binary, host, port, probe, expected)
130 sources_dir: Path) ->
None:
131 binary = build_cpp_test(sources_dir,
"loopback_typed_test",
"loopback")
132 for probe, expected
in LOOPBACK_TYPED_PROBES:
133 run_probe(binary, host, port, probe, expected)
136 """Verify esiquery info output against the generated manifest
137 (QUERY-INFO checks)."""
138 require_tool(
"esiquery")
139 manifest = sources_dir /
"esi_system_manifest.json"
140 assert manifest.exists(),
"Manifest not found"
141 result = subprocess.run(
142 [
"esiquery",
"trace", f
"w:{manifest}",
"info"],
147 check_lines(result.stdout, [
149 "* Module information",
151 "IP which simply echos bytes",
159 """Verify esiquery hier output against the generated manifest
160 (QUERY-HIER checks)."""
161 require_tool(
"esiquery")
162 manifest = sources_dir /
"esi_system_manifest.json"
163 assert manifest.exists(),
"Manifest not found"
164 result = subprocess.run(
165 [
"esiquery",
"trace", f
"w:{manifest}",
"hier"],
170 check_lines(result.stdout, [
171 "* Design hierarchy",
172 "func1: function uint16(uint16)",
173 "structFunc: function ResultStruct(ArgStruct)",
174 "arrayFunc: function ResultArray(sint8[1])",
175 "* Instance: loopback_inst[0]",
184 "* 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)