ARMmbed / mbed-cli

Arm Mbed Command Line Interface
https://os.mbed.com
Apache License 2.0
333 stars 176 forks source link

Run test for the case that application contains a main function #537

Closed maxpeng closed 5 years ago

maxpeng commented 7 years ago

From the mbed CLI documentation, it describes this:

Note: mbed test does not work in applications that contain a main function that is outside of a TESTS directory.

For normal project layout, we will place a main function outside the TESTS directory, and place unit test code inside TESTS directory. I didn't want to rename the file containing main, so I tried to write the application C file containing main function as:

#ifndef UNIT_TEST
...
int main(void)
{
...
}
#endif

That is, when UNIT_TEST is defined, the application main will not be included. Then I tried to build the test code by this command:

mbed test -m xxx -t xxx -DUNIT_TEST

Although the documentation does not describe it support -D option, the test code could be compiled successfully. Unfortunately, the mbedgt didn't like the -D option:

mbedgt: error: no such option: -D
[mbed] ERROR: "mbedgt" returned error code 2.

How do we build the application and test code easily by using mbed CLI?

bridadan commented 7 years ago

@maxpeng That's a good work around!

You can do the build run step separately:

mbed test -m xxx -t xxx -DUNIT_TEST --compile
mbed test -m xxx -t xxx --run
maxpeng commented 7 years ago

@bridadan Thanks for your tip - split the intended action into 2 steps.

I wonder if it is better for the mbed test command to automatically define some kind of macro to ease the task.

screamerbg commented 6 years ago

@bridadan @maxpeng Is there any follow up on this? If not, are you happy to close this issue?

bridadan commented 6 years ago

I wonder if it is better for the mbed test command to automatically define some kind of macro to ease the task.

That seems reasonable honestly, and I bet a lot of folks would appreciate that.

@theotherjimmy how do you feel about that?

theotherjimmy commented 6 years ago

Sounds like a workable plan to me.

moshe-shahar commented 6 years ago

I face similar issue, trying to build application (using mbed compile) and tests (using mbed test) under the same working tree.

Please consider another way for the fix, by ignoring main functions outside of TESTS directories when building tests using mbed test. In that way there is no need to use another compilation flag.

jenia81 commented 6 years ago

@screamerbg Fix of this issue will help us for compilation of our unit tests. I believe that also @TeroJaasko will find this useful (for compiling PAL unit tests from Pelion Client application). Is this something that can be considered to be added in next mbed-cli version?

theotherjimmy commented 6 years ago

@jenia81 The Mbed CLI version has no bearing on the behavior of mbed test --compile, outside of accepting the --icetea and --greentea switches.

@moshe-shahar

by ignoring main functions outside of TESTS directories when building tests using mbed test.

I'm sure this would be useful, but how do you propose we do that? As it stands, the build tools don't know where main lives, and only deal with source files.

moshe-shahar commented 6 years ago

@theotherjimmy ,I understand. Thanks for your answer.

ciarmcom commented 6 years ago

Internal Jira reference: https://jira.arm.com/browse/MBOCUSTRIA-72

j3hill commented 5 years ago

@moshe-shahar 5 months have gone by, and it appears that Jimmy answered your question by explaining the limitations of what can be determined by the CLI when a program is being compiled. This issue will now be closed if there are no further questions.

moshe-shahar commented 5 years ago

Ok, thanks!

From: Tres Hill notifications@github.com Sent: Monday, March 11, 2019 4:37 PM To: ARMmbed/mbed-cli mbed-cli@noreply.github.com Cc: Moshe Shahar Moshe.Shahar@arm.com; Mention mention@noreply.github.com Subject: Re: [ARMmbed/mbed-cli] Run test for the case that application contains a main function (#537)

@moshe-shaharhttps://github.com/moshe-shahar 5 months have gone by, and it appears that Jimmy answered your question by explaining the limitations of what can be determined by the CLI when a program is being compiled. This issue will now be closed if there are no further questions.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/ARMmbed/mbed-cli/issues/537#issuecomment-471564759, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AeH3gb9EMUilYpOcOHQIYrnOZbRz7xHwks5vVmoGgaJpZM4PC6RG.

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

bridadan commented 5 years ago

Note that as of version 1.9.0 of Mbed CLI, we add the MBED_TEST_MODE macro when compiling with mbed test. Here are the docs describing the feature: https://github.com/ARMmbed/mbed-os-5-docs/pull/1003