Skip to content

Commit 999650d

Browse files
author
Amanda Butler
authored
Copy edit README.md
Make minor copy edits.
1 parent 7795c20 commit 999650d

File tree

1 file changed

+50
-29
lines changed

1 file changed

+50
-29
lines changed

UNITTESTS/README.md

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,44 @@ This document describes how to run and write unit tests for Mbed OS. Please see
55
## Prerequisites
66

77
* GNU toolchains installed.
8-
* GCC 6 or later
9-
* MinGW-W64 is recommended, although any windows port of the above GCC versions should work
8+
* GCC 6 or later.
9+
* We recommend you use MinGW-W64, but any Windows port of the above GCC versions works.
1010
* CMake 3.0+ installed.
1111
* Python 2.7.x or >3.5 and pip 10.0 (or newer) installed.
1212
* gcovr >=4.1
1313

1414
### Installing dependencies on Debian/Ubuntu
1515

1616
1. `sudo apt-get -y install build-essential cmake`
17-
2. Install python and pip:
17+
2. Install Python and pip:
18+
1819
```
1920
sudo apt-get -y install python python-setuptools
2021
sudo easy_install pip
2122
```
23+
2224
3. Install [gcovr](#installing-covr).
2325
4. (Optional) Install [Mbed CLI](https://os.mbed.com/docs/latest/tools/arm-mbed-cli.html).
2426

2527
### Installing dependencies on Mac OS
2628

2729
1. Install [Homebrew](https://brew.sh/).
28-
2. Install gcc compilers and cmake with: `brew install gcc cmake`
29-
3. Install python and pip:
30+
2. Install GCC compilers and cmake with: `brew install gcc cmake`.
31+
3. Install Python and pip:
32+
3033
```
3134
brew install python
3235
sudo easy_install pip
3336
```
37+
3438
3. Install [gcovr](#installing-covr).
3539
4. (Optional) Install [Mbed CLI](https://os.mbed.com/docs/latest/tools/arm-mbed-cli.html).
3640

3741
### Installing dependencies on Windows
3842

3943
1. Download and install [MinGW-W64](http://mingw-w64.org/).
4044
2. Download CMake binaries from https://cmake.org/download/ and run the installer.
41-
3. Download Python2.7 or Python3 from https://www.python.org/getit/ and run the installer.
45+
3. Download Python 2.7 or Python 3 from https://www.python.org/getit/, and run the installer.
4246
4. Add MinGW, CMake and Python into PATH.
4347
5. Install [gcovr](#installing-covr).
4448
6. (Optional) Install [Mbed CLI](https://os.mbed.com/docs/latest/tools/arm-mbed-cli.html).
@@ -49,16 +53,19 @@ Install gcovr code coverage tool globally with `pip install 'gcovr>=4.1'` or usi
4953

5054
#### virtualenv
5155

52-
1. Install virtualenv if not installed with `pip install virtualenv`
56+
1. Install virtualenv if not installed with `pip install virtualenv`.
5357
2. Install gcovr with:
5458

5559
**[Debian/Linux/Mac OS]**
60+
5661
```
5762
virtualenv pyenv
5863
. pyenv/bin/activate
5964
pip install 'gcovr>=4.1'
6065
```
66+
6167
**[Windows]**
68+
6269
```
6370
virtualenv pyenv
6471
pyenv\\Scripts\\activate
@@ -67,7 +74,7 @@ pip install "gcovr>=4.1"
6774

6875
## Building and running unit tests
6976

70-
> In case of running into problems see [troubleshooting](#troubleshooting) section.
77+
> If you run into problems, see the [troubleshooting](#troubleshooting) section.
7178
7279
`UNITTESTS/mbed_unittest.py` contains testing scripts for Mbed OS unit testing. Mbed CLI supports unit testing through `mbed test --unittests` command with the same arguments.
7380

@@ -77,17 +84,17 @@ pip install "gcovr>=4.1"
7784
mbed test --unittests
7885
```
7986

80-
A subset of tests can be run by providing `-r` flag for the tool which runs tests matching a regular expression.
87+
A subset of tests can be run by providing `-r` flag for the tool, which runs tests matching a regular expression.
8188

82-
e.g. `mbed test --unittests --run -r features_netsocket`
89+
For example, `mbed test --unittests --run -r features_netsocket`
8390

8491
### Build manually without Python tools
8592

86-
1. Create a build directory e.g. `mkdir UNITTESTS/build`.
93+
1. Create a build directory. For example, `mkdir UNITTESTS/build`.
8794
2. Move to the build directory `cd UNITTESTS/build`.
88-
3. Run CMake with `cmake [RELATIVE PATH TO UNITTESTS DIR] [OPTIONAL ARGUMENTS]` e.g. `cmake ..`:
89-
* Add `-g [generator]` argument if target other than Unix Makefiles e.g. MinGW `-g "MinGW Makefiles"`
90-
4. Run make program (make, gmake, mingw32-make, etc).
95+
3. Run CMake with `cmake [RELATIVE PATH TO UNITTESTS DIR] [OPTIONAL ARGUMENTS]`. For example, `cmake ..`:
96+
* Add `-g [generator]` argument if target other than Unix Makefiles. For example, MinGW `-g "MinGW Makefiles"`.
97+
4. Run make program (make, gmake, mingw32-make and so on).
9198

9299
##### Run CMake and build Unix Makefiles (GNU make)
93100

@@ -116,42 +123,48 @@ Keyword variables (usage `cmake -D<VARIABLE>(:<TYPE>)=<value>`:
116123

117124
### Run in terminal
118125

119-
Unit tests can be run separately from each executable or by using ctest test runner. Run ctest with make program using target test. Options can be passed to ctest using ARGS argument. See [ctest manual](https://cmake.org/cmake/help/v3.0/manual/ctest.1.html) for more information.
126+
You can run unit tests separately from each executable or by using ctest test runner. Run ctest with make program using target test. Options can be passed to ctest using ARGS argument. See [ctest manual](https://cmake.org/cmake/help/v3.0/manual/ctest.1.html) for more information.
120127

121128
Run ctest on test suite level:
129+
122130
```
123131
{MAKE_PROGRAM} test -C [RELATIVE PATH TO BUILD DIRECTORY]
124132
```
125-
e.g. `make test -C UNITTESTS/build` or `mingw32-make test -C UNITTESTS/build`
133+
134+
For example, `make test -C UNITTESTS/build` or `mingw32-make test -C UNITTESTS/build`
126135

127136
Run ctest verbose (show each test case):
137+
128138
```
129139
{MAKE_PROGRAM} test -C UNITTESTS/build ARGS="-V"
130140
```
131141

132142
Run ctest dashboard test and create test results:
143+
133144
```
134145
{MAKE_PROGRAM} test --C UNITTESTS/build ARGS="-D ExperimentalTest"
135146
```
136147

137148
### Run with GUI test runner
138149

139-
1. Build and/or install *gtest-runner* using the documentation: https://github.com/nholthaus/gtest-runner
150+
1. Build and install *gtest-runner* using the documentation: https://github.com/nholthaus/gtest-runner.
140151

141152
2. Run the application, add built test executables into the list and run it.
142153

143154
### Get code coverage
144155

145-
Python tools use gcovr to build code coverage reports. Generate html report `UNITTESTS/build/coverage/index.html` with:
156+
Python tools use `gcovr` to build code coverage reports. Generate html report `UNITTESTS/build/coverage/index.html` with:
157+
146158
```
147159
mbed test --unittests --coverage html
148160
```
149161

150-
To get coverage for a single test suite, run gcovr separately for suite coverage data directory. See [gcovr documentation](https://gcovr.com/guide.html#filter-options) for more information.
162+
To get coverage for a single test suite, run `gcovr` separately for suite coverage data directory. See [gcovr documentation](https://gcovr.com/guide.html#filter-options) for more information.
151163

152-
e.g. for features/netsocket/InternetSocket coverage:
164+
For example, for `features/netsocket/InternetSocket` coverage:
153165

154166
Debian/Ubuntu/Mac OS:
167+
155168
```
156169
mkdir UNITTESTS/build
157170
cd UNITTESTS/build
@@ -160,7 +173,9 @@ make
160173
./features_netsocket_InternetSocket
161174
gcovr -r ../.. --html --html-detail -o ./index.html ./CMakeFiles/features_netsocket_InternetSocket.MbedOS.dir/
162175
```
176+
163177
Windows:
178+
164179
```
165180
mkdir UNITTESTS/build
166181
cd UNITTESTS/build
@@ -173,6 +188,7 @@ gcovr -r ..\.. --html --html-detail -o .\index.html .\CMakeFiles\features_netsoc
173188
## The structure of unit tests
174189

175190
The structure of the unit tests directory looks like this:
191+
176192
```
177193
UNITTESTS
178194
├── mbed_unittest.py Python tool for unit testing
@@ -193,17 +209,19 @@ UNITTESTS
193209
├── target_h Shared headers which can be used for tests.
194210
└── template Templates for creating new unittests
195211
```
196-
Each unit test has an identical directory tree as seen in the Mbed OS root folder. This is not a mandatory requirement but helps to maintain tests. Each class to be tested have their own `unittest.cmake` which is found by `CMakeLists.txt`.
212+
213+
Each unit test has an identical directory tree as seen in the Mbed OS root folder. This is not a mandatory requirement but helps to maintain tests. Each class to be tested has its own `unittest.cmake`, which `CMakeLists.txt` finds.
197214

198215
## Creating a unit test
199216

200217
Each class to be tested requires two files for unit testing:
201-
1. C++ unit test source file (e.g. `test_NetworkInterface.cpp`)
202-
2. CMake module file for unit test definition (`unittest.cmake`)
218+
219+
1. C++ unit test source file (for example, `test_NetworkInterface.cpp`).
220+
2. CMake module file for unit test definition (`unittest.cmake`).
203221

204222
A unit test definition file `unittest.cmake` requires variables to be set for a test to be configured. File source paths in `unittest.cmake` files need to be relative to the unit test folder and `CMakeLists.txt`.
205223

206-
* **TEST_SUITE_NAME** - Identifier for the test suite. Use naming convention *PATH_TO_THE_TESTABLE_FILE* e.g. *features_netsocket_InternetSocket*
224+
* **TEST_SUITE_NAME** - Identifier for the test suite. Use naming convention *PATH_TO_THE_TESTABLE_FILE*. For example, *features_netsocket_InternetSocket*
207225
* **unittest-includes** - Include paths for headers needed to build the tests in addition to the base include paths listed in [CMakeLists.txt](CMakeLists.txt). Optional.
208226
* **unittest-sources** - Mbed OS source files and stubs included for the build.
209227
* **unittest-test-sources** - Unit test source files.
@@ -214,16 +232,17 @@ A unit test definition file `unittest.cmake` requires variables to be set for a
214232
mbed test --unittests --new <FILEPATH>
215233
```
216234

217-
E.g. `mbed test --unittests --new rtos/Semaphore.cpp`
235+
For example, `mbed test --unittests --new rtos/Semaphore.cpp`
218236

219-
The generator script only creates the files required for a unit test. It does not write unit tests automatically nor does it handle source dependencies.
237+
The generator script only creates the files required for a unit test. It does not write unit tests automatically, nor does it handle source dependencies.
220238

221239
#### Create files manually
222240

223-
For example to create a unit test for `rtos/Semaphore.cpp`:
241+
For example, to create a unit test for `rtos/Semaphore.cpp`:
224242

225243
1. Create a directory for unit test files in `UNITTESTS/rtos/Semaphore`.
226244
2. Create a test definition file `UNITTESTS/rtos/Semaphore/unittest.cmake` with the following content:
245+
227246
```
228247
set(TEST_SUITE_NAME "rtos_Semaphore")
229248
@@ -236,7 +255,9 @@ set(unittest-test-sources
236255
rtos/Semaphore/test_Semaphore.cpp
237256
)
238257
```
258+
239259
3. Create a test source file `UNITTESTS/rtos/Semaphore/test_Semaphore.cpp` with the following content:
260+
240261
```
241262
#include "gtest/gtest.h"
242263
#include "rtos/Semaphore.h"
@@ -289,6 +310,6 @@ TEST_F(TestSemaphore, constructor)
289310

290311
## Troubleshooting
291312

292-
**Problem:** virus protection identifies files generated by CMake as malicious and quarantines the files on Windows.
313+
**Problem:** Virus protection identifies files generated by CMake as malicious and quarantines the files on Windows.
293314

294-
* **Solution**: restore the false positive files from the quarantine.
315+
* **Solution**: Restore the false positive files from the quarantine.

0 commit comments

Comments
 (0)