tools: build_api_test: add test to detect when part overflows region size

pull/9021/head
Naveen Kaje 2019-01-29 09:11:09 -06:00
parent 4393e4b82a
commit 43da2f22af
1 changed files with 36 additions and 2 deletions

View File

@ -18,11 +18,14 @@ limitations under the License.
import unittest
from collections import namedtuple
from mock import patch, MagicMock
from tools.build_api import prepare_toolchain, build_project, build_library
from tools.build_api import prepare_toolchain, build_project, build_library, merge_region_list
from tools.resources import Resources
from tools.toolchains import TOOLCHAINS
from tools.notifier.mock import MockNotifier
from tools.config import Region
from tools.utils import ToolException
from intelhex import IntelHex
import intelhex
"""
Tests for build_api.py
"""
@ -240,5 +243,36 @@ class BuildApiTests(unittest.TestCase):
self.assertEqual(args[1]['app_config'], None,
"prepare_toolchain was called with an incorrect app_config")
@patch('tools.build_api.intelhex_offset')
@patch('tools.config')
def test_merge_region_no_fit(self, mock_config, mock_intelhex_offset):
"""
Test that merge region fails as expected when part size overflows region size.
"""
max_addr = 87444
# create a dummy hex file with above max_addr
mock_intelhex_offset.return_value = IntelHex({0:2, max_addr:0})
# create application and post-application regions and merge.
region_application = Region("application", 10000, 86000, True, "random.hex")
region_post_application = Region("postapplication", 100000, 90000, False, None)
notify = MockNotifier()
region_list = [region_application, region_post_application]
# path to store the result in, should not get used as we expect exception.
res = "./"
mock_config.target.restrict_size = 90000
toolexception = False
try:
merge_region_list(region_list, res, notify, mock_config)
except ToolException:
toolexception = True
except Exception as e:
print("%s %s" % (e.message, e.args))
self.assertTrue(toolexception, "Expected ToolException not raised")
if __name__ == '__main__':
unittest.main()