-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add bare metal test for UART. #5273
Conversation
@maciejbocianski @fkjagodzinski - Ready for review. |
@@ -0,0 +1,3 @@ | |||
/* This file has been automatically generated by the python script. */ | |||
/* This file contains serial port baud rate. */ | |||
#define BAUD_RATE 19200 |
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.
We could use config for this? to create Config object, add this attribute there and generate config file that would be ignored by git?
In case, this is the best approach, this file possibly should be created by a test and being ignored in git? Thus not part of this patch?
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 file is already generated by the script based on provided script parameter.
I will remove this file from commit.
* function returns FAILED status. | ||
* | ||
* */ | ||
test_status test_uart_communication(RawSerial &serial, const char * msg) |
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.
doxygen comments, in separate header file?
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 not sure if we need this for this test. This test must be executed manually and does not use grean tea. The hart of this test is the python script and it provides detailed description.
retest uvisor |
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.
Python script lacks portability -- I suppose this is not OK.
call host test with appropriate --baudrate parameter. | ||
|
||
Example usage: | ||
uart_test.py -m K64F -m K64F -t GCC_ARM -b 9600 |
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.
Typo: -m K64F -m K64F.
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.
Fixed.
VERBOSE = False | ||
RETRY_LIMIT = 10 | ||
|
||
# Listo of expected messages from the mbed device. |
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.
Typo: Listo.
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.
Fixed.
'PASSED\0'] | ||
|
||
def log_info(msg): | ||
print('[INFO]: %s') % msg |
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 suggest using Python's logging
module for logging.
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 tip, but for now I decided to stay with my log functions. After the update they are only simple wrappers to print function. This gives additional flexibility. I can have log functions to indicate failure, pass and received/transmitted data.
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.
And how is this an advantage over the logging module?
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 solution gives me everything what is needed to print out logs and allows to format log messages. Of course there is no problem to use logging module instead.
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'd recommend moving to logging as well. I know the tools don't currently support Python 3, but in the future we'll have to (Python 2 is only minimally being maintained). logging has Python 3 support out of the box, where as this current implementation does not.
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.
Modified logging method as suggested.
print('[FAIL]: %s') % msg | ||
if(serial_port != None and serial_port.isOpen() == True): | ||
serial_port.close() | ||
sys.exit() |
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 way too big side effect for a log function.
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.
Removed additional actions performed by the log function.
log_fail('Command can not be executed.') | ||
sys.exit() | ||
|
||
output = str() |
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.
Unused variable output
.
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.
Fixed.
# When dumping output to file both \r and \n will be a new line | ||
# To avoid this "extra new-line" we only use \n at the end | ||
sys.stdout.write(line.rstrip() + '\n') | ||
sys.stdout.flush() |
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.
Use Popen(cmd, stdout=sys.stdout)
instead.
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.
Fixed as suggested.
if('ERROR' in line): | ||
build_success = False | ||
if('Image:' in line): | ||
image_path = line[7:] |
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.
More stable API sould be used instead of parsing stdout
. Use mbed test --compile --build-data foo
and then parse foo
JSON file:
build_data = {}
with open('foo') as f:
build_data = json.load(f)
try:
image_path = build_data['builds'][0]['bin']
except KeyError:
image_path = '' # or raise an exception
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.
Fixed as suggested.
# for like COMnotanumber | ||
pass | ||
|
||
hComPort = win32.CreateFile(port, win32.GENERIC_READ | win32.GENERIC_WRITE, 0, None, win32.OPEN_EXISTING, win32.FILE_ATTRIBUTE_NORMAL | win32.FILE_FLAG_OVERLAPPED, 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.
The assumption of using a Windows machine should be documented.
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.
Note has been added to the script description.
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 should just not assume that you're on a windows machine! We have linux machines in CI.
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 agree, but currently I don't have linux machine.
Build : FAILUREBuild number : 58 |
@mprse jenkins CI fails, related to this patch, please check |
I'm not sure if there is a sens to check this tests on build machines. It needs to be executed manually.
test_config.h is a config file generated by python script (has been removed from this patch). |
Modified function to reset the mbed board. Current implementation should be valid for Windows and Linux (not tested). |
Build : FAILUREBuild number : 150 |
I see, than this test should not be automatically run, as it has this python dependency. is it required or how to make it CI friendly? |
Honestly I'm not familiar with CI, maybe we should put it in some place where CI is not performed. This test is for vendors to be able to verify if their serial HAL drivers are ready to use Grean Tea. To do this python script should be run with some parameters. This script builds the embed app, loads it on the board and run it. This embed app uses only RawSerial class and tries to communicate with PC (python script) by sending sample strings with different length and waiting for the responses. If all strings are successfully transmitted in both sides, then test is passed. |
cc @studavekar @theotherjimmy - how to handle this type of test? |
We can add in check, if and only if there is a label "needs: CI" then we start CI. |
@studavekar @bridadan How we can handle this one, via ignore or any other suggestions? |
'PASSED\0'] | ||
|
||
def log_info(msg): | ||
print('[INFO]: %s') % msg |
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'd recommend moving to logging as well. I know the tools don't currently support Python 3, but in the future we'll have to (Python 2 is only minimally being maintained). logging has Python 3 support out of the box, where as this current implementation does not.
required = parser.add_argument_group('required arguments') | ||
optional = parser.add_argument_group('optional arguments') | ||
required.add_argument("-m", "--target", help="Target id") | ||
optional.add_argument("-t", "--toolchanin", help="Compile toolchain. Example: ARM, GCC_ARM, IAR.", default='GCC_ARM') |
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.
Typo here, should be --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.
Fixed.
One option would be to create a new folder in mbed OS for these kinds of tests. This one would be included in a To actually build the test, you could force tools to ignore the
Where test.py would call mbed-cli as:
|
@bridadan I tried to use "mbed test --source" in current tree folder where test is located in: I have executed the following command: Currently in python script I use mbed --compile to build test and I have my functions for flashing and resetting the board. As far as I understand these function will be redundant. Command @0xc0170 |
@0xc0170 @bridadan @studavekar Could you review? |
Darn it, you're right. I forgot that that's how that particular script works. I did some more digging and learned that I goofed when I originally wrote the file. It doesn't actually use the SO I patched it: bridadan@f8ed507 You'll also need to update your directory structure:
And then the CLI command would look like:
I have to say, I'm not really seeing that many advantages this has over just using Greentea/htrun. It basically invokes the build tools, copies the binaries, resets the target, and compare strings in the Python script. Which basically describes Greentea in a nutshell. It looks like you're citing a engineering requirement @mprse, can you tell us where this is from? |
@bridadan Thank you for clarifications. The cited requirement can be found here: I have updated directory tree and with your patch to test.py I was able to run the mbed part of the test with: |
Directory structure has been proposed by @bridadan and I thought that this is the final location. Maybe the valid location would be |
I agree with @0xc0170 I think a suite of tests that are geared purely for the porting guide would benefit from being in their own repo. Mbed-os clone is big enough already without cluttering with additional tests that are not directly related to the codebase. These tests are no more related to mbed-os itself than say an mbed-os-example is. |
From what I rememember @bridadan and @theotherjimmy suggested to put it in TEST directory and add mbedignore so that it's ignored by mbed test command. |
@0xc0170 @bulislaw @acabarbaye
Do we have some decision about the test location? |
@bridadan @theotherjimmy is there anything stoping us from having it in |
Pretty sure that should be fine! |
@bulislaw That should be fine. |
Why doesn't the test case use unity? |
@sg- Unity relies on utest for printing: https://github.com/ARMmbed/mbed-os/blob/master/features/frameworks/unity/unity/unity_config.h#L38 And utest relies on Greentea for printing:
And the whole point of this test is to not use Greentea. |
So if |
@sg- after looking at this a bit more, I'm now remembering that you can't use Unity outside of utest. This is due to the way Unity allows you to jump out of a utest test case immediately as soon as an assert fails (known as "Fail and bail": https://github.com/ARMmbed/mbed-os/blob/master/features/frameworks/unity/source/unity.c#L20). Unity asserts only work in the context of a utest test case. So if you wanted to use Unity asserts in non-utest test cases, some further refactoring would need to take place. |
In that case, is this essentially a greentea self-test? |
I wouldn't say so as it doesn't test greentea, it validates that your serial driver is good enough to run further tests (which use greentea). |
Do we have final decision about the localisation of this test? |
This got voted, can we place it there |
@mprse Looks like this now needs a rebase ? |
This test is for Vendors to check if uart (RawSerial) drivers are ready to use green-tea. Example usage: python test.py -t GCC_ARM -m NUCLEO_F070RB -b 9600 - run test using GCC_ARM toolchain, NUCLEO_F070RB board and test serial port with baud rate set to 9600 b/s.
Fixed conflicts - updated Travis script. |
I still maintain these should go to their own repository. The logic behind this is quite clear, they are an alternative to Greentea to ascertain whether or not the drivers are in a suitable state to be able to work with Greentea. Greentea has it's own repository so why shouldn't this ? |
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 a bit out-of-touch on this, so feel free to take my opinion with a grain of salt. I have no problem with this here as long as its documented well. It also has the benefit that I don't have to find another repository to clone.
But I understand @adbridge's view and think its valid as well. In my view I think this just needs an executive decision on where this lives.
Will need to be put into another repo. |
Description
This is a proposition of UART bare metal test for Green Tea.
Requirements:
Commit provides 2 files:
Example usage:
python test.py -t GCC_ARM -m NUCLEO_F070RB -b 9600 - run test using GCC_ARM toolchain, NUCLEO_F070RB board and test serial port with baud rate set to 9600 b/s.
python test.py -h - see detail usage information.
Status
HOLD - test location needs to be changed
Migrations
NO