Found several bugs, too.
overlap_descrs.append("resource {!r} at {:#x}..{:#x}"
.format(overlap, resource_range.start, resource_range.stop))
if overlap in self._windows:
+ window_range = self._windows[overlap]
overlap_descrs.append("window {!r} at {:#x}..{:#x}"
- .format(overlap, resource_range.start, resource_range.stop))
+ .format(overlap, window_range.start, window_range.stop))
raise ValueError("Address range {:#x}..{:#x} overlaps with {}"
.format(addr, addr + size, ", ".join(overlap_descrs)))
for sub_resource, sub_descr in assignment.all_resources():
yield sub_resource, self._translate(*sub_descr, assignment, addr_range)
else:
- assert False
+ assert False # :nocov:
def find_resource(self, resource):
"""Find address range corresponding to a resource.
addr_range = self._windows[assignment]
return assignment.decode_address((address - addr_range.start) // addr_range.step)
else:
- assert False
+ assert False # :nocov:
(2, 3))
def test_add_wrong(self):
- with self.assertRaisesRegex(ValueError,
- r"Width must be a non-negative integer, not -1"):
- Element(-1, "rw")
+ with self.assertRaisesRegex(TypeError,
+ r"Element must be an instance of csr\.Element, not 'foo'"):
+ self.dut.add("foo")
def test_align_to(self):
self.assertEqual(self.dut.add(Element(8, "rw")),
self.dut = Decoder(addr_width=16, data_width=8)
Fragment.get(self.dut, platform=None) # silence UnusedElaboratable
+ def test_align_to(self):
+ self.assertEqual(self.dut.add(Interface(addr_width=10, data_width=8)),
+ (0, 0x400, 1))
+ self.assertEqual(self.dut.align_to(12), 0x1000)
+ self.assertEqual(self.dut.add(Interface(addr_width=10, data_width=8)),
+ (0x1000, 0x1400, 1))
+
def test_add_wrong_sub_bus(self):
with self.assertRaisesRegex(TypeError,
r"Subordinate bus must be an instance of csr\.Interface, not 1"):
r"16 is not an integer multiple of window data width 7"):
memory_map.add_window(MemoryMap(addr_width=10, data_width=7), sparse=False)
+ def test_add_window_wrong_overlap(self):
+ memory_map = MemoryMap(addr_width=16, data_width=8)
+ memory_map.add_window(MemoryMap(addr_width=10, data_width=8))
+ with self.assertRaisesRegex(ValueError,
+ r"Address range 0x200\.\.0x600 overlaps with window "
+ r"<nmigen_soc\.memory\.MemoryMap object at .+?> at 0x0\.\.0x400"):
+ memory_map.add_window(MemoryMap(addr_width=10, data_width=8), addr=0x200)
+
+ def test_add_window_wrong_twice(self):
+ memory_map = MemoryMap(addr_width=16, data_width=8)
+ window = MemoryMap(addr_width=10, data_width=8)
+ memory_map.add_window(window)
+ with self.assertRaisesRegex(ValueError,
+ r"Window <nmigen_soc\.memory\.MemoryMap object at .+?> is already added "
+ r"at address range 0x0\.\.0x400"):
+ memory_map.add_window(window)
+
def test_iter_windows(self):
memory_map = MemoryMap(addr_width=16, data_width=16)
window_1 = MemoryMap(addr_width=10, data_width=8)
self.assertEqual(memory_map.align_to(10), 0x400)
self.assertEqual(memory_map.add_resource("b", size=16), (0x400, 0x410))
+ def test_align_to_wrong(self):
+ memory_map = MemoryMap(addr_width=16, data_width=8)
+ with self.assertRaisesRegex(ValueError,
+ r"Alignment must be a non-negative integer, not -1"):
+ memory_map.align_to(-1)
+
class MemoryMapDiscoveryTestCase(unittest.TestCase):
def setUp(self):
r"Granularity must be one of 8, 16, 32, 64, not 7"):
Interface(addr_width=0, data_width=32, granularity=7)
- def test_wrong_granularity(self):
+ def test_wrong_granularity_wide(self):
with self.assertRaisesRegex(ValueError,
r"Granularity 32 may not be greater than data width 8"):
Interface(addr_width=0, data_width=8, granularity=32)