2222from tools .resources import Resources
2323from tools .toolchains import TOOLCHAINS
2424from tools .notifier .mock import MockNotifier
25- from tools .config import Region
25+ from tools .config import Region , Config , ConfigException
2626from tools .utils import ToolException
2727from intelhex import IntelHex
28- import intelhex
28+
2929"""
3030Tests for build_api.py
3131"""
@@ -247,7 +247,10 @@ def test_build_library_no_app_config(self, mock_prepare_toolchain, mock_exists,
247247 @patch ('tools.config' )
248248 def test_merge_region_no_fit (self , mock_config , mock_intelhex_offset ):
249249 """
250- Test that merge region fails as expected when part size overflows region size.
250+ Test that merge_region_list call fails when part size overflows region size.
251+ :param mock_config: config object that is mocked.
252+ :param mock_intelhex_offset: mocked intel_hex_offset call.
253+ :return:
251254 """
252255 max_addr = 87444
253256 # create a dummy hex file with above max_addr
@@ -274,5 +277,90 @@ def test_merge_region_no_fit(self, mock_config, mock_intelhex_offset):
274277 self .assertTrue (toolexception , "Expected ToolException not raised" )
275278
276279
280+ @patch ('tools.config.exists' )
281+ @patch ('tools.config.isabs' )
282+ @patch ('tools.config.intelhex_offset' )
283+ def test_bl_pieces (self , mock_intelhex_offset , mock_exists , mock_isabs ):
284+ """
285+
286+ :param mock_intelhex_offset: mock intel_hex_ofset call
287+ :param mock_exists: mock the file exists call
288+ :param mock_isabs: mock the isabs call
289+ :return:
290+ """
291+ """
292+ Test that merge region fails as expected when part size overflows region size.
293+ """
294+ cfg = Config ('NRF52_DK' )
295+ mock_exists .return_value = True
296+ mock_isabs .return_value = True
297+ max = 0x960
298+ #create mock MBR and BL and merge them
299+ mbr = IntelHex ()
300+ for v in range (max ):
301+ mbr [v ] = v
302+
303+ bl = IntelHex ()
304+ min = 0x16000
305+ max = 0x22000
306+ for v in range (min , max ):
307+ bl [v ] = v
308+ mbr .merge (bl )
309+
310+ mock_intelhex_offset .return_value = mbr
311+
312+ # Place application within the bootloader and verify
313+ # that config exception is generated
314+ cfg .target .bootloader_img = True
315+ cfg .target .app_offset = min + 0x200
316+ cfg .target .restrict_size = '4096'
317+
318+ ce = False
319+ if cfg .has_regions :
320+ try :
321+ for r in list (cfg .regions ):
322+ print (r )
323+ except ConfigException :
324+ ce = True
325+
326+ self .assertTrue (ce )
327+
328+ @patch ('tools.config.exists' )
329+ @patch ('tools.config.isabs' )
330+ @patch ('tools.config.intelhex_offset' )
331+ def test_bl_too_large (self , mock_intelhex_offset , mock_exists , mock_isabs ):
332+ """
333+ Create a BL that's too large to fit in ROM and test that exception is
334+ generated.
335+ :param mock_intelhex_offset: mock intel hex
336+ :param mock_exists: mock the file exists call
337+ :param mock_isabs: mock the isabs call
338+ :return:
339+ """
340+ cfg = Config ('NRF52_DK' )
341+ mock_exists .return_value = True
342+ mock_isabs .return_value = True
343+
344+ # setup the hex file
345+ bl = IntelHex ()
346+ min = 0x0
347+ max = 0x88000
348+ for v in range (max ):
349+ bl [v ] = v
350+ mock_intelhex_offset .return_value = bl
351+ cfg .target .bootloader_img = True
352+ ce = False
353+
354+ if cfg .has_regions :
355+ try :
356+ for r in list (cfg .regions ):
357+ print (r )
358+ except ConfigException as e :
359+ print ("args %s" % (e .args ))
360+ if (e .args [0 ] == "bootloader segments don't fit within rom" ):
361+ ce = True
362+
363+ self .assertTrue (ce )
364+
277365if __name__ == '__main__' :
278366 unittest .main ()
0 commit comments