Skip to content

Commit e63b71d

Browse files
committed
Add tests for the full range of unsigned romblock and memblock values.
Also update pytest configuration to run tests in parallel.
1 parent 090f21e commit e63b71d

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ pylint
33
pyparsing
44
pytest
55
pytest-cov
6+
pytest-xdist
67
tox

tests/test_compilesim.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,20 @@ def test_negative_memory_value_map(self):
10091009
bitwidth=mem.bitwidth)
10101010
self.assertEqual(actual_read_data, memory_value_map[i])
10111011

1012+
def test_unsigned_memory_value_map(self):
1013+
mem = pyrtl.MemBlock(addrwidth=3, bitwidth=3)
1014+
counter = pyrtl.Register(bitwidth=mem.addrwidth)
1015+
counter.next <<= counter + 1
1016+
read_data = pyrtl.Output(name="read_data")
1017+
read_data <<= mem[counter]
1018+
memory_values = [0, 1, 2, 3, 4, 5, 6, 7]
1019+
memory_value_map = {index: value for index, value in enumerate(memory_values)}
1020+
sim = self.sim(memory_value_map={mem: memory_value_map})
1021+
for i in range(2 ** mem.addrwidth):
1022+
sim.step()
1023+
actual_read_data = sim.inspect("read_data")
1024+
self.assertEqual(actual_read_data, memory_value_map[i])
1025+
10121026

10131027
class InspectBase(unittest.TestCase):
10141028
"""

tests/test_memblock.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,19 @@ def test_negative_romdata(self):
399399
bitwidth=rom.bitwidth)
400400
self.assertEqual(actual_read_data, romdata[i])
401401

402+
def test_unsigned_romdata(self):
403+
romdata = [0, 1, 2, 3, 4, 5, 6, 7]
404+
rom = pyrtl.RomBlock(addrwidth=3, bitwidth=3, romdata=romdata)
405+
counter = pyrtl.Register(bitwidth=rom.addrwidth)
406+
counter.next <<= counter + 1
407+
read_data = pyrtl.Output(name="read_data", bitwidth=rom.bitwidth)
408+
read_data <<= rom[counter]
409+
sim = pyrtl.Simulation()
410+
for i in range(2 ** rom.addrwidth):
411+
sim.step()
412+
actual_read_data = sim.inspect("read_data")
413+
self.assertEqual(actual_read_data, romdata[i])
414+
402415

403416
if __name__ == "__main__":
404417
unittest.main()

tests/test_simulation.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,20 @@ def test_negative_memory_value_map(self):
13191319
bitwidth=mem.bitwidth)
13201320
self.assertEqual(actual_read_data, memory_value_map[i])
13211321

1322+
def test_unsigned_memory_value_map(self):
1323+
mem = pyrtl.MemBlock(addrwidth=3, bitwidth=3)
1324+
counter = pyrtl.Register(bitwidth=mem.addrwidth)
1325+
counter.next <<= counter + 1
1326+
read_data = mem[counter]
1327+
read_data.name = "read_data"
1328+
memory_values = [0, 1, 2, 3, 4, 5, 6, 7]
1329+
memory_value_map = {index: value for index, value in enumerate(memory_values)}
1330+
sim = self.sim(memory_value_map={mem: memory_value_map})
1331+
for i in range(2 ** mem.addrwidth):
1332+
sim.step()
1333+
actual_read_data = sim.inspect("read_data")
1334+
self.assertEqual(actual_read_data, memory_value_map[i])
1335+
13221336
def test_simultaneous_read_write(self):
13231337
"""Simultaneously read and write address 0.
13241338

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ setenv =
2121
PYTHONPATH = {toxinidir}
2222

2323
commands =
24-
test: pytest --cov=pyrtl --cov-report=xml
24+
test: pytest --cov=pyrtl --cov-report=xml -n auto {posargs}
2525
test: pylint -E pyrtl/
2626
pycodestyle: pycodestyle --max-line-length=100 --ignore=W503 pyrtl/
2727
pycodestyle: pycodestyle --max-line-length=100 --ignore=W503 examples/

0 commit comments

Comments
 (0)