Skip to content

Commit 508e4ce

Browse files
committed
Update UNITTESTS and Greentea test docs
1 parent f72af59 commit 508e4ce

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

docs/debugging-testing/testing/testing_greentea.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This document will help you start using Greentea. Please see the [`htrun` docume
1010

1111
### Test code structure
1212

13-
You can run tests throughout Mbed OS and for your project's code. They are located under a special directory called `TESTS`.
13+
Greentea tests can be created anywhere in the Mbed OS directory structure or in your project's code. They are located under a special directory called `TESTS`. By convention, greentea tests for a specific Mbed OS library should be placed in a `TESTS` folder under that library. The `mbed-os/TESTS` folder is dedicated to integration or system tests.
1414

1515
The fact that the code is located under this directory means that it is ignored when building applications and libraries. It is only used when building tests. This is important because all tests require a `main()` function, and building them with your application would cause multiple `main()` functions to be defined.
1616

@@ -43,7 +43,7 @@ Test discovery also obeys the same rules that are used when building your projec
4343
For example, if you place a test under the directory `FEATURE_BLE` with the following path:
4444

4545
```
46-
myproject/mbed-os/features/FEATURE_BLE/TESTS/ble_tests/unit_test
46+
myproject/mbed-os/connectivity/FEATURE_BLE/tests/TESTS/ble_tests/unit_test
4747
```
4848

4949
This test case is only discovered if the target being tested supports the BLE feature. Otherwise, the test is ignored.
@@ -149,7 +149,8 @@ To interact with the host test from the device, you can use two functions: `gree
149149

150150
### Creating the host test
151151

152-
This example writes an integration test that sends `hello` to the host and waits until it receives `world`. Create a file called `hello_world_tests.py` in the `TESTS/host_tests` folder, and fill it with:
152+
This example writes an integration test that sends `hello` to the host and waits until it receives `world`.
153+
Create `host_tests` directory under `mbed-os/TESTS/`, if it does not exist and create a file called `hello_world_tests.py` in the `mbed-os/TESTS/host_tests` folder, and fill it with:
153154

154155
```py
155156
from mbed_host_tests import BaseHostTest
@@ -189,7 +190,7 @@ This registers one function you can call from the device: `init`. The function c
189190

190191
### Creating the Greentea test
191192

192-
This example writes the embedded part of this test. Create a new file `main.cpp` in `TESTS/tests/integration-test`, and fill it with:
193+
This example writes the embedded part of this test. Create a new file `main.cpp` under `TESTS/integration/test_case` directory, and fill it with:
193194

194195
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-snippet-Greentea_Ex_2/tree/v6.0)](https://github.com/ARMmbed/mbed-os-snippet-Greentea_Ex_2/blob/v6.0/main.cpp)
195196

@@ -198,7 +199,7 @@ You see the calls to and from the host through the `greentea_send_kv` and `green
198199
Run the test:
199200

200201
```
201-
$ mbed test -v -n tests-tests-integration-test
202+
$ mbed test -v -n tests-integration-test_case
202203
```
203204

204205
## Debugging tests
@@ -269,13 +270,13 @@ You can use the `--compile-list` argument to list all available tests:
269270

270271
```
271272
$ mbed test --compile-list
272-
[mbed] Working path "/Users/janjon01/repos/first-greentea-test" (program)
273+
[mbed] Working path "/Users/janjon01/mbed-os" (program)
273274
Test Case:
274-
Name: mbed-os-components-storage-blockdevice-component_flashiap-tests-filesystem-fopen
275-
Path: ./mbed-os/components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/filesystem/fopen
275+
Name: storage-blockdevice-component_sd-tests-tests-filesystem-fopen
276+
Path: ./storage/blockdevice/COMPONENT_SD/tests/TESTS/filesystem/fopen
276277
Test Case:
277-
Name: mbed-os-features-cellular-tests-api-cellular_device
278-
Path: ./mbed-os/features/cellular/TESTS/api/cellular_device
278+
Name: connectivity-lorawan-tests-tests-lorawan-loraradio
279+
Path: ./connectivity/lorawan/tests/TESTS/lorawan/loraradio
279280
280281
...
281282
```
@@ -288,22 +289,22 @@ The default action of Greentea using `mbed test` is to execute all tests found.
288289

289290
### Limiting tests
290291

291-
You can select test cases by name using the `-n` argument. This command executes all tests named `tests-mbedmicro-rtos-mbed-mail` from all builds in the test specification:
292+
You can select test cases by name using the `-n` argument. This command executes all tests named `platform-tests-tests-mbed_platform-atomic` from all builds in the test specification:
292293

293294
```
294-
$ mbed test -n tests-mbedmicro-rtos-mbed-mail
295+
$ mbed test -n platform-tests-tests-mbed_platform-atomic
295296
```
296297

297-
When using the `-n` argument, you can use the `*` character as a wildcard. This command executes all tests that start with `tests-` and have `-rtos-` in them.
298+
When using the `-n` argument, you can use the `*` character as a wildcard. This command executes all tests that start with `tests-` and have `-mbed_platform-` in them.
298299

299300
```
300-
$ mbed test -n tests-*-rtos-*
301+
$ mbed test -n tests-*-mbed_platform-*
301302
```
302303

303-
You can use a comma (`,`) to separate test names (argument `-n`) and build names (argument `-t`). This command executes the tests `tests-mbedmicro-rtos-mbed-mail` and `tests-mbed_drivers-c_strings` for the `K64F-ARM` and `K64F-GCC_ARM` builds in the test specification:
304+
You can use a comma (`,`) to separate test names (argument `-n`) and build names (argument `-t`). This command executes the tests `platform-tests-tests-mbed_platform-atomic` and `drivers-tests-tests-mbed_drivers-c_strings` for the `K64F-ARM` and `K64F-GCC_ARM` builds in the test specification:
304305

305306
```
306-
$ mbed test -n tests-mbedmicro-rtos-mbed-mail,tests-mbed_drivers-c_strings -t K64F-ARM,K64F-GCC_ARM
307+
$ mbed test -n platform-tests-tests-mbed_platform-atomic,drivers-tests-tests-mbed_drivers-c_strings -t K64F-ARM,K64F-GCC_ARM
307308
```
308309

309310
### Selecting platforms
@@ -393,19 +394,19 @@ Place this file in your root folder, and name it `test_spec.json`.
393394
"base_path": "./BUILD/K64F/ARM",
394395
"baud_rate": 9600,
395396
"tests": {
396-
"tests-mbedmicro-rtos-mbed-mail": {
397+
"platform-tests-tests-mbed_platform-atomic": {
397398
"binaries": [
398399
{
399400
"binary_type": "bootable",
400-
"path": "./BUILD/K64F/ARM/tests-mbedmicro-rtos-mbed-mail.bin"
401+
"path": "./BUILD/K64F/ARM/platform/tests/tests/mbed_platform/atomic/atomic.bin"
401402
}
402403
]
403404
},
404-
"tests-mbed_drivers-c_strings": {
405+
"drivers-tests-tests-mbed_drivers-c_strings": {
405406
"binaries": [
406407
{
407408
"binary_type": "bootable",
408-
"path": "./BUILD/K64F/ARM/tests-mbed_drivers-c_strings.bin"
409+
"path": "./BUILD/K64F/ARM/drivers/tests/tests/mbed_drivers/c_strings/c_strings.bin"
409410
}
410411
]
411412
}
@@ -417,11 +418,11 @@ Place this file in your root folder, and name it `test_spec.json`.
417418
"base_path": "./BUILD/K64F/GCC_ARM",
418419
"baud_rate": 9600,
419420
"tests": {
420-
"tests-mbedmicro-rtos-mbed-mail": {
421+
"platform-tests-tests-mbed_platform-atomic": {
421422
"binaries": [
422423
{
423424
"binary_type": "bootable",
424-
"path": "./BUILD/K64F/GCC_ARM/tests-mbedmicro-rtos-mbed-mail.bin"
425+
"path": "./BUILD/K64F/GCC_ARM/platform/tests/tests/mbed_platform/atomic/atomic.bin"
425426
}
426427
]
427428
}
@@ -439,10 +440,10 @@ mbedgt: using multiple test specifications from current directory!
439440
using 'BUILD\tests\K64F\ARM\test_spec.json'
440441
using 'BUILD\tests\K64F\GCC_ARM\test_spec.json'
441442
mbedgt: available tests for built 'K64F-GCC_ARM', location 'BUILD/tests/K64F/GCC_ARM'
442-
test 'tests-mbedmicro-rtos-mbed-mail'
443+
test 'platform-tests-tests-mbed_platform-atomic'
443444
mbedgt: available tests for built 'K64F-ARM', location 'BUILD/tests/K64F/ARM'
444-
test 'tests-mbed_drivers-c_strings'
445-
test 'tests-mbedmicro-rtos-mbed-mail'
445+
test 'drivers-tests-tests-mbed_drivers-c_strings'
446+
test 'platform-tests-tests-mbed_platform-atomic'
446447
```
447448

448449

docs/debugging-testing/testing/unit_testing.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ In a terminal window:
6161

6262
## Test code structure
6363

64-
Find unit tests in the Mbed OS repository under the `UNITTESTS` folder. We recommend unit test files use an identical directory path as the file under test. This makes it easier to find unit tests for a particular class or a module. For example, if the file you're testing is `some/example/path/ClassName.cpp`, then all the test files are in the `UNITTESTS/some/example/path/ClassName` directory. Each test suite needs to have its own `unittest.cmake` file for test configuration.
64+
Find unit tests in the Mbed OS repository under the `UNITTESTS` folder of each library. We recommend unit test files use an identical directory path as the file under test. This makes it easier to find unit tests for a particular class or a module. For example, if the file you're testing is `some/example/path/ClassName.cpp`, then all the test files are in the `UNITTESTS/some/example/path/ClassName` directory. Each test suite needs to have its own `unittest.cmake` file for test configuration.
6565

66-
All the class stubs should be located in the `UNITTESTS/stubs` directory. Multiple test suites can use a single stub class, which should follow the naming convention `ClassName_stub.cpp` for the source file and `ClassName_stub.h` for the header file. Use the actual header files for the unit tests, and don't stub headers if possible. The stubbed headers reside in the `UNITTESTS/target_h` directory.
66+
All the class stubs should be located in the Mbed OS root directory `UNITTESTS/stubs`. Multiple test suites can use a single stub class, which should follow the naming convention `ClassName_stub.cpp` for the source file and `ClassName_stub.h` for the header file. Use the actual header files for the unit tests, and don't stub headers if possible. The stubbed headers reside in the `UNITTESTS/target_h` directory.
6767

6868
### Test discovery
6969

@@ -190,7 +190,7 @@ With the following steps, you can write a unit test. This example creates dummy
190190
191191
## Add here test classes and stubs
192192
set(unittest-test-sources
193-
example/MyClass/test_MyClass.cpp
193+
${CMAKE_CURRENT_LIST_DIR}/test_MyClass.cpp
194194
stubs/OtherClass_stub.cpp
195195
)
196196
```
@@ -227,7 +227,7 @@ With the following steps, you can write a unit test. This example creates dummy
227227
}
228228
```
229229
230-
1. Stub all external dependencies. Create the following stub in `UNITTESTS/stubs`:
230+
1. Stub all external dependencies. Create the following stub in the Mbed OS root directory `UNITTESTS/stubs`:
231231
232232
**OtherClass_stub.cpp**
233233

0 commit comments

Comments
 (0)