|
18 | 18 | import unittest
|
19 | 19 | from collections import namedtuple
|
20 | 20 | 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 |
22 | 22 | from tools.resources import Resources
|
23 | 23 | from tools.toolchains import TOOLCHAINS
|
24 | 24 | 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 |
26 | 29 | """
|
27 | 30 | Tests for build_api.py
|
28 | 31 | """
|
@@ -240,5 +243,36 @@ def test_build_library_no_app_config(self, mock_prepare_toolchain, mock_exists,
|
240 | 243 | self.assertEqual(args[1]['app_config'], None,
|
241 | 244 | "prepare_toolchain was called with an incorrect app_config")
|
242 | 245 |
|
| 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 | + |
243 | 277 | if __name__ == '__main__':
|
244 | 278 | unittest.main()
|
0 commit comments