mirror of https://github.com/ARMmbed/mbed-os.git
tools: build_api_test: add test to detect when part overflows region size
parent
4393e4b82a
commit
43da2f22af
|
@ -18,11 +18,14 @@ limitations under the License.
|
||||||
import unittest
|
import unittest
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from mock import patch, MagicMock
|
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.resources import Resources
|
||||||
from tools.toolchains import TOOLCHAINS
|
from tools.toolchains import TOOLCHAINS
|
||||||
from tools.notifier.mock import MockNotifier
|
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
|
Tests for build_api.py
|
||||||
"""
|
"""
|
||||||
|
@ -240,5 +243,36 @@ class BuildApiTests(unittest.TestCase):
|
||||||
self.assertEqual(args[1]['app_config'], None,
|
self.assertEqual(args[1]['app_config'], None,
|
||||||
"prepare_toolchain was called with an incorrect app_config")
|
"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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue