You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -49,16 +53,19 @@ Install gcovr code coverage tool globally with `pip install 'gcovr>=4.1'` or usi
49
53
50
54
#### virtualenv
51
55
52
-
1. Install virtualenv if not installed with `pip install virtualenv`
56
+
1. Install virtualenv if not installed with `pip install virtualenv`.
53
57
2. Install gcovr with:
54
58
55
59
**[Debian/Linux/Mac OS]**
60
+
56
61
```
57
62
virtualenv pyenv
58
63
. pyenv/bin/activate
59
64
pip install 'gcovr>=4.1'
60
65
```
66
+
61
67
**[Windows]**
68
+
62
69
```
63
70
virtualenv pyenv
64
71
pyenv\\Scripts\\activate
@@ -67,7 +74,7 @@ pip install "gcovr>=4.1"
67
74
68
75
## Building and running unit tests
69
76
70
-
> In case of running into problems see [troubleshooting](#troubleshooting) section.
77
+
> If you run into problems, see the[troubleshooting](#troubleshooting) section.
71
78
72
79
`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.
73
80
@@ -77,17 +84,17 @@ pip install "gcovr>=4.1"
77
84
mbed test --unittests
78
85
```
79
86
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.
81
88
82
-
e.g.`mbed test --unittests --run -r features_netsocket`
89
+
For example,`mbed test --unittests --run -r features_netsocket`
83
90
84
91
### Build manually without Python tools
85
92
86
-
1. Create a build directory e.g.`mkdir UNITTESTS/build`.
93
+
1. Create a build directory. For example,`mkdir UNITTESTS/build`.
87
94
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).
91
98
92
99
##### Run CMake and build Unix Makefiles (GNU make)
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.
120
127
121
128
Run ctest on test suite level:
129
+
122
130
```
123
131
{MAKE_PROGRAM} test -C [RELATIVE PATH TO BUILD DIRECTORY]
124
132
```
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`
126
135
127
136
Run ctest verbose (show each test case):
137
+
128
138
```
129
139
{MAKE_PROGRAM} test -C UNITTESTS/build ARGS="-V"
130
140
```
131
141
132
142
Run ctest dashboard test and create test results:
143
+
133
144
```
134
145
{MAKE_PROGRAM} test --C UNITTESTS/build ARGS="-D ExperimentalTest"
135
146
```
136
147
137
148
### Run with GUI test runner
138
149
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.
140
151
141
152
2. Run the application, add built test executables into the list and run it.
142
153
143
154
### Get code coverage
144
155
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
+
146
158
```
147
159
mbed test --unittests --coverage html
148
160
```
149
161
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.
151
163
152
-
e.g. for features/netsocket/InternetSocket coverage:
164
+
For example, for `features/netsocket/InternetSocket` coverage:
The structure of the unit tests directory looks like this:
191
+
176
192
```
177
193
UNITTESTS
178
194
├── mbed_unittest.py Python tool for unit testing
@@ -193,17 +209,19 @@ UNITTESTS
193
209
├── target_h Shared headers which can be used for tests.
194
210
└── template Templates for creating new unittests
195
211
```
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.
197
214
198
215
## Creating a unit test
199
216
200
217
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`).
203
221
204
222
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`.
205
223
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*
207
225
***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.
208
226
***unittest-sources** - Mbed OS source files and stubs included for the build.
209
227
***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
214
232
mbed test --unittests --new <FILEPATH>
215
233
```
216
234
217
-
E.g.`mbed test --unittests --new rtos/Semaphore.cpp`
235
+
For example,`mbed test --unittests --new rtos/Semaphore.cpp`
218
236
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.
220
238
221
239
#### Create files manually
222
240
223
-
For example to create a unit test for `rtos/Semaphore.cpp`:
241
+
For example, to create a unit test for `rtos/Semaphore.cpp`:
224
242
225
243
1. Create a directory for unit test files in `UNITTESTS/rtos/Semaphore`.
226
244
2. Create a test definition file `UNITTESTS/rtos/Semaphore/unittest.cmake` with the following content:
245
+
227
246
```
228
247
set(TEST_SUITE_NAME "rtos_Semaphore")
229
248
@@ -236,7 +255,9 @@ set(unittest-test-sources
236
255
rtos/Semaphore/test_Semaphore.cpp
237
256
)
238
257
```
258
+
239
259
3. Create a test source file `UNITTESTS/rtos/Semaphore/test_Semaphore.cpp` with the following content:
0 commit comments