@@ -399,7 +399,7 @@ def test_add_window_sparse(self):
399399
400400 def test_add_window_dense (self ):
401401 memory_map = MemoryMap (addr_width = 16 , data_width = 32 )
402- self .assertEqual (memory_map .add_window (MemoryMap (addr_width = 10 , data_width = 8 ),
402+ self .assertEqual (memory_map .add_window (MemoryMap (addr_width = 10 , data_width = 8 , alignment = 2 ),
403403 sparse = False ),
404404 (0 , 0x100 , 4 ))
405405
@@ -430,13 +430,28 @@ def test_add_window_wrong_no_mode(self):
430430 r"a window with data width 8 to a memory map with data width 16" ):
431431 memory_map .add_window (MemoryMap (addr_width = 10 , data_width = 8 ))
432432
433- def test_add_window_wrong_ratio (self ):
433+ def test_add_window_wrong_ratio_multiple (self ):
434434 memory_map = MemoryMap (addr_width = 16 , data_width = 16 )
435435 with self .assertRaisesRegex (ValueError ,
436436 r"Dense addressing cannot be used because the memory map data width "
437437 r"16 is not an integer multiple of window data width 7" ):
438438 memory_map .add_window (MemoryMap (addr_width = 10 , data_width = 7 ), sparse = False )
439439
440+ def test_add_window_wrong_ratio_pow2 (self ):
441+ memory_map = MemoryMap (addr_width = 16 , data_width = 24 )
442+ with self .assertRaisesRegex (ValueError ,
443+ r"Dense addressing cannot be used because the ratio 3 of the memory map "
444+ r"data width 24 to the window data width 8 is not a power-of-2" ):
445+ memory_map .add_window (MemoryMap (addr_width = 10 , data_width = 8 ), sparse = False )
446+
447+ def test_add_window_wrong_ratio_alignment (self ):
448+ memory_map = MemoryMap (addr_width = 16 , data_width = 16 )
449+ with self .assertRaisesRegex (ValueError ,
450+ r"Dense addressing cannot be used because the ratio 2 of the memory map "
451+ r"data width 16 to the window data width 8 is greater than the window "
452+ r"alignment 1" ):
453+ memory_map .add_window (MemoryMap (addr_width = 10 , data_width = 8 ), sparse = False )
454+
440455 def test_add_window_wrong_out_of_bounds (self ):
441456 memory_map = MemoryMap (addr_width = 16 , data_width = 8 )
442457 with self .assertRaisesRegex (ValueError ,
@@ -489,9 +504,9 @@ def test_add_window_wrong_name_conflict_subordinate(self):
489504
490505 def test_iter_windows (self ):
491506 memory_map = MemoryMap (addr_width = 16 , data_width = 16 )
492- window_1 = MemoryMap (addr_width = 10 , data_width = 8 )
507+ window_1 = MemoryMap (addr_width = 10 , data_width = 8 , alignment = 1 )
493508 window_2 = MemoryMap (addr_width = 12 , data_width = 16 )
494- window_3 = MemoryMap (addr_width = 10 , data_width = 8 )
509+ window_3 = MemoryMap (addr_width = 10 , data_width = 8 , alignment = 1 )
495510 memory_map .add_window (window_1 , sparse = False )
496511 memory_map .add_window (window_2 )
497512 memory_map .add_window (window_3 , sparse = False , addr = 0x400 )
@@ -503,9 +518,9 @@ def test_iter_windows(self):
503518
504519 def test_iter_window_patterns (self ):
505520 memory_map = MemoryMap (addr_width = 16 , data_width = 16 )
506- window_1 = MemoryMap (addr_width = 10 , data_width = 8 )
521+ window_1 = MemoryMap (addr_width = 10 , data_width = 8 , alignment = 1 )
507522 window_2 = MemoryMap (addr_width = 12 , data_width = 16 )
508- window_3 = MemoryMap (addr_width = 10 , data_width = 8 )
523+ window_3 = MemoryMap (addr_width = 10 , data_width = 8 , alignment = 1 )
509524 memory_map .add_window (window_1 , sparse = False )
510525 memory_map .add_window (window_2 )
511526 memory_map .add_window (window_3 , sparse = False , addr = 0x400 )
@@ -555,9 +570,11 @@ def setUp(self):
555570 self .res5 = _MockResource ("res5" )
556571 self .win2 .add_resource (self .res5 , name = ("name5" ,), size = 16 )
557572 self .root .add_window (self .win2 , sparse = True )
558- self .win3 = MemoryMap (addr_width = 16 , data_width = 8 , name = "win3" )
573+ self .win3 = MemoryMap (addr_width = 16 , data_width = 8 , alignment = 2 , name = "win3" )
559574 self .res6 = _MockResource ("res6" )
575+ self .res7 = _MockResource ("res7" )
560576 self .win3 .add_resource (self .res6 , name = ("name6" ,), size = 16 )
577+ self .win3 .add_resource (self .res7 , name = ("name7" ,), size = 1 )
561578 self .root .add_window (self .win3 , sparse = False )
562579
563580 def test_iter_all_resources (self ):
@@ -599,6 +616,12 @@ def test_iter_all_resources(self):
599616 self .assertEqual (res_info [5 ].end , 0x00040004 )
600617 self .assertEqual (res_info [5 ].width , 32 )
601618
619+ self .assertIs (res_info [6 ].resource , self .res7 )
620+ self .assertEqual (res_info [6 ].path , ("win3" , ("name7" ,)))
621+ self .assertEqual (res_info [6 ].start , 0x00040004 )
622+ self .assertEqual (res_info [6 ].end , 0x00040005 )
623+ self .assertEqual (res_info [6 ].width , 32 )
624+
602625 def test_find_resource (self ):
603626 for res_info in self .root .all_resources ():
604627 other = self .root .find_resource (res_info .resource )
0 commit comments