-
Notifications
You must be signed in to change notification settings - Fork 43
Standalone Greentea host #301
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
c653379
to
f6b92ad
Compare
f6b92ad
to
a6dbdf9
Compare
729cdc7
to
fb146d2
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.
In the commit "Initial greentea host" we seem to be doing far too much. We should split this into separate commits:
- Copies the code over as is
- Reformats with black
- Adds tox.ini
- Removes mbed refs
It doesn't matter as much about every commit passing tests at this point as we don't have any CI enabled. At the moment it's too difficult to review any changes we've made.
We also need to work out how we integrate this PR and #302 - I would've expected one of the PRs to be based on the other if there's any crossover. If they merge cleanly without conflicts as-is then great.
3dd6af9
to
1180f2b
Compare
I've rebased and updated so that this integrates on top of the previous work, and split out the commits. When running This seems to be due to the host_tests not being loaded from |
ctest_test_list, test_by_names, skip_test, test_spec=None | ||
): | ||
"""! Filters test case list (filtered with switch -n) and return filtered list. | ||
@ctest_test_list List iof tests, originally from CTestTestFile.cmake in yotta module. Now comes from test specification |
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.
Interesting, seems we had support for CTest in some form. Although it looks like we were trying to use this python tool to replace CTest by grepping CTestTestFile.cmake.
src/greentea/gtea/greentea_log.py
Outdated
|
||
class GreenTeaSimpleLockLogger(object): | ||
"""Simple locking printing mechanism.""" | ||
"""Simple lock printing mechanism.""" |
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's a lock printing mechanism? Do we mean a thread-safe printing mechanism? I assume we're trying to guarantee serialised output in a multi-threaded context with this object.
Returns: | ||
String containing Junit XML formatted test result output. | ||
""" | ||
from junit_xml import TestSuite, TestCase |
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 think we should create a task to remove the function scoped imports: it's not good form to import a bunch of stuff in a public api function, especially if it's going to be called more than once (we'll run the import code again on each call). It's a small cost to import these things at file scope, and a cost we only need to pay once at "import time". The function scoped imports are misguided attempts at micro-optimisation imo.
0b6a4db
to
b05e20c
Compare
b05e20c
to
b2a1c03
Compare
b2a1c03
to
3238106
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.
Thanks, there are lots of nice improvements in this PR.
But as an initial code-import PR, it might be easier if we just imported mbed-os-tools code "as-is" and make it run? As mbed-os-tools is in a working state, keeping it working in a different repo might only involve updating paths, etc. if I didn't miss anything? Maybe we can enable tests (e.g. tox) and fix failures incrementally in separate PRs?
The commits to import code look good to me, but the other fixes and improvements seem to have some learning curve for reviewers, and there are several things to review. Shall we consider limiting the scope and getting the imported code in first, so subsequent work (incl. other items in #303) can be worked on parallel? Or, if we are "overall" fine with all the commits, maybe get them in?
ignore = | ||
# H301: one import per line | ||
H301, | ||
# H306: imports not in alphabetical order | ||
H306, | ||
# W503: line break before binary operator (this is no longer PEP8 compliant) | ||
W503, | ||
# E203: whitespace before ':' (this is not PEP8 compliant) | ||
E203, |
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 seems to be added by this PR, as it looks different from what exists in mbed-os-tools?
The rules look good to have, maybe we should acknowledge the issues and plan to fix them in the future, instead of ignoring the rules?
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, I added these from mbed-tools. I've removed H301 and H306 as these do not need to be ignored. W503 is ignored as it goes against best practices, and E203 is ignored for PEP compliance, otherwise errors are raised due to formatting of list slicing.
This pulls in greentea from mbed-os-tools into this repo.
linting, py3* environments are added. requirements.txt is updated to include requirements that previously were used in mbed-os-tools.
License headers in files vary significantly in format. All files are updated to use a standard template.
Yotta is deprecated, and this content is no longer needed in greentea.
The following changes are made: - mbed prefix is removed from files. - mbed_os_tools greentea imports are replaced with greentea imports. - mbed_devices are renamed as devices. - MUT (Mbed Under Test) is changed to DUT (Device Under Test). - mbedhtrun in greentea CLI is changed to htrun. - mbedgt is changed to gt.
Dependency on mbed_os_tools is replaced with mbedls_tools. htrun is used from this repo.
Remove unused arguments and reword to improve understandability.
In greentea_hooks two different methods are given for running hooks, which have the same behaviour, implemented differently. This removes run_hook_ext to avoid this unnecessary repeat.
target_info relied on a local dict of information for a few Mbed OS targets, with data identical to that in targets.json. target_info is reworked to remove this case, just using targets.json if present, with a default fallback.
Some parser options are not used and can be removed. digest_source is removed along with corresponding code, due to lack of implementation.
optparse has been deprecated since Python 3.2. argparse is recommended as a replacement, minor changes must be made to support this.
A large HTML template was in report_api.py, which is moved into a separate template file. Old-style % string formatting is also replaced with f-strings and .format().
3238106
to
ca7a51f
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.
So, I verified using tox -e py39
and tests passed. Also did a smoke test using gt
installed from this PR to run tests on a board.
Btw, what about calling the command greentea
instead of gt
? I just feel that two-letter commands are too easy to clash, and normally system commands are this short.
@ARMmbed/mbed-os-core I strongly feel that we should prioritise getting this merged, because it's been open for a long time and blocking further work on this repo.
src/greentea/gtea/greentea_hooks.py
Outdated
import json | ||
from subprocess import Popen, PIPE | ||
|
||
from subprocess import run |
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.
Usually the style is to import subprocess
and then call subprocess.run
as it's then explicit what the run
function is doing. The function name itself is rather generic, so using the namespaced form at the call site is better in this case.
except OSError as e: | ||
gt_logger.gt_log_err(str(e)) | ||
return -1 | ||
if p.stdout: |
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 not just set capture_output=False
? We seem to print stdout
and stderr
all the time if they aren't empty.
I would also leave shell=False
unless absolutely necessary, as shell=True
causes subprocess
to spawn an intermediate "shell instance" to run the command, which could make us vulnerable to shell injection exploits.
We might have to change self.cmd
to a list to make this work with shell=False
, if it's currently just a string. We should probably deal with the shell spawning in another PR anyway as it was preexisting.
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've removed the capture_output
arg. cmd
is a string, so that will need to be changed to remove shell=True
.
I'm OK with the overall commits (apart from one point about how we import |
subprocess.run() is supported in Python 3.5+, making this wrapper not required. An unused implementation of the same wrapper is also removed.
The locking mechanism, greentea kettle, is marked as experimental, and the implementation is not complete. The package used by the mechanism is deprecated, and the value of implementing a locking feature is not clear, so this mechanism can be removed.
CTestTestfile.cmake is no longer parsed by greentea. References to CTest and unused code for CTest parsing are removed.
Previous testing had ignored greentea source files when running flake8. As a result, a number of style issues needed to be resolved. Along with this, docstrings are updated, in google-style.
ca7a51f
to
fed2b1a
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.
LGTM. Thanks.
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.
LGTM
Development of greentea host was moved into mbed-os-tools and this repository was deprecated. Following the decision to make Greentea standalone again, this repository is reused.
The following changes are made:
mbed-os-tools
is not required, now usingmbedls
directly for device detection.htrun
is to be included in this repo.black
,mypy
andflake8
are resolved.