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_channel(self, host: str, port: int) -> None:
79 conn = f"{host}:{port}"
80 stdout = run_cmd(["esitester", "cosim", conn, "channel", "-i", "3"])
81 check_lines(stdout, [
82 "[channel] producer i=0 got=0",
83 "[channel] producer i=1 got=1",
84 "[channel] producer i=2 got=2",
85 "[channel] loopback i=0",
86 "[channel] loopback i=1",
87 "[channel] loopback i=2",
88 "Channel test passed",
89 ])
90
91 def test_telemetry(self, host: str, port: int) -> None:
92 conn = f"{host}:{port}"
93 stdout = run_cmd(["esiquery", "cosim", conn, "telemetry"])
94 check_lines(stdout, [
95 "* Telemetry",
96 "fromhostdma[32].fromHostCycles: 0",
97 "readmem[32].addrCmdCycles: 0",
98 "readmem[32].addrCmdIssued: 0",
99 "readmem[32].addrCmdResponses: 0",
100 "readmem[32].lastReadLSB: 0",
101 "tohostdma[32].toHostCycles: 0",
102 "tohostdma[32].totalWrites: 0",
103 "writemem[32].addrCmdCycles: 0",
104 "writemem[32].addrCmdIssued: 0",
105 "writemem[32].addrCmdResponses: 0",
106 ])
107
108
109@cosim_test(HW_DIR / "esitester.py", args=("{tmp_dir}", "cosim_dma"))
111
112 def setup_method(self) -> None:
113 require_tool("esitester")
114 require_tool("esiquery")
115
116 def test_hostmem(self, host: str, port: int) -> None:
117 conn = f"{host}:{port}"
118 run_cmd(["esitester", "cosim", conn, "hostmem"])
119
120 def test_dma(self, host: str, port: int) -> None:
121 conn = f"{host}:{port}"
122 run_cmd(["esitester", "cosim", conn, "dma", "-w", "-r"])
123
124 def test_telemetry(self, host: str, port: int) -> None:
125 conn = f"{host}:{port}"
126 stdout = run_cmd(["esiquery", "cosim", conn, "telemetry"])
127 check_lines(stdout, [
128 "* Telemetry",
129 "fromhostdma[32].fromHostCycles: 0",
130 "tohostdma[32].toHostCycles: 0",
131 ])
132
133 def test_channel(self, host: str, port: int) -> None:
134 conn = f"{host}:{port}"
135 stdout = run_cmd(["esitester", "cosim", conn, "channel", "-i", "3"])
136 check_lines(stdout, [
137 "[channel] producer i=0 got=0",
138 "[channel] producer i=1 got=1",
139 "[channel] producer i=2 got=2",
140 "[channel] loopback i=0",
141 "[channel] loopback i=1",
142 "[channel] loopback i=2",
143 "Channel test passed",
144 ])
145
146 def test_serial_coords(self, host: str, port: int) -> None:
147 conn = f"{host}:{port}"
148 stdout = run_cmd(
149 ["esitester", "cosim", conn, "serial_coords", "-n", "40", "-b", "33"])
150 check_lines(stdout, [
151 "Serial coord translate test results:",
152 "coord[0]=",
153 "Serial coord translate test passed",
154 ])
155
156
157@cosim_test(HW_DIR / "esitester.py", args=("{tmp_dir}", "cosim"))
158def test_channel_python(conn: AcceleratorConnection) -> None:
159 """Test ChannelService ToHost and FromHost ports from Python."""
160 acc = conn.build_accelerator()
161 channel_test = acc.children[esiaccel.AppID("channel_test")]
162 ports = channel_test.ports
163
164 # Get the MMIO port and trigger the producer to send 5 values.
165 mmio = ports[esiaccel.AppID("cmd")]
166 assert isinstance(mmio, types.MMIORegion), \
167 f"Expected MMIORegion, got {type(mmio)}"
168
169 producer = ports[esiaccel.AppID("producer")]
170 assert isinstance(producer, types.ToHostPort), \
171 f"Expected ToHostPort, got {type(producer)}"
172 producer.connect()
173
174 num_values = 5
175 mmio.write(0x0, num_values)
176 for i in range(num_values):
177 result = producer.read().result()
178 assert result == i, f"Producer: expected {i}, got {result}"
179
180 # Test from_host -> to_host loopback.
181 loopback_in = ports[esiaccel.AppID("loopback_in")]
182 assert isinstance(loopback_in, types.FromHostPort), \
183 f"Expected FromHostPort, got {type(loopback_in)}"
184 loopback_in.connect()
185
186 loopback_out = ports[esiaccel.AppID("loopback_out")]
187 assert isinstance(loopback_out, types.ToHostPort), \
188 f"Expected ToHostPort, got {type(loopback_out)}"
189 loopback_out.connect()
190
191 for i in range(5):
192 loopback_in.write(42 + i)
193 result = loopback_out.read().result()
194 assert result == 42 + i, \
195 f"Loopback: expected {42 + i}, got {result}"
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_channel_python(AcceleratorConnection conn)