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_channel_python(self, conn: AcceleratorConnection) -> None:
119 """Test ChannelService ToHost and FromHost ports from Python."""
120 acc = conn.build_accelerator()
121 channel_test = acc.children[esiaccel.AppID("channel_test")]
122 ports = channel_test.ports
123
124 # Get the MMIO port and trigger the producer to send 5 values.
125 mmio = ports[esiaccel.AppID("cmd")]
126 assert isinstance(mmio, types.MMIORegion), \
127 f"Expected MMIORegion, got {type(mmio)}"
128
129 producer = ports[esiaccel.AppID("producer")]
130 assert isinstance(producer, types.ToHostPort), \
131 f"Expected ToHostPort, got {type(producer)}"
132 producer.connect()
133
134 num_values = 5
135 mmio.write(0x0, num_values)
136 for i in range(num_values):
137 result = producer.read().result()
138 assert result == i, f"Producer: expected {i}, got {result}"
139
140 # Test from_host -> to_host loopback.
141 loopback_in = ports[esiaccel.AppID("loopback_in")]
142 assert isinstance(loopback_in, types.FromHostPort), \
143 f"Expected FromHostPort, got {type(loopback_in)}"
144 loopback_in.connect()
145
146 loopback_out = ports[esiaccel.AppID("loopback_out")]
147 assert isinstance(loopback_out, types.ToHostPort), \
148 f"Expected ToHostPort, got {type(loopback_out)}"
149 loopback_out.connect()
150
151 for i in range(5):
152 loopback_in.write(42 + i)
153 result = loopback_out.read().result()
154 assert result == 42 + i, \
155 f"Loopback: expected {42 + i}, got {result}"
156
157
158@cosim_test(HW_DIR / "esitester.py", args=("{tmp_dir}", "cosim_dma"))
160
161 def setup_method(self) -> None:
162 require_tool("esitester")
163 require_tool("esiquery")
164
165 def test_hostmem(self, host: str, port: int) -> None:
166 conn = f"{host}:{port}"
167 run_cmd(["esitester", "cosim", conn, "hostmem"])
168
169 def test_dma(self, host: str, port: int) -> None:
170 conn = f"{host}:{port}"
171 run_cmd(["esitester", "cosim", conn, "dma", "-w", "-r"])
172
173 def test_telemetry(self, host: str, port: int) -> None:
174 conn = f"{host}:{port}"
175 stdout = run_cmd(["esiquery", "cosim", conn, "telemetry"])
176 check_lines(stdout, [
177 "* Telemetry",
178 "fromhostdma[32].fromHostCycles: 0",
179 "tohostdma[32].toHostCycles: 0",
180 ])
181
182 def test_channel(self, host: str, port: int) -> None:
183 conn = f"{host}:{port}"
184 stdout = run_cmd(["esitester", "cosim", conn, "channel", "-i", "3"])
185 check_lines(stdout, [
186 "[channel] producer i=0 got=0",
187 "[channel] producer i=1 got=1",
188 "[channel] producer i=2 got=2",
189 "[channel] loopback i=0",
190 "[channel] loopback i=1",
191 "[channel] loopback i=2",
192 "Channel test passed",
193 ])
194
195 def test_serial_coords(self, host: str, port: int) -> None:
196 conn = f"{host}:{port}"
197 stdout = run_cmd(
198 ["esitester", "cosim", conn, "serial_coords", "-n", "40", "-b", "33"])
199 check_lines(stdout, [
200 "Serial coord translate test results:",
201 "coord[0]=",
202 "Serial coord translate test passed",
203 ])
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)