CIRCT 24.0.0git
Loading...
Searching...
No Matches
test_esitester.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
5from __future__ import annotations
6
7import json
8from pathlib import Path
9import subprocess
10
11import esiaccel
12from esiaccel.accelerator import AcceleratorConnection
13from esiaccel.cosim.pytest import cosim_test
14import esiaccel.types as types
15import pytest
16
17from .conftest import HW_DIR, check_lines, require_tool, run_cmd
18
19
20@cosim_test(HW_DIR / "esitester.py", args=("{tmp_dir}", "cosim"))
22
23 def setup_method(self) -> None:
24 require_tool("esitester")
25 require_tool("esiquery")
26
27 def test_callback(self, host: str, port: int) -> None:
28 conn = f"{host}:{port}"
29 stdout = run_cmd(["esitester", "-v", "cosim", conn, "callback", "-i", "5"])
30 check_lines(stdout, [
31 "[CONNECT] connecting to backend",
32 ])
33 # The callback loop should print values 0 through 4.
34 for i in range(5):
35 assert f"callback: {i}" in stdout, \
36 f"Expected 'callback: {i}' in stdout"
37
38 def test_streaming_add(self, host: str, port: int) -> None:
39 conn = f"{host}:{port}"
40 stdout = run_cmd(["esitester", "cosim", conn, "streaming_add"])
41 check_lines(stdout, [
42 "Streaming add test results:",
43 "input[0]=222709 + 5 = 222714 (expected 222714)",
44 "input[1]=894611 + 5 = 894616 (expected 894616)",
45 "input[2]=772894 + 5 = 772899 (expected 772899)",
46 "input[3]=429150 + 5 = 429155 (expected 429155)",
47 "input[4]=629806 + 5 = 629811 (expected 629811)",
48 "Streaming add test passed",
49 ])
50
51 def test_streaming_add_quiet(self, host: str, port: int) -> None:
52 conn = f"{host}:{port}"
53 stdout = run_cmd(["esitester", "cosim", conn, "streaming_add", "-t"])
54 check_lines(stdout, [
55 "Streaming add test results:",
56 "Streaming add test passed",
57 ])
58
59 def test_translate_coords(self, host: str, port: int) -> None:
60 conn = f"{host}:{port}"
61 stdout = run_cmd(["esitester", "cosim", conn, "translate_coords"])
62 check_lines(stdout, [
63 "Coord translate test results:",
64 "coord[0]=(222709,894611) + (10,20) = (222719,894631)",
65 "coord[1]=(772894,429150) + (10,20) = (772904,429170)",
66 "coord[2]=(629806,138727) + (10,20) = (629816,138747)",
67 "coord[3]=(218516,390276) + (10,20) = (218526,390296)",
68 "coord[4]=(750021,423525) + (10,20) = (750031,423545)",
69 "Coord translate test passed",
70 ])
71
72 def test_serial_coords(self, host: str, port: int) -> None:
73 conn = f"{host}:{port}"
74 stdout = run_cmd(
75 ["esitester", "cosim", conn, "serial_coords", "-n", "40", "-b", "33"])
76 check_lines(stdout, [
77 "Serial coord translate test results:",
78 "coord[0]=",
79 "Serial coord translate test passed",
80 ])
81
82 def test_auto_serial_coords(self, host: str, port: int) -> None:
83 conn = f"{host}:{port}"
84 stdout = run_cmd(
85 ["esitester", "cosim", conn, "auto_serial_coords", "-n", "5"])
86 check_lines(stdout, [
87 "Auto serial coord translate test results:",
88 "coord[0]=",
89 "Auto serial coord translate test passed",
90 ])
91
92 def test_channel(self, host: str, port: int) -> None:
93 conn = f"{host}:{port}"
94 stdout = run_cmd(["esitester", "cosim", conn, "channel", "-i", "3"])
95 check_lines(stdout, [
96 "[channel] producer i=0 got=0",
97 "[channel] producer i=1 got=1",
98 "[channel] producer i=2 got=2",
99 "[channel] loopback i=0",
100 "[channel] loopback i=1",
101 "[channel] loopback i=2",
102 "[channel] callback loopback passed (48 messages)",
103 "Channel test passed",
104 ])
105
106 def test_telemetry(self, host: str, port: int) -> None:
107 conn = f"{host}:{port}"
108 result = subprocess.run(
109 ["esiquery", "cosim", conn, "telemetry"],
110 check=False,
111 capture_output=True,
112 text=True,
113 )
114 assert result.returncode == 0, result.stdout + result.stderr
115 stdout = result.stdout
116 check_lines(stdout, [
117 "* Telemetry",
118 "fromhostdma[32].fromHostChecksum: 0",
119 "fromhostdma[32].fromHostCycles: 0",
120 "readmem[32].addrCmdIssued: 0",
121 "readmem[32].addrCmdResponses: 0",
122 "readmem[32].lastReadLSB: 0",
123 "readmem[32].readChecksum: 0",
124 "tohostdma[32].toHostCycles: 0",
125 "tohostdma[32].totalWrites: 0",
126 "writemem[32].addrCmdIssued: 0",
127 "writemem[32].addrCmdResponses: 0",
128 "readmem[32].addrCmdResp.cycles: 0",
129 "writemem[32].addrCmdResp.cycles: 0",
130 ])
131
132 def test_reset(self, host: str, port: int) -> None:
133 conn = f"{host}:{port}"
134 stdout = run_cmd(["esitester", "cosim", conn, "reset"])
135 check_lines(stdout, [
136 "[reset] reset requested",
137 "[reset] telemetry addrCmdResponses after reset = 0",
138 "Reset test passed",
139 ])
140
141 def test_channel_python(self, conn: AcceleratorConnection) -> None:
142 """Test ChannelService ToHost and FromHost ports from Python."""
143 acc = conn.build_accelerator()
144 channel_test = acc.children[esiaccel.AppID("channel_test")]
145 ports = channel_test.ports
146
147 # Get the MMIO port and trigger the producer to send 5 values.
148 mmio = ports[esiaccel.AppID("cmd")]
149 assert isinstance(mmio, types.MMIORegion), \
150 f"Expected MMIORegion, got {type(mmio)}"
151
152 producer = ports[esiaccel.AppID("producer")]
153 assert isinstance(producer, types.ToHostPort), \
154 f"Expected ToHostPort, got {type(producer)}"
155 producer.connect()
156
157 num_values = 5
158 mmio.write(0x0, num_values)
159 for i in range(num_values):
160 result = producer.read().result()
161 assert result == i, f"Producer: expected {i}, got {result}"
162
163 # Test from_host -> to_host loopback.
164 loopback_in = ports[esiaccel.AppID("loopback_in")]
165 assert isinstance(loopback_in, types.FromHostPort), \
166 f"Expected FromHostPort, got {type(loopback_in)}"
167 loopback_in.connect()
168
169 loopback_out = ports[esiaccel.AppID("loopback_out")]
170 assert isinstance(loopback_out, types.ToHostPort), \
171 f"Expected ToHostPort, got {type(loopback_out)}"
172 loopback_out.connect()
173
174 for i in range(5):
175 loopback_in.write(42 + i)
176 result = loopback_out.read().result()
177 assert result == 42 + i, \
178 f"Loopback: expected {42 + i}, got {result}"
179
180
181@cosim_test(HW_DIR / "esitester.py", args=("{tmp_dir}", "cosim_dma"))
183
184 def setup_method(self) -> None:
185 require_tool("esitester")
186 require_tool("esiquery")
187
188 def test_channel_engine_manifest(self, sources_dir: Path) -> None:
189 """CosimBSP_DMA's caller-supplied channel service must emit DMA engines."""
190 manifest = json.loads(
191 (sources_dir / "esi_system_manifest.json").read_text())
192 engine_names = {"OneItemBuffersToHost", "OneItemBuffersFromHost"}
193 engines = [
194 engine for engine in manifest["design"]["engines"]
195 if engine["serviceImplName"] in engine_names
196 ]
197 assert {engine["serviceImplName"] for engine in engines} == engine_names
198 assert all(engine["clientDetails"] for engine in engines)
199
200 def test_hostmem(self, host: str, port: int) -> None:
201 conn = f"{host}:{port}"
202 run_cmd(["esitester", "cosim", conn, "hostmem"])
203
204 def test_dma(self, host: str, port: int) -> None:
205 conn = f"{host}:{port}"
206 result = subprocess.run(
207 ["esitester", "cosim", conn, "dma", "-w", "-r"],
208 check=False,
209 capture_output=True,
210 text=True,
211 )
212 assert result.returncode == 0, result.stdout + result.stderr
213
214 def test_bandwidth_data_integrity(self, host: str, port: int) -> None:
215 """Verify complete engine payloads in both transfer directions."""
216 conn = f"{host}:{port}"
217 result = subprocess.run(
218 [
219 "esitester",
220 "cosim",
221 conn,
222 "bandwidth",
223 "-w",
224 "-r",
225 "--check-data",
226 "--widths",
227 "24",
228 "64",
229 "534",
230 "--count",
231 "24",
232 ],
233 check=False,
234 capture_output=True,
235 text=True,
236 )
237 assert result.returncode == 0, result.stdout + result.stderr
238
239 def test_hostmembw(self, host: str, port: int) -> None:
240 conn = f"{host}:{port}"
241 # Widths chosen to cover every element-vs-engine-word relationship the read
242 # gearbox must unpack from a contiguous, byte-packed layout: 24 (sub-word,
243 # does not divide the 64-bit engine word), 32 (sub-word divisor), 72
244 # (wider than the word, not a multiple -> straddles words), and 128 (a whole
245 # number of words). A 1000-element 24-bit read burst is 3000 bytes, which
246 # exceeds the PCIe maximum read request size and so exercises the
247 # read-request splitter. The -w/-r data-integrity checks verify each element
248 # landed at / was fetched from the right bytes.
249 result = subprocess.run(
250 [
251 "esitester",
252 "cosim",
253 conn,
254 "hostmembw",
255 "-w",
256 "-r",
257 "-c",
258 "1000",
259 ],
260 check=False,
261 capture_output=True,
262 text=True,
263 )
264 combined = result.stdout + result.stderr
265 assert result.returncode == 0, combined
266 assert "exceeds the PCIe maximum read request size" not in combined, \
267 combined
268
269 def test_aggbandwidth(self, host: str, port: int) -> None:
270 conn = f"{host}:{port}"
271 # Aggregate bandwidth across the width-512 readmem*/writemem* units
272 # (4 read + 4 write), exercising the multi-unit nested-AppID resolution
273 # (mmio[width]/cmd and addrCmdResp/cycles) of the burst modules.
274 result = subprocess.run(
275 [
276 "esitester", "cosim", conn, "aggbandwidth", "--width", "512", "-r",
277 "-w", "-c", "64"
278 ],
279 check=False,
280 capture_output=True,
281 text=True,
282 )
283 assert result.returncode == 0, result.stdout + result.stderr
284
285 def test_telemetry(self, host: str, port: int) -> None:
286 conn = f"{host}:{port}"
287 result = subprocess.run(
288 ["esiquery", "cosim", conn, "telemetry"],
289 check=False,
290 capture_output=True,
291 text=True,
292 )
293 assert result.returncode == 0, result.stdout + result.stderr
294 stdout = result.stdout
295 check_lines(stdout, [
296 "* Telemetry",
297 "fromhostdma[32].fromHostChecksum: 0",
298 "fromhostdma[32].fromHostCycles: 0",
299 "tohostdma[32].toHostCycles: 0",
300 ])
301
302 def test_channel(self, host: str, port: int) -> None:
303 conn = f"{host}:{port}"
304 stdout = run_cmd(["esitester", "cosim", conn, "channel", "-i", "3"])
305 check_lines(stdout, [
306 "[channel] producer i=0 got=0",
307 "[channel] producer i=1 got=1",
308 "[channel] producer i=2 got=2",
309 "[channel] loopback i=0",
310 "[channel] loopback i=1",
311 "[channel] loopback i=2",
312 "[channel] callback loopback passed (48 messages)",
313 "Channel test passed",
314 ])
315
316 def test_serial_coords(self, host: str, port: int) -> None:
317 conn = f"{host}:{port}"
318 stdout = run_cmd(
319 ["esitester", "cosim", conn, "serial_coords", "-n", "40", "-b", "33"])
320 check_lines(stdout, [
321 "Serial coord translate test results:",
322 "coord[0]=",
323 "Serial coord translate test passed",
324 ])
None test_bandwidth_data_integrity(self, str host, int port)
None test_channel_python(self, AcceleratorConnection conn)
None test_streaming_add_quiet(self, str host, int port)
None test_translate_coords(self, str host, int port)
None test_streaming_add(self, str host, int port)
None test_serial_coords(self, str host, int port)
None test_auto_serial_coords(self, str host, int port)