Skip to content

Conversation

wernerlewis
Copy link
Contributor

@wernerlewis wernerlewis commented May 24, 2021

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 using mbedls directly for device detection. htrun is to be included in this repo.
  • Unused yotta files and references are removed.
  • Mbed references are removed, package has not yet been renamed.
  • Errors found with black, mypy and flake8 are resolved.
  • Docstrings are updated and standardised.

@wernerlewis wernerlewis marked this pull request as draft May 25, 2021 10:09
@wernerlewis wernerlewis marked this pull request as ready for review June 3, 2021 09:20
@rwalton-arm rwalton-arm mentioned this pull request Jun 3, 2021
22 tasks
@wernerlewis wernerlewis force-pushed the greentea-host branch 2 times, most recently from 729cdc7 to fb146d2 Compare June 3, 2021 12:51
Copy link
Contributor

@rwalton-arm rwalton-arm left a 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:

  1. Copies the code over as is
  2. Reformats with black
  3. Adds tox.ini
  4. 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.

@wernerlewis wernerlewis force-pushed the greentea-host branch 2 times, most recently from 3dd6af9 to 1180f2b Compare June 4, 2021 14:58
@wernerlewis
Copy link
Contributor Author

I've rebased and updated so that this integrates on top of the previous work, and split out the commits.

When running gt, htrun passes a few test suites, but fails the majority. Replacing htrun with mbedhtrun to use the existing version from mbed-os-tools doesn't show the same issue.

This seems to be due to the host_tests not being loaded from mbed-os: for example, due to the change in module name. So in host_registry.py host_tests aren't being registered, leading to "host test not detected" errors. This means gt/htrun will fail to run tests that rely on host_tests defined in mbed-os until those are updated.

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
Copy link
Contributor

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.


class GreenTeaSimpleLockLogger(object):
"""Simple locking printing mechanism."""
"""Simple lock printing mechanism."""
Copy link
Contributor

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
Copy link
Contributor

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.

@wernerlewis wernerlewis force-pushed the greentea-host branch 4 times, most recently from 0b6a4db to b05e20c Compare June 21, 2021 09:30
@Patater Patater requested a review from rwalton-arm June 25, 2021 10:56
Copy link

@LDong-Arm LDong-Arm left a 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?

Comment on lines 7 to 11
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,

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?

Copy link
Contributor Author

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().
LDong-Arm
LDong-Arm previously approved these changes Jul 1, 2021
Copy link

@LDong-Arm LDong-Arm left a 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 gtinstalled 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.

import json
from subprocess import Popen, PIPE

from subprocess import run
Copy link
Contributor

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:
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@rwalton-arm
Copy link
Contributor

So, I verified using tox -e py39 and tests passed. Also did a smoke test using gtinstalled 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.

I'm OK with the overall commits (apart from one point about how we import subprocess.run). One potentially important change is that we've removed the lockfile mechanism when spawning multiple instances. Most of the other changes are just cosmetic or small amounts of refactoring. I'm fine with merging the PR after my latest comment is addressed.

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.
Copy link
Contributor

@rwalton-arm rwalton-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@Patater Patater requested a review from LDong-Arm July 1, 2021 15:34
Copy link

@LDong-Arm LDong-Arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Patater Patater merged commit 2d527c0 into ARMmbed:master Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants