Skip to content

Commit 5416aa8

Browse files
Cruz Monrreal IICruz Monrreal II
authored andcommitted
Merge branch 'lorjala-unittests-docs' into rollup-aus_writathon
2 parents 4e71d3f + 0f8e337 commit 5416aa8

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

UNITTESTS/README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Unit testing
22

3-
This document describes how to write and test unit tests for Mbed OS. To prevent and solve problems, please see the [troubleshooting](#troubleshooting) section.
3+
This document describes how to write and test unit tests for Arm Mbed OS. To prevent and solve problems, please see the [troubleshooting](#troubleshooting) section.
44

55
### Introduction
66

@@ -16,7 +16,7 @@ Please install the following dependencies to use Mbed OS unit testing.
1616
- Python 2.7.x, 3.5 or newer.
1717
- Pip 10.0 or newer.
1818
- Gcovr 4.1 or newer.
19-
- Mbed CLI 1.8.0 or newer.
19+
- Arm Mbed CLI 1.8.0 or newer.
2020

2121
Detailed instructions for supported operating systems are below.
2222

@@ -30,7 +30,7 @@ Detailed instructions for supported operating systems are below.
3030
sudo easy_install pip
3131
```
3232

33-
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/latest/tools/arm-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
33+
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/latest/tools/developing-arm-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
3434

3535
#### Installing dependencies on macOS
3636

@@ -43,15 +43,15 @@ Detailed instructions for supported operating systems are below.
4343
sudo easy_install pip
4444
```
4545

46-
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/latest/tools/arm-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
46+
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/latest/tools/developing-arm-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
4747

4848
#### Installing dependencies on Windows
4949

5050
1. Download and install [MinGW-W64](http://mingw-w64.org/).
5151
1. Download CMake binaries from https://cmake.org/download/, and run the installer.
5252
1. Download Python 2.7 or Python 3 from https://www.python.org/getit/, and run the installer.
5353
1. Add MinGW, CMake and Python into system PATH.
54-
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/latest/tools/arm-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
54+
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/latest/tools/developing-arm-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
5555

5656
### Test code structure
5757

@@ -69,7 +69,7 @@ The build system automatically generates names of test suites. The name is const
6969

7070
### Unit testing with Mbed CLI
7171

72-
Mbed CLI supports unit tests through `mbed test --unittests` command. For information on using Mbed CLI, please see the [CLI documentation in handbook](https://os.mbed.com/docs/latest/tools/arm-mbed-cli.html).
72+
Mbed CLI supports unit tests through `mbed test --unittests` command. For information on using Mbed CLI, please see the [CLI documentation](https://os.mbed.com/docs/latest/tools/developing-arm-mbed-cli.html).
7373

7474
### Writing unit tests
7575

@@ -154,17 +154,19 @@ TEST_F(TestSemaphore, constructor)
154154

155155
### Building and running unit tests
156156

157-
Use Mbed CLI to build and run unit tests. For advanced use, you can run CMake and a make program directly.
157+
Use Mbed CLI to build and run unit tests. For advanced use, you can run CMake and a Make program directly.
158158

159159
#### Build tests directly with CMake
160160

161161
1. Create a build directory `mkdir UNITTESTS/build`.
162162
1. Move to the build directory `cd UNITTESTS/build`.
163163
1. Run CMake using a relative path to `UNITTESTS` folder as the argument. So from `UNITTESTS/build` use `cmake ..`:
164164
- Add `-g [generator]` if generating other than Unix Makefiles such in case of MinGW use `-g "MinGW Makefiles"`.
165-
- Add `-DCOVERAGE:True` to add coverage compiler flags.
165+
- Add `-DCMAKE_MAKE_PROGRAM=<value>`, `-DCMAKE_CXX_COMPILER=<value>` and `-DCMAKE_C_COMPILER=<value>` to use a specific Make program and compilers.
166+
- Add `-DCMAKE_BUILD_TYPE=Debug` to build a debug build.
167+
- Add `-DCOVERAGE=True` to add coverage compiler flags.
166168
- See the [CMake manual](https://cmake.org/cmake/help/v3.0/manual/cmake.1.html) for more information.
167-
1. Run a make program (Make, Gmake, Mingw32-make and so on) to build the tests.
169+
1. Run a Make program to build the tests.
168170

169171
#### Run tests directly with CTest
170172

@@ -177,14 +179,24 @@ Run a test binary in the build directory to run a unit test suite. To run multip
177179
1. Add test executables into the list.
178180
1. Run them.
179181

182+
### Debugging
183+
184+
1. Use Mbed CLI to build a debug build. For advanced use, run CMake directly with `-DCMAKE_BUILD_TYPE=Debug`, and then run a Make program.
185+
1. Run GDB with a test executable as an argument to debug unit tests.
186+
180187
### Get code coverage
181188

182-
Use Mbed CLI to generate code coverage reports. For advanced use, you can run Gcovr or any other code coverage tool directly in the build directory.
189+
Use Mbed CLI to generate code coverage reports. For advanced use, follow these steps:
190+
191+
1. Run CMake with both `-DCMAKE_BUILD_TYPE=Debug` and `-DCOVERAGE=True`.
192+
1. Run a Make program to build the tests.
193+
1. Run the tests.
194+
1. Run Gcovr or any other code coverage tool directly in the build directory.
183195

184196
### Troubleshooting
185197

186198
**Problem:** Generic problems with CMake or with the build process.
187-
* **Solution**: Delete the build directory. Make sure that CMake, g++, gcc and a make program can be found in the path and are correct versions.
199+
* **Solution**: Delete the build directory. Make sure that CMake, g++, GCC and a Make program can be found in the path and are correct versions.
188200

189201
**Problem:** Virus protection identifies files generated by CMake as malicious and quarantines the files on Windows.
190202
* **Solution**: Restore the false positive files from the quarantine.

0 commit comments

Comments
 (0)