-
Notifications
You must be signed in to change notification settings - Fork 3k
tools: check that part size is not exceeding region size #9021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Addressing #9012 (comment) |
@naveenkaje, thank you for your changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
part.maxaddr
may be past the end of ROM, as introduced by #8097
OOps, got to give you a path forward. Support that use case please. |
@naveenkaje Has any progress been made on this PR? |
Will make changes and upload. |
2ac5a4a
to
2e74b8b
Compare
Ready for another review (it was updated) |
@naveenkaje Would it be possible to add some tests for |
@theotherjimmy Here are logs from a test in which target.restrict_size is set to overflow and with this change, such a condition is caught. Test Log:
|
@naveenkaje I meant some unit tests. That way we can have a quick sanity check and faster feedback in case anyone wants to refactor this code. |
2e74b8b
to
56b53e2
Compare
Test results
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new test cannot fail: it catches the only exception of the function under test and does not assert.
Please add an assert.
@patch('tools.build_api.Resources') | ||
@patch('tools.build_api.mkdir') | ||
@patch('os.path.exists') | ||
@patch('tools.build_api.prepare_toolchain') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this patch
""" | ||
Test that merge region fails as expected when part size overflows region size. | ||
""" | ||
with patch("tools.build_api.intelhex_offset") as _intelhex_offset: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this patch into the @patch
directorator section above the funnction?
region_list = [region_application, region_post_application] | ||
region_list = list(region_list) | ||
toolchain = prepare_toolchain(self.src_paths, self.build_path, self.target, | ||
self.toolchain_name, notify=notify) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need a toolchain object at all, so you can delete this line and the line above
mock_prepare_toolchain.config = MagicMock( | ||
has_regions=True, name=None, lib_config_data=None) | ||
region_list = [region_application, region_post_application] | ||
region_list = list(region_list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is not needed, as region_list is already a list.
@@ -238,5 +240,41 @@ def test_build_library_no_app_config(self, mock_prepare_toolchain, mock_exists, | |||
self.assertEqual(args[1]['app_config'], None, | |||
"prepare_toolchain was called with an incorrect app_config") | |||
|
|||
@patch('tools.build_api.Resources') | |||
@patch('tools.build_api.mkdir') | |||
@patch('os.path.exists') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.path.exsits is not used, so you don't need this patch either.
Come to think of it, you probably don't need to patch |
56b53e2
to
6c68f14
Compare
|
||
notify = MockNotifier() | ||
region_list = [region_application, region_post_application] | ||
toolchain = prepare_toolchain(self.src_paths, self.build_path, self.target, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toolchain needed to pass to merge_region_list()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge_region_list(region_list, res, notify, toolchain.config)
Nope. It needs a config object, or stand in. That's not a toolchain object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @theotherjimmy got it. Updated the patch.
6c68f14
to
a190ec8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improving, but we still don't assert any behavior of merge_region_list
. Please add an assert to the return value or in either the try
or the except
path, enforcing that only one of them is possible.
mock_intelhex_offset.return_value = IntelHex({0:2, max_addr:0}) | ||
|
||
self.assertEqual(0, mock_intelhex_offset.return_value.minaddr()) | ||
self.assertEqual(max_addr, mock_intelhex_offset.return_value.maxaddr()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These asserts don't test any tools code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we use the IntelHex() library to generate this object, we can forego these asserts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
a190ec8
to
bf70ab3
Compare
Without fix 060d3d3
With fix 060d3d3
|
1306bb1
to
3f39f99
Compare
If config is specified, check that part size is not exceeding the region. Normally we now assume that part.maxaddr() can be beyond end of rom.
3f39f99
to
7e169d5
Compare
7e169d5
to
43da2f2
Compare
CI started |
Test run: SUCCESSSummary: 12 of 12 test jobs passed |
@0xc0170 CI passed, does this need another review? |
@naveenkaje , please restore the template to the PR description and fill in. |
Description
Check that the Intel hex file segment fits within the region. Add a test to the tools test suite to verify the same.
Pull request type
Reviewers
@theotherjimmy