Skip to content

Unit testing framework #7819

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 2 commits into from
Aug 29, 2018
Merged

Unit testing framework #7819

merged 2 commits into from
Aug 29, 2018

Conversation

lorjala
Copy link
Contributor

@lorjala lorjala commented Aug 17, 2018

Description

Unit testing framework for writing, building and running Mbed OS unit tests for developers and contributors.

  • Separate test binaries
  • No HW and SW dependencies for testable code
  • Linux, Mac OS and Windows

MBEDOSTEST-3

Pull request type

[ ] Fix
[ ] Refactor
[ ] Target update
[x] Feature
[ ] Breaking change

@cmonr cmonr requested review from NeilJackson-AlifSemi, a user and sg- August 17, 2018 22:51
static uint32_t count = 0;

// Test stubs
osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout) { return retval; }
Copy link
Contributor

Choose a reason for hiding this comment

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

examples should follow our coding style (please run astyle on this code and update the example)

{
char *n = 0;
EXPECT_EQ(iface->get_mac_address(), n);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

No newline in t hese files? Leave one please

### Testing with Python script:

```
./UNITTESTS/mbed_unittest.py test
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this how we want to introduce this tools ? Shouldn't this be mbed unittest rather? and this scripts to be moved into tools/ folder

@@ -0,0 +1,13 @@
#include "events/mbed_shared_queues.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Add license headers to the new files, like this one

@@ -0,0 +1,24 @@
#include "rtos/EventFlags.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

ATHandler_stub - has suffix, but some of the stubs do not have, like this one. Is there a naming convention?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Few example unit tests are from features/cellular/UNITTESTS without major changes to demonstrate how to convert existing unit tests to use this framework. So ATHandler_stub for example is from these existing tests which uses that naming convention. These unit tests introduced in this PR are not final in any form including naming. Their purpose is only to showcase the framework before proper unit tests are written/converted.

### Testing with Mbed CLI

```
mbed unittest test

Choose a reason for hiding this comment

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

Please describe what will be the behavior of new code when executing mbed compile. All C/CPP files inside unittest folder will not be build or will be skipped during linking step?

Copy link
Contributor

@0xc0170 0xc0170 Aug 20, 2018

Choose a reason for hiding this comment

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

I am now reviewing Icetea addition. So back to this mbed unittest comment I had earlier today.
Icetea has it as mbed test -m <target> -t <toolchain> --icetea . This should follow it ? as mbed test -m <target> -t <toolchain> --unittest or just this unittest

Just looking for alignment (icetea / unittest/ app test) - if there can be any. Adding my comment here to this line (hijacking @deepikabhavnani question that is however related)

@OPpuolitaival Please review

Copy link
Contributor

Choose a reason for hiding this comment

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

No, the unittesting is basically target and toolchain agnostic.
It runs the one provided by the host OS.

So it is so different from what mbed test is targeting, that it requires its own command.

Copy link
Contributor

Choose a reason for hiding this comment

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

@SeppoTakalo is right, we need separated command because:
"mbed test" - testing code which runs on embedded device and therefore need a target and toolchain
"mbed unittest" - testing code units in host computer using documented compilers

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, own command

### Testing with Mbed CLI

```
mbed unittest test
Copy link
Contributor

Choose a reason for hiding this comment

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

@SeppoTakalo is right, we need separated command because:
"mbed test" - testing code which runs on embedded device and therefore need a target and toolchain
"mbed unittest" - testing code units in host computer using documented compilers


Traditional software testing is defined into three main levels: unit testing, integration testing and system testing. These levels are often pictured as a pyramid to indicate the amount of testing per level.
```
^ Testing level
Copy link
Contributor

Choose a reason for hiding this comment

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

@SeppoTakalo should we move this picture in testing introduction in Handbook?

* GCC 6 or later
* MinGW-W64 GCC-6.4.0 or MinGW-W64 GCC-7.3.0 (Windows)
* CMake 3.0+ installed.
* Python and pip installed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Which python versions we support? Need to define. And maybe pip also. Something like python 2.7.x or >3.5

* MinGW-W64 GCC-6.4.0 or MinGW-W64 GCC-7.3.0 (Windows)
* CMake 3.0+ installed.
* Python and pip installed.
* gcovr and optionally virtualenv pip modules installed.
Copy link
Contributor

Choose a reason for hiding this comment

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

gcovr version definition?

mbed unittest test
```

##### Parameters to mbed unittest test
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel good to list these here because these are coming from mbed-cli and mbed-cli works with any version of Mbed OS. Then we don't have guarantee that these are like this forever.

mbed unittest new
```

##### Parameters to mbed unittest new
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't list parameters here because there is no guarantee. Just command and why it exist is good enough

@SeppoTakalo
Copy link
Contributor

Is it a bit too early to describe mbed unittest command here?
First we need this in,
then we can add the command into mbed-cli.

Also, don't remove anything from the README.md, once ready, we just submit part of it into Mbed OS handbook.

@lorjala
Copy link
Contributor Author

lorjala commented Aug 21, 2018

Referencing Mbed CLI here should be ok, because it is mentioned elsewhere in the repo as well(case greentea), and it would not take long to get new mbed-cli release out (PR is ongoing).

@SeppoTakalo
Copy link
Contributor

OK.
Thanks.
PR already here ARMmbed/mbed-cli#734

Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

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

@theotherjimmy Please check the location for the scripts here (in the UNITTESTS folder rather than tools/unittests or similar). If that is fine.

@cmonr cmonr added risk: A and removed risk: G labels Aug 24, 2018
@cmonr
Copy link
Contributor

cmonr commented Aug 24, 2018

First we need this in, then we can add the command into mbed-cli.

Not really. Both PRs can be active in parallel, and we can even merge one before another, as long as we make sure they're released together. But it looks like y'all are already moving forward with that.

@OPpuolitaival
Copy link
Contributor

@cmonr you are right. Mbed-cli need to work for many Mbed OS version which means that it works also without unit tests in repository. PRs can be merged in any order

@lorjala
Copy link
Contributor Author

lorjala commented Aug 27, 2018

@0xc0170 @cmonr can you trigger the build?

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 27, 2018

@0xc0170 @cmonr can you trigger the build?

I would like to have first all approvals (currently one requested changes) and someone from @ARMmbed/mbed-os-test reviewed

@OPpuolitaival
Copy link
Contributor

@0xc0170 I accepted this

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 27, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Aug 27, 2018

Build : SUCCESS

Build number : 2923
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/7819/

Triggering tests

/morph test
/morph export-build
/morph mbed2-build

@cmonr cmonr added risk: G and removed risk: A labels Aug 27, 2018
@mbed-ci
Copy link

mbed-ci commented Aug 27, 2018

```
virtualenv pyenv
pyenv\\Scripts\\activate
pip install 'gcovr>=4.1'
Copy link
Contributor

Choose a reason for hiding this comment

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

All looks good, well done! I give a quick try, everything works just fine, apart from this line.
Seems on my windows 10, pip not like the single quotes, but only works with double quotes. please confirm @lorjala

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, single quotes do not work when using default command prompt, but they do with powershell.

@mbed-ci
Copy link

mbed-ci commented Aug 28, 2018

Test : SUCCESS

Build number : 2674
Test logs :http://mbed-os-logs.s3-website-us-west-1.amazonaws.com/?prefix=logs/7819/2674

@lorjala
Copy link
Contributor Author

lorjala commented Aug 28, 2018

@0xc0170 @cmonr This can be merged (trigger the build again if necessary).

@cmonr
Copy link
Contributor

cmonr commented Aug 28, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Aug 28, 2018

Build : SUCCESS

Build number : 2942
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/7819/

Triggering tests

/morph test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Aug 28, 2018

@mbed-ci
Copy link

mbed-ci commented Aug 29, 2018

@cmonr cmonr merged commit 7ecf111 into ARMmbed:master Aug 29, 2018
@lorjala lorjala deleted the unittests branch August 31, 2018 09:21
@cmonr cmonr removed the risk: G label Sep 2, 2018
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.

9 participants