CIRCT 24.0.0git
Loading...
Searching...
No Matches
test_bsp_common.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
5import pytest
6
7from esiaccel.bsp.common import ChannelMMIO
8
9
10class _Bundle:
11
12 def __init__(self, port, options=None):
13 self.port = port
14 self.options = options or {}
15 self.records = []
16
17 def add_record(self, details):
18 self.records.append(details)
19
20
22
23 def __init__(self, *bundles):
24 self.to_client_reqs = bundles
25
26
28 default = _Bundle("read")
29 custom = _Bundle("read_write", {"size": 0x1203})
30
31 table, manifest_loc = ChannelMMIO.build_table(_Bundles(default, custom))
32
33 assert list(table) == [0x100, 0x2000]
34 assert default.records == [{"offset": 0x100, "size": 0x100, "type": "ro"}]
35 assert custom.records == [{"offset": 0x2000, "size": 0x2000, "type": "rw"}]
36 # The manifest lands directly above the last client, rounded to a power of
37 # two so a single prefix test separates it from the client space.
38 assert manifest_loc == 0x4000
39
40
42 """The manifest window must not be a fixed reservation: it follows whatever
43 the clients actually use so the BAR stays as small as possible."""
44
45 small, = _Bundles(_Bundle("read", {"size": 8})).to_client_reqs
46 _, small_loc = ChannelMMIO.build_table(_Bundles(small))
47 assert small_loc == 0x200
48
49 big = _Bundle("read", {"size": 1 << 20})
50 _, big_loc = ChannelMMIO.build_table(_Bundles(big))
51 assert big_loc == 1 << 21
52
53
55 table, manifest_loc = ChannelMMIO.build_table(
56 _Bundles(_Bundle("read"), _Bundle("read", {"size": 0x1203})))
57 last_base = list(table)[-1]
58 last_size = table[last_base][0]
59
60 assert manifest_loc >= last_base + last_size
61 # A power-of-two base means 'address has a bit set above the clients' is the
62 # whole decode: no comparator, and the region can't overflow.
63 assert manifest_loc & (manifest_loc - 1) == 0
64
65
66@pytest.mark.parametrize("size", [True, 1.5, "256", 0, -8])
68 with pytest.raises(ValueError, match="option 'size'"):
69 ChannelMMIO.build_table(_Bundles(_Bundle("read", {"size": size})))
70
71
73 monkeypatch.setattr(ChannelMMIO, "initial_offset", 0xFFFF_FFF8)
74 with pytest.raises(ValueError, match="exceeds the 32-bit space"):
75 ChannelMMIO.build_table(_Bundles(_Bundle("read", {"size": 8})))
static StringAttr append(StringAttr base, const Twine &suffix)
Return a attribute with the specified suffix appended.
__init__(self, port, options=None)
test_channel_mmio_manifest_tracks_client_space()
test_channel_mmio_places_manifest_after_clients()
test_channel_mmio_rejects_address_overflow(monkeypatch)
test_channel_mmio_rejects_invalid_size(size)