Testing with the Greentea framework
Read the following page to understand how tests are structured:
Prerequisites
Minimum HAL module support
To run the Mbed OS built-in tests, you need to have ported and verified at least these HAL modules:
- Low power ticker.
- Serial port (synchronous transfer). To verify that it works, load a test binary with
printf()
. Verify debug messages can be seen on your serial terminal program. - Microsecond ticker.
You'll also need to have ported DAPLink or compatible interface firmware to your interface chip. If DAPLink is still under development, you can still run tests manually.
mbedls
The platform under test needs to be supported in mbedls for automated tests to work.
If an updated mbedls pip package including support for your platform hasn't been released yet, you need to direct pip to use your local directory (which includes the code changes to support the new platform):
-
Run
pip install --editable <your_local_root_to_mbed-os-tools>
. -
Run
pip install --editable <your_local_root_to_mbed-os-tools>/packages/mbed-ls
. -
If you're using an external serial probe (like an FTDI USB cable), create an
mbedls.json
file and specify the serial port.The serial port path varies in different operation systems. On Windows, you can find it through Device Manager; it will usually be something like
COM#
. On Mac OS you can usels /dev/tty.usb*
. On Linux you can usels /dev/ttyACM*
. The format ofmbedls.json
is as follows:{ "33000000e062afa300000000000000000000000097969902": { "serial_port": "/dev/tty.usbserial-FTGDJJOC" } }
Where
"33000000e062afa300000000000000000000000097969902"
is the correct target id.
Compiling and running tests
- Compile the tests:
- To compile all tests, run
mbed test --compile
. - To see the list of compiled tests, run
mbed test --compile-list
. - To compile a specific test, run
mbed test --compile -n <test_name>
. For example:mbed test --compile -n mbed-os-tests-concurrent-gpio)
.
- To compile all tests, run
- To run your tests, run
mbed test --run
.
Here is an example of a successful run:
mbed test --run -n tests-concurrent-gpio
mbedgt: greentea test automation tool ver. 1.4.0
mbedgt: using multiple test specifications from current directory!
using 'BUILD/tests/CC3220SF/GCC_ARM/test_spec.json'
mbedgt: detecting connected mbed-enabled devices...
mbedgt: detected 1 device
mbedgt: processing target 'CC3220SF' toolchain 'GCC_ARM' compatible platforms... (note: switch set to --parallel 1)
mbedgt: running 1 test for platform 'CC3220SF' and toolchain 'GCC_ARM'
mbedgt: mbed-host-test-runner: started
mbedgt: checking for GCOV data...
mbedgt: test on hardware with target id: 33000000e062afa300000000000000000000000097969902
mbedgt: test suite 'tests-concurrent-gpio' ........................................................... OK in 19.25 sec
test case: 'Concurrent testing of DIO(D0,D1), and InterruptIn(D2,D3)' ........................ OK in 0.09 sec
test case: 'Concurrent testing of DIO(D1,D0), and InterruptIn(D3,D2)' ........................ OK in 0.07 sec
test case: 'Concurrent testing of DIO(D2,D3), and InterruptIn(D4,D5)' ........................ OK in 0.08 sec
test case: 'Concurrent testing of DIO(D3,D2), and InterruptIn(D5,D4)' ........................ OK in 0.10 sec
test case: 'Concurrent testing of DIO(D4,D5), and InterruptIn(D0,D1)' ........................ OK in 0.09 sec
test case: 'Concurrent testing of DIO(D4,D5), and InterruptIn(D2,D3)' ........................ OK in 0.10 sec
test case: 'Concurrent testing of DIO(D5,D4), and InterruptIn(D1,D0)' ........................ OK in 0.09 sec
test case: 'Concurrent testing of DIO(D5,D4), and InterruptIn(D3,D2)' ........................ OK in 0.09 sec
test case: 'Concurrent testing of DIO(D6,D7), and InterruptIn(D8,D9)' ........................ OK in 0.09 sec
test case: 'Concurrent testing of DIO(D7,D6), and InterruptIn(D9,D8)' ........................ OK in 0.10 sec
test case: 'Concurrent testing of DIO(D8,D9), and InterruptIn(D2,D3)' ........................ OK in 0.08 sec
test case: 'Concurrent testing of DIO(D9,D8), and InterruptIn(D3,D2)' ........................ OK in 0.10 sec
mbedgt: test case summary: 12 passes, 0 failures
mbedgt: all tests finished!
mbedgt: shuffle seed: 0.3988791596
mbedgt: test suite report:
+------------------+---------------+-----------------------+--------+--------------------+-------------+
| target | platform_name | test suite | result | elapsed_time (sec) | copy_method |
+------------------+---------------+-----------------------+--------+--------------------+-------------+
| CC3220SF-GCC_ARM | CC3220SF | tests-concurrent-gpio | OK | 19.25 | default |
+------------------+---------------+-----------------------+--------+--------------------+-------------+
mbedgt: test suite results: 1 OK
mbedgt: test case report:
+------------------+---------------+-----------------------+----------------------------------------------------------+--------+--------+--------+--------------------+
| target | platform_name | test suite | test case | passed | failed | result | elapsed_time (sec) |
+------------------+---------------+-----------------------+----------------------------------------------------------+--------+--------+--------+--------------------+
| CC3220SF-GCC_ARM | CC3220SF | tests-concurrent-gpio | Concurrent testing of DIO(D0,D1), and InterruptIn(D2,D3) | 1 | 0 | OK | 0.09 |
| CC3220SF-GCC_ARM | CC3220SF | tests-concurrent-gpio | Concurrent testing of DIO(D1,D0), and InterruptIn(D3,D2) | 1 | 0 | OK | 0.07 |
| CC3220SF-GCC_ARM | CC3220SF | tests-concurrent-gpio | Concurrent testing of DIO(D2,D3), and InterruptIn(D4,D5) | 1 | 0 | OK | 0.08 |
| CC3220SF-GCC_ARM | CC3220SF | tests-concurrent-gpio | Concurrent testing of DIO(D3,D2), and InterruptIn(D5,D4) | 1 | 0 | OK | 0.1 |
| CC3220SF-GCC_ARM | CC3220SF | tests-concurrent-gpio | Concurrent testing of DIO(D4,D5), and InterruptIn(D0,D1) | 1 | 0 | OK | 0.09 |
| CC3220SF-GCC_ARM | CC3220SF | tests-concurrent-gpio | Concurrent testing of DIO(D4,D5), and InterruptIn(D2,D3) | 1 | 0 | OK | 0.1 |
| CC3220SF-GCC_ARM | CC3220SF | tests-concurrent-gpio | Concurrent testing of DIO(D5,D4), and InterruptIn(D1,D0) | 1 | 0 | OK | 0.09 |
| CC3220SF-GCC_ARM | CC3220SF | tests-concurrent-gpio | Concurrent testing of DIO(D5,D4), and InterruptIn(D3,D2) | 1 | 0 | OK | 0.09 |
| CC3220SF-GCC_ARM | CC3220SF | tests-concurrent-gpio | Concurrent testing of DIO(D6,D7), and InterruptIn(D8,D9) | 1 | 0 | OK | 0.09 |
| CC3220SF-GCC_ARM | CC3220SF | tests-concurrent-gpio | Concurrent testing of DIO(D7,D6), and InterruptIn(D9,D8) | 1 | 0 | OK | 0.1 |
| CC3220SF-GCC_ARM | CC3220SF | tests-concurrent-gpio | Concurrent testing of DIO(D8,D9), and InterruptIn(D2,D3) | 1 | 0 | OK | 0.08 |
| CC3220SF-GCC_ARM | CC3220SF | tests-concurrent-gpio | Concurrent testing of DIO(D9,D8), and InterruptIn(D3,D2) | 1 | 0 | OK | 0.1 |
+------------------+---------------+-----------------------+----------------------------------------------------------+--------+--------+--------+--------------------+
mbedgt: test case results: 12 OK
mbedgt: completed in 20.24 sec