-
Notifications
You must be signed in to change notification settings - Fork 3k
Added interface version information to mbed detect command. #5077
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
Added interface version information to mbed detect command. #5077
Conversation
Additional tests performed on Ubuntu 17.04 from VirtualBox using USB Extensions:
|
tools/test_api.py
Outdated
@@ -1647,6 +1647,12 @@ def get_module_avail(module_name): | |||
""" | |||
return module_name in sys.modules.keys() | |||
|
|||
def get_mounted_details_txt(mount_point): |
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.
Why is this function in test_api.py
? I don't think it logically fits here.
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.
@theotherjimmy Happy to move it- my original thought process was to add it into test_api.get_autodetected_MUTS_list and return it as a mut object. After realising it would break the mut .json format, I decided to put it above. Any suggestions on where it may fit in better?
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 it's only used in detect_targets.py
let's put it there.
Fixed minor typos in test_api.py Added get_interface_version to detect_targets
@theotherjimmy I removed get_mounted_details_txt from test_api.py and added get_interface_version to detect_targets, also fixed some minor typos I noticed. |
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 for the typo fixes. The changes look good.
tools/detect_targets.py
Outdated
|
||
def get_interface_version(mount_point): | ||
""" Function returns interface version from the target mounted on the specified mount point | ||
mount_point = mut['port'] |
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.
What is this line of the function description supposed to tell me?
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.
Example usage. Though I just found one mistake- let me push an update there. An accurate usage should be mount_point = mut['disk']
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 looks great!
tools/detect_targets.py
Outdated
def get_interface_version(mount_point): | ||
""" Function returns interface version from the target mounted on the specified mount point | ||
Example of mount_point: | ||
mount_point = mut['disk'] |
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'm still not clear to me why I need an example of what to do with the parameter here. Are you suggesting that a user might be able to acquire a mount_point
with the example code? If so, could you state that?
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.
Pushed a new commit with a bit more clarity, apologies for the confusion ;)
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.
THAT IS SO CLEAR 👏
/morph test Let's get this in. |
Apologies @theotherjimmy but I had to push one more emergency commit. I found an edge case on a NRF52840_DK where there was no details.txt and thus details_txt was None. This was causing a boom, so I added in a safety check there. Thanks for the quick reviews |
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.
Given the aforementioned "explosion", I think it might be good to have a unit test for this new function.
tools/detect_targets.py
Outdated
details_txt = mbeds.get_details_txt(mount_point) | ||
|
||
if (details_txt is None): | ||
details_txt = {} |
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 just
return "unkown"
here?
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.
Makes sense for a unit test, I hadn't realised how many variations of details.txt there could be until now. I'll work on this in the coming few days.
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
I restarted jenkins CI @dhwalters423 Is this complete ? |
Hi @0xc0170 it's not quite ready as I discovered a breaking issue that will require a bit of tweaking and some test coverage. The issue is when a device does not have an interface version in the details.txt listed, which was causing the function to blow up when it tried to return None. I'm out of the office this week so I've been a bit slow to work on this but I will make another commit addressing these issues in the next coming days. |
@theotherjimmy Added in tests as requested, though I think wrapping the entire thing in a try/except covers all cases, therefore I think there is an argument that the unit tests are redundant. Either way, it's a nice double coverage there |
tools/test/detect_targets_test.py
Outdated
|
||
count += 1 | ||
self.valid_mount_point = mut['disk'] | ||
break |
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 looks very out of place. Count is only ever going to be 1 or 0.
tools/test/detect_targets_test.py
Outdated
# Function should handle failure gracefully regardless of a mount point being present. | ||
# Therefore it is safe to assume a valid mount point. | ||
if count is 0: | ||
self.valid_mount_point = "D:" |
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 is needed by the test_interface_version_valid_mount_point
function, so it should be assigned unconditionally.
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.
How could we handle the case where there was no mount point (no device connected to the host), and across cases where host OS differs.. IE a valid mount point on Win 10 could be D: but a valid mount point in Linux is something like /media/{username}/DAPLink? There would need to be some condition that has to make an assumption at a certain point.
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.
How could we handle the case where there was no mount point (no device connected to the host), and across cases where host OS differs.
Test 'em all?
There would need to be some condition that has to make an assumption at a certain point.
Yes, but that assumption can be guaranteed with mocking.
tools/test/detect_targets_test.py
Outdated
:return: | ||
""" | ||
# Gather a valid mount point from the host machine | ||
muts = get_autodetected_MUTS_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 should be mocked so that we don't depend on this test machine having some connected devices.
tools/test/detect_targets_test.py
Outdated
def test_interface_version_valid_mount_point(self): | ||
|
||
interface_version = get_interface_version(self.valid_mount_point) | ||
assert len(interface_version) > 0 |
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 is not a strong guarantee. I would like to see an assertion like the others in this commit: asserting that the interface version is a particular string/number.
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.
Please use mocks in your testing to avoid hardware/environment requirements during testing.
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 like the tests. It's very clear what mbed LS should provide and what the mbed OS tools do.
tools/test/detect_targets_test.py
Outdated
class MbedLsToolsMock(): | ||
|
||
def __init__(self, type): | ||
self.interface_test_type = type |
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 change the name of this parameter to not shadow a builtin?
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.
Done 👍
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.
💯
It's been a long road. Let's get to the destination. /morph test |
/morph test |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
Result: FAILUREYour command has finished executing! Here's what you wrote!
OutputBuild failed! |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
/morph test |
Result: ABORTEDYour command has finished executing! Here's what you wrote!
OutputTest failed! |
/morph test |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
Description
This adds the additional information of the interface version (IE DAPlink, OpenSDA, etc) to the command
mbed detect
This has proved useful when debugging applications, particularly when encountering interface issues. Not knowing about mbedls, I found it difficult to debug my application, where the USB driver and board was crashing when dragging the .bin to the disk for deployment in Windows 10. This information is a "nice to have" for a quick reference for mbed developers.
Example output:
Status
Built on mbed OS 5.5, will be tested against mbed OS 5.6 when an rc is ready.
Migrations
Added one method to test_api.py
def get_mounted_details_txt(mount_point)
to pull the details.txt for a specific target given it's mount point. This could prove useful later as additional information may want to be propagated to other tools using the test API.Related Issues
Submitted issue relating to this here:
ARMmbed/mbed-cli#541
The approach was changed slightly from the original issue request. This was because the
mut matrix PrettyTable
for the commandmbed detect
displayed specifically MUT information. In order to not change the format of the MUT JSON, I decided to create the additional functiondef get_mounted_details_txt(mount_point)
which created another mbed ls tools resource and display the information separately from the mut matrix.Steps to test or reproduce
Run the
mbed detect
command.Expected output should be similar to: