Skip to content

Feature: Macros handling to mbed test #835

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

Merged
merged 4 commits into from
Feb 7, 2019

Conversation

screamerbg
Copy link
Contributor

This PR introduces 3 related features:

  • Add support for macros handling to mbed test
  • Pass macros only to mbed-os/tools/test.py and not to mbedgt to enable workflow where mbed test ... -D SOME_MACRO will both compile the tests with the macro and also run mbed greentea without getting the no such option: -D error.
  • Add macro MBED_TEST_MODE to mbed test to allow the main application to exclude main(). See https://github.com/ARMmbed/pelion-ready-example/blob/master/main.cpp#L18

Pass macros only to `mbed-os/tools/test.py` and not to mbedgt to enable workflow where `mbed test ... -D SOME_MACRO` will both compile with the macro and also run mbed greentea without `no such option: -D` error.
Add macro `MBED_TEST_MODE` to `mbed test` to allow the main application to exclude the main() using the macro. See https://github.com/ARMmbed/pelion-ready-example/blob/master/main.cpp#L18
def get_macros(self):
macros = []
def get_macros(self, more_macros=False):
macros = more_macros or []
Copy link
Contributor

@bridadan bridadan Feb 1, 2019

Choose a reason for hiding this comment

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

EDIT: oh dear, this is a bad idea, please ignore. Thanks @theotherjimmy

nitpick/simplification: You can simplify this block by altering the function:

    def get_macros(self, macros=[]):

This allows you to remove this line

Suggested change
macros = more_macros or []

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

That being said, please change False to None, as it's the pythonic "value is missing" value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yikes, thanks for the heads up. I learned something today.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bridadan see Jimmy's comment and also the extra commit. I had it before the way you suggested :)

mbed/mbed.py Outdated
macros = []
def get_macros(self, more_macros=False):
macros = more_macros or []
# backwards compatibility with old MACROS.txt file
if os.path.isfile('MACROS.txt'):
with open('MACROS.txt') as f:
macros = f.read().splitlines()
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to add to the macros that could be found in MACROS.txt file, then you'd want something like this:

Suggested change
macros = f.read().splitlines()
macros.extend(f.read().splitlines())

Otherwise the supplied macros from the function arguments will be dropped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I'll change it later.

app_config=None, test_config=None, coverage=None, make_program=None,
new=None, generator=None, regex=None, unittests=None,
build_data=None, greentea=None, icetea=None):
def test_(toolchain=None, target=None, macro=False, compile_list=False, run_list=False, compile_only=False, run_only=False, tests_by_name=None, source=False, profile=False, build=False, clean=False, test_spec=None, app_config=None, test_config=None, coverage=None, make_program=None, new=None, generator=None, regex=None, unittests=None, build_data=None, greentea=None, icetea=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def test_(toolchain=None, target=None, macro=False, compile_list=False, run_list=False, compile_only=False, run_only=False, tests_by_name=None, source=False, profile=False, build=False, clean=False, test_spec=None, app_config=None, test_config=None, coverage=None, make_program=None, new=None, generator=None, regex=None, unittests=None, build_data=None, greentea=None, icetea=None):
def test_(toolchain=None, target=None, macro=False, compile_list=False,
run_list=False, compile_only=False, run_only=False, tests_by_name=None,
source=False, profile=False, build=False, clean=False, test_spec=None,
app_config=None, test_config=None, coverage=None,
make_program=None, new=None, generator=None, regex=None,
unittests=None, build_data=None, greentea=None, icetea=None):

Co-Authored-By: screamerbg <[email protected]>
@theotherjimmy
Copy link
Contributor

@screamerbg Do you have time to make the suggested changes? would you like me to help make them?

Copy link
Contributor

@bridadan bridadan left a comment

Choose a reason for hiding this comment

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

Needs the update to the MACROS.txt I mentioned.

Otherwise the supplied macros from the function arguments will be dropped.
@theotherjimmy theotherjimmy dismissed bridadan’s stale review February 7, 2019 17:35

Updated macros.txt code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants