Skip to content

Commit d9759ee

Browse files
authored
Merge pull request #273 from krcb197/267-make-a-generalised-memory-test_from_r3
Generalised memory test in the library Closes #267
2 parents 19d9320 + bfe6107 commit d9759ee

12 files changed

Lines changed: 679 additions & 217 deletions

src/peakrdl_python/lib/async_memory.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ async def _write(self, start_entry: int, data: Union[Array, list[int]]) -> None:
377377
if not isinstance(data, (list, Array)):
378378
raise TypeError(f'data should be an array.array got {type(data)}')
379379

380+
if (max(data) > self.max_entry_value) or (min(data) < 0):
381+
raise ValueError('Data out of range for memory must be in the '
382+
f'range 0 to {self.max_entry_value}')
383+
380384
if len(data) not in range(0, self.entries - start_entry + 1):
381385
raise ValueError(f'data length must be in range 0 to {self.entries - start_entry:d} '
382386
f'but got {len(data):d}')

src/peakrdl_python/lib/memory.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ def width(self) -> int:
9999
"""
100100
return self.__memwidth
101101

102+
@property
103+
def max_entry_value(self) -> int:
104+
"""
105+
maximum unsigned integer value that can be stored in a memory entry
106+
107+
For example:
108+
109+
* 8-bit memory width returns 0xFF (255)
110+
* 16-bit memory width returns 0xFFFF (65535)
111+
* 32-bit memory width returns 0xFFFF_FFFF (4294967295)
112+
113+
"""
114+
return (2 ** self.width) - 1
115+
102116
@property
103117
def width_in_bytes(self) -> int:
104118
"""
@@ -505,6 +519,10 @@ def _write(self, start_entry: int, data: Union[Array, list[int]]) -> None:
505519
if not isinstance(data, (Array, list)):
506520
raise TypeError(f'data should be an List or array.array got {type(data)}')
507521

522+
if (max(data) > self.max_entry_value) or (min(data) < 0):
523+
raise ValueError('Data out of range for memory must be in the '
524+
f'range 0 to {self.max_entry_value}')
525+
508526
if len(data) not in range(0, self.entries - start_entry + 1):
509527
raise ValueError(f'data length must be in range 0 to {self.entries - start_entry:d} '
510528
f'but got {len(data):d}')

src/peakrdl_python/lib/utility_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def get_array_typecode(width: int) -> str:
5959
return 'Q'
6060

6161
if width == 16:
62-
return 'I'
62+
return 'H'
6363

6464
if width == 8:
6565
return 'B'

src/peakrdl_python/lib_test/_common_base_test_class.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from ..lib import RegAsyncReadOnly, RegAsyncReadWrite, RegAsyncWriteOnly
3232
from ..lib import AddressMap, AsyncAddressMap
3333
from ..lib import RegFile, AsyncRegFile
34+
from ..lib.memory import BaseMemory
3435
from ..lib import MemoryReadOnly, MemoryReadOnlyLegacy
3536
from ..lib import MemoryWriteOnly, MemoryWriteOnlyLegacy
3637
from ..lib import MemoryReadWrite, MemoryReadWriteLegacy
@@ -95,6 +96,13 @@ def simulator_instance(self) -> BaseSimulator:
9596
Simulator configured for the DUT
9697
"""
9798

99+
@property
100+
@abstractmethod
101+
def legacy_block_access(self) -> bool:
102+
"""
103+
Whether the register model has been configured for legacy block access or not
104+
"""
105+
98106
# pylint:disable-next=too-many-arguments
99107
def _single_field_property_test(self, *,
100108
fut: Union[FieldReadWrite,
@@ -160,6 +168,26 @@ def _single_register_property_test(self, *,
160168
else:
161169
self.assertEqual(rut.accesswidth, width)
162170

171+
# pylint:disable-next=too-many-arguments
172+
def _single_memory_property_test(self, *,
173+
mut: BaseMemory,
174+
address: int,
175+
width: int,
176+
entries: int,
177+
accesswidth: Optional[int],
178+
array_typecode: Optional[str]) -> None:
179+
self.assertEqual(mut.address, address)
180+
self.assertEqual(mut.width, width)
181+
self.assertEqual(mut.entries, entries)
182+
if accesswidth is not None:
183+
self.assertEqual(mut.accesswidth, accesswidth)
184+
else:
185+
self.assertEqual(mut.accesswidth, width)
186+
if self.legacy_block_access:
187+
self.assertEqual(mut.array_typecode, array_typecode)
188+
else:
189+
self.assertIsNone(array_typecode)
190+
163191
def _single_node_rdl_name_and_desc_test(self,
164192
dut: Base,
165193
rdl_name: Optional[str],
@@ -190,11 +218,11 @@ def _test_node_inst_name(self,
190218

191219
def _test_field_iterators(self, *,
192220
rut: Union[RegReadOnly,
193-
RegReadWrite,
194-
RegWriteOnly,
195-
RegAsyncReadOnly,
196-
RegAsyncReadWrite,
197-
RegAsyncWriteOnly],
221+
RegReadWrite,
222+
RegWriteOnly,
223+
RegAsyncReadOnly,
224+
RegAsyncReadWrite,
225+
RegAsyncWriteOnly],
198226
has_sw_readable: bool,
199227
has_sw_writable: bool,
200228
readable_fields: set[str],

0 commit comments

Comments
 (0)