CIRCT 24.0.0git
Loading...
Searching...
No Matches
test_custom_channel_service.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 collections import Counter
6import json
7from pathlib import Path
8
9import esiaccel
10from esiaccel.accelerator import AcceleratorConnection
11from esiaccel.cosim.pytest import cosim_test
12
13from .conftest import HW_DIR
14
15
16@cosim_test(HW_DIR / "custom_channel_service.py")
17def test_custom_channel_service(conn: AcceleratorConnection,
18 sources_dir: Path) -> None:
19 """Route a custom service's multiple MMIO and HostMem clients via the BSP."""
20 manifest = json.loads((sources_dir / "esi_system_manifest.json").read_text())
21 engine_names = {"OneItemBuffersFromHost", "OneItemBuffersToHost"}
22 engines = [
23 engine for engine in manifest["design"]["engines"]
24 if engine["serviceImplName"] in engine_names
25 ]
26 assert Counter(engine["serviceImplName"] for engine in engines) == {
27 "OneItemBuffersFromHost": 2,
28 "OneItemBuffersToHost": 2,
29 }
30 expected_clients = {
31 f"loopback_{direction}_{i}" for direction in ("in", "out")
32 for i in range(2)
33 }
34 assert {
35 tuple(appid["name"]
36 for appid in client["relAppIDPath"])
37 for engine in engines
38 for client in engine["clientDetails"]
39 } == {(name,) for name in expected_clients}
40 assert {engine["mmio"]["name"] for engine in engines
41 } == {f"custom_{name}.mmio" for name in expected_clients}
42
43 acc = conn.build_accelerator()
44 inputs = [acc.ports[esiaccel.AppID(f"loopback_in_{i}")] for i in range(2)]
45 outputs = [acc.ports[esiaccel.AppID(f"loopback_out_{i}")] for i in range(2)]
46 for port in inputs + outputs:
47 port.connect()
48
49 # Distinct data in every 64-bit word detects routing and gearbox errors.
50 for iteration in range(8):
51 values = [
52 sum((1 + iteration + i * 16 + word * 256) << (64 * word)
53 for word in range(4))
54 for i in range(2)
55 ]
56 reads = [port.read() for port in outputs]
57 for port, value in zip(inputs, values):
58 port.write(value)
59 assert [read.result(timeout=10) for read in reads] == values