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