16from .conftest
import (HW_DIR, SW_DIR, check_lines, get_runtime_root,
23 sources_dir: Path) ->
None:
26 runtime_root = get_runtime_root()
28 include_dir = tmp_path /
"include"
29 generated_dir = include_dir /
"loopback"
30 generated_dir.mkdir(parents=
True, exist_ok=
True)
31 if mode ==
"from_manifest":
33 codegen_src = sources_dir /
"generated"
34 if codegen_src.exists():
35 for item
in codegen_src.iterdir():
37 shutil.copy(item, generated_dir)
56 header_path = generated_dir /
"LoopbackIP.h"
57 assert header_path.exists(),
"Generated header LoopbackIP.h not found"
58 header_content = header_path.read_text()
59 check_lines(header_content, [
60 "/// Generated header for esi_system module LoopbackIP.",
63 "namespace esi_system {",
65 "static constexpr uint32_t depth = 0x5;",
66 "} // namespace esi_system",
69 build_dir = tmp_path / f
"loopback-build-{mode}"
70 result = subprocess.run(
77 f
"-DLOOPBACK_GENERATED_DIR={include_dir}",
78 f
"-DESI_RUNTIME_ROOT={runtime_root}",
83 assert result.returncode == 0, (
84 f
"cmake configure failed (rc={result.returncode}):\n"
85 f
"--- stdout ---\n{result.stdout}\n"
86 f
"--- stderr ---\n{result.stderr}")
88 result = subprocess.run(
90 str(build_dir),
"--target",
"loopback_test"],
94 assert result.returncode == 0, (
95 f
"cmake build failed (rc={result.returncode}):\n"
96 f
"--- stdout ---\n{result.stdout}\n"
97 f
"--- stderr ---\n{result.stderr}")
101 "loopback i8 ok: 0x5a",
102 "struct func ok: b=-7 x=-6 y=-7",
103 "odd struct func ok: a=2749 b=-20 p=10 q=-5 r0=4 r1=6",
104 "array func ok: -3 -2",
107 LOOPBACK_TYPED_EXPECTED = LOOPBACK_EXPECTED[:1] + [
108 "loopback i8 ok: 0x5a",
109 "sint4 loopback ok: pos=5 neg=-3",
110 "struct func ok: b=-7 x=-6 y=-7",
111 "odd struct func ok: a=2749 b=-20 p=10 q=-5 r0=4 r1=6",
112 "array func ok: -3 -2",
116 result = subprocess.run(
117 [str(build_dir /
"loopback_test"),
"cosim", f
"{host}:{port}"],
122 check_lines(result.stdout, LOOPBACK_EXPECTED)
127 if mode ==
"from_manifest":
128 result = subprocess.run(
130 str(build_dir),
"--target",
"loopback_typed_test"],
134 assert result.returncode == 0, (
135 f
"cmake build (typed) failed (rc={result.returncode}):\n"
136 f
"--- stdout ---\n{result.stdout}\n"
137 f
"--- stderr ---\n{result.stderr}")
139 result = subprocess.run(
140 [str(build_dir /
"loopback_typed_test"),
"cosim", f
"{host}:{port}"],
145 check_lines(result.stdout, LOOPBACK_TYPED_EXPECTED)
148@cosim_test(HW_DIR / "loopback.py")