Skip to content

Commit 43da2f2

Browse files
author
Naveen Kaje
committed
tools: build_api_test: add test to detect when part overflows region size
1 parent 4393e4b commit 43da2f2

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

tools/test/build_api/build_api_test.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
import unittest
1919
from collections import namedtuple
2020
from mock import patch, MagicMock
21-
from tools.build_api import prepare_toolchain, build_project, build_library
21+
from tools.build_api import prepare_toolchain, build_project, build_library, merge_region_list
2222
from tools.resources import Resources
2323
from tools.toolchains import TOOLCHAINS
2424
from tools.notifier.mock import MockNotifier
25-
25+
from tools.config import Region
26+
from tools.utils import ToolException
27+
from intelhex import IntelHex
28+
import intelhex
2629
"""
2730
Tests for build_api.py
2831
"""
@@ -240,5 +243,36 @@ def test_build_library_no_app_config(self, mock_prepare_toolchain, mock_exists,
240243
self.assertEqual(args[1]['app_config'], None,
241244
"prepare_toolchain was called with an incorrect app_config")
242245

246+
@patch('tools.build_api.intelhex_offset')
247+
@patch('tools.config')
248+
def test_merge_region_no_fit(self, mock_config, mock_intelhex_offset):
249+
"""
250+
Test that merge region fails as expected when part size overflows region size.
251+
"""
252+
max_addr = 87444
253+
# create a dummy hex file with above max_addr
254+
mock_intelhex_offset.return_value = IntelHex({0:2, max_addr:0})
255+
256+
# create application and post-application regions and merge.
257+
region_application = Region("application", 10000, 86000, True, "random.hex")
258+
region_post_application = Region("postapplication", 100000, 90000, False, None)
259+
260+
notify = MockNotifier()
261+
region_list = [region_application, region_post_application]
262+
# path to store the result in, should not get used as we expect exception.
263+
res = "./"
264+
mock_config.target.restrict_size = 90000
265+
toolexception = False
266+
267+
try:
268+
merge_region_list(region_list, res, notify, mock_config)
269+
except ToolException:
270+
toolexception = True
271+
except Exception as e:
272+
print("%s %s" % (e.message, e.args))
273+
274+
self.assertTrue(toolexception, "Expected ToolException not raised")
275+
276+
243277
if __name__ == '__main__':
244278
unittest.main()

0 commit comments

Comments
 (0)