CIRCT 23.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 esiaccel
8from esiaccel.accelerator import AcceleratorConnection
9from esiaccel.cosim.pytest import cosim_test
10import esiaccel.types as types
11import pytest
12
13from .conftest import HW_DIR, check_lines, require_tool, run_cmd
14
15
16@cosim_test(HW_DIR / "esitester.py", args=("{tmp_dir}", "cosim"))
18
19 def setup_method(self) -> None:
20 require_tool("esitester")
21 require_tool("esiquery")
22
23 def test_callback(self, host: str, port: int) -> None:
24 conn = f"{host}:{port}"
25 stdout = run_cmd(["esitester", "-v", "cosim", conn, "callback", "-i", "5"])
26 check_lines(stdout, [
27 "[CONNECT] connecting to backend",
28 ])
29 # The callback loop should print values 0 through 4.
30 for i in range(5):
31 assert f"callback: {i}" in stdout, \
32 f"Expected 'callback: {i}' in stdout"
33
34 def test_streaming_add(self, host: str, port: int) -> None:
35 conn = f"{host}:{port}"
36 stdout = run_cmd(["esitester", "cosim", conn, "streaming_add"])
37 check_lines(stdout, [
38 "Streaming add test results:",
39 "input[0]=222709 + 5 = 222714 (expected 222714)",
40 "input[1]=894611 + 5 = 894616 (expected 894616)",
41 "input[2]=772894 + 5 = 772899 (expected 772899)",
42 "input[3]=429150 + 5 = 429155 (expected 429155)",
43 "input[4]=629806 + 5 = 629811 (expected 629811)",
44 "Streaming add test passed",
45 ])
46
47 def test_streaming_add_quiet(self, host: str, port: int) -> None:
48 conn = f"{host}:{port}"
49 stdout = run_cmd(["esitester", "cosim", conn, "streaming_add", "-t"])
50 check_lines(stdout, [
51 "Streaming add test results:",
52 "Streaming add test passed",
53 ])
54
55 def test_translate_coords(self, host: str, port: int) -> None:
56 conn = f"{host}:{port}"
57 stdout = run_cmd(["esitester", "cosim", conn, "translate_coords"])
58 check_lines(stdout, [
59 "Coord translate test results:",
60 "coord[0]=(222709,894611) + (10,20) = (222719,894631)",
61 "coord[1]=(772894,429150) + (10,20) = (772904,429170)",
62 "coord[2]=(629806,138727) + (10,20) = (629816,138747)",
63 "coord[3]=(218516,390276) + (10,20) = (218526,390296)",
64 "coord[4]=(750021,423525) + (10,20) = (750031,423545)",
65 "Coord translate test passed",
66 ])
67
68 def test_serial_coords(self, host: str, port: int) -> None:
69 conn = f"{host}:{port}"
70 stdout = run_cmd(
71 ["esitester", "cosim", conn, "serial_coords", "-n", "40", "-b", "33"])
72 check_lines(stdout, [
73 "Serial coord translate test results:",
74 "coord[0]=",
75 "Serial coord translate test passed",
76 ])
77
78 def test_auto_serial_coords(self, host: str, port: int) -> None:
79 conn = f"{host}:{port}"
80 stdout = run_cmd(
81 ["esitester", "cosim", conn, "auto_serial_coords", "-n", "5"])
82 check_lines(stdout, [
83 "Auto serial coord translate test results:",
84 "coord[0]=",
85 "Auto serial coord translate test passed",
86 ])
87
88 def test_channel(self, host: str, port: int) -> None:
89 conn = f"{host}:{port}"
90 stdout = run_cmd(["esitester", "cosim", conn, "channel", "-i", "3"])
91 check_lines(stdout, [
92 "[channel] producer i=0 got=0",
93 "[channel] producer i=1 got=1",
94 "[channel] producer i=2 got=2",
95 "[channel] loopback i=0",
96 "[channel] loopback i=1",
97 "[channel] loopback i=2",
98 "Channel test passed",
99 ])
100
101 def test_telemetry(self, host: str, port: int) -> None:
102 conn = f"{host}:{port}"
103 stdout = run_cmd(["esiquery", "cosim", conn, "telemetry"])
104 check_lines(stdout, [
105 "* Telemetry",
106 "fromhostdma[32].fromHostCycles: 0",
107 "readmem[32].addrCmdCycles: 0",
108 "readmem[32].addrCmdIssued: 0",
109 "readmem[32].addrCmdResponses: 0",
110 "readmem[32].lastReadLSB: 0",
111 "tohostdma[32].toHostCycles: 0",
112 "tohostdma[32].totalWrites: 0",
113 "writemem[32].addrCmdCycles: 0",
114 "writemem[32].addrCmdIssued: 0",
115 "writemem[32].addrCmdResponses: 0",
116 ])
117
118 def test_reset(self, host: str, port: int) -> None:
119 conn = f"{host}:{port}"
120 stdout = run_cmd(["esitester", "cosim", conn, "reset"])
121 check_lines(stdout, [
122 "[reset] reset requested",
123 "[reset] telemetry addrCmdResponses after reset = 0",
124 "Reset test passed",
125 ])
126
127 def test_channel_python(self, conn: AcceleratorConnection) -> None:
128 """Test ChannelService ToHost and FromHost ports from Python."""
129 acc = conn.build_accelerator()
130 channel_test = acc.children[esiaccel.AppID("channel_test")]
131 ports = channel_test.ports
132
133 # Get the MMIO port and trigger the producer to send 5 values.
134 mmio = ports[esiaccel.AppID("cmd")]
135 assert isinstance(mmio, types.MMIORegion), \
136 f"Expected MMIORegion, got {type(mmio)}"
137
138 producer = ports[esiaccel.AppID("producer")]
139 assert isinstance(producer, types.ToHostPort), \
140 f"Expected ToHostPort, got {type(producer)}"
141 producer.connect()
142
143 num_values = 5
144 mmio.write(0x0, num_values)
145 for i in range(num_values):
146 result = producer.read().result()
147 assert result == i, f"Producer: expected {i}, got {result}"
148
149 # Test from_host -> to_host loopback.
150 loopback_in = ports[esiaccel.AppID("loopback_in")]
151 assert isinstance(loopback_in, types.FromHostPort), \
152 f"Expected FromHostPort, got {type(loopback_in)}"
153 loopback_in.connect()
154
155 loopback_out = ports[esiaccel.AppID("loopback_out")]
156 assert isinstance(loopback_out, types.ToHostPort), \
157 f"Expected ToHostPort, got {type(loopback_out)}"
158 loopback_out.connect()
159
160 for i in range(5):
161 loopback_in.write(42 + i)
162 result = loopback_out.read().result()
163 assert result == 42 + i, \
164 f"Loopback: expected {42 + i}, got {result}"
165
166
167@cosim_test(HW_DIR / "esitester.py", args=("{tmp_dir}", "cosim_dma"))
169
170 def setup_method(self) -> None:
171 require_tool("esitester")
172 require_tool("esiquery")
173
174 def test_hostmem(self, host: str, port: int) -> None:
175 conn = f"{host}:{port}"
176 run_cmd(["esitester", "cosim", conn, "hostmem"])
177
178 def test_dma(self, host: str, port: int) -> None:
179 conn = f"{host}:{port}"
180 run_cmd(["esitester", "cosim", conn, "dma", "-w", "-r"])
181
182 def test_telemetry(self, host: str, port: int) -> None:
183 conn = f"{host}:{port}"
184 stdout = run_cmd(["esiquery", "cosim", conn, "telemetry"])
185 check_lines(stdout, [
186 "* Telemetry",
187 "fromhostdma[32].fromHostCycles: 0",
188 "tohostdma[32].toHostCycles: 0",
189 ])
190
191 def test_channel(self, host: str, port: int) -> None:
192 conn = f"{host}:{port}"
193 stdout = run_cmd(["esitester", "cosim", conn, "channel", "-i", "3"])
194 check_lines(stdout, [
195 "[channel] producer i=0 got=0",
196 "[channel] producer i=1 got=1",
197 "[channel] producer i=2 got=2",
198 "[channel] loopback i=0",
199 "[channel] loopback i=1",
200 "[channel] loopback i=2",
201 "Channel test passed",
202 ])
203
204 def test_serial_coords(self, host: str, port: int) -> None:
205 conn = f"{host}:{port}"
206 stdout = run_cmd(
207 ["esitester", "cosim", conn, "serial_coords", "-n", "40", "-b", "33"])
208 check_lines(stdout, [
209 "Serial coord translate test results:",
210 "coord[0]=",
211 "Serial coord translate test passed",
212 ])
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)