Skip to content

Running the Mbed Greentea Tests Locally

Jamie Smith edited this page Oct 27, 2024 · 12 revisions

This page will show you how to compile and run the Mbed OS Greentea tests on your local machine. Greentea tests are the tests which get loaded and run on a connected Mbed board, so this procedure will let you check how well Mbed OS actually works on a board you have.

Note: These instructions use the command line, but this can also be done using an IDE by opening the mbed-os folder as a project and adding the needed CMake options.

  1. Make sure the toolchain is set up, per this page.

  2. Connect the Mbed device to your machine, and find what serial port it uses (e.g. COM3 or /dev/ttyACM0). On Linux, this page can help you configure the tty device and permissions correctly.

    • If the Mbed board has Ethernet support, connect its Ethernet jack to a network that can communicate with the Internet and with your PC. The network must have DHCP enabled. If you do not make this connection, some networking tests may fail.
    • If the Mbed board has USB support, connect its USB port to a free USB port on your machine. On Windows, you will need to use Zadig to install drivers, see here. On Linux, you will need to install additional udev rules, see "Set up the USB device" here.
  3. Clone this repository and open a terminal there.

    • You can also use the mbed-os submodule of another project, if you have one handy
  4. Install the Python requirements (see Project Setup Command Line page). Also install the Python requirements in mbed-os/tools/requirements-ci-build.txt.

  5. Create a build dir and enter it:

mkdir build_<your target> && cd build_<your target>

(where <your target> is replaced by your Mbed target name, e.g. NUCLEO_F429ZI)

  1. Run CMake:
cmake .. -GNinja -DMBED_TARGET=<your target> -DCMAKE_BUILD_TYPE=Develop -DMBED_BUILD_GREENTEA_TESTS=ON -DMBED_GREENTEA_SERIAL_PORT=<your serial port> -DUPLOAD_METHOD=<your upload method> -DMBED_APP_JSON_PATH=../TESTS/configs/greentea_full.json5

Replace <your serial port> with the serial port you found in step 1. Replace <your upload method> with the upload method you wish to use. The CI runner is integrated with the upload method system, so whatever you select here will get used during the test run. Note: you can also pass other upload method related options in this command, such as setting the STM32CUBE_PROBE_SN to select a specific device.

Note: If you are testing a board with Wi-Fi support, you may also need to set additional variables (MBED_GREENTEA_WIFI_SECURE_SSID, MBED_GREENTEA_WIFI_SECURE_PASSWORD, and MBED_GREENTEA_WIFI_SECURE_PROTOCOL) to pass in your wifi network info. See here for details.

Note 2: If you are testing a board with Wi-Fi or Ethernet support, you will need to load the ctp server application onto a second board and connect that board to your Ethernet network. Otherwise, the mbed-connectivity-network-emac test will fail.

  1. Run the build:
ninja

If everything is set up correctly, you should see a bunch of Mbed OS tests get linked.

  1. Run the tests:
ctest . --output-on-failure

You should see a bunch of tests get executed on your hardware! This process normally takes 15-30 min. Note: It's normal to see tests show as skipped, this is because the test is trying to test something that doesn't exist on your MCU.

Note: Running a Specific Test

If you want to run one specific test instead of the entire test suite, you can use:

ctest -V -R <substring of test name>

The -V option causes CTest to print the test output in real time, and the -R option makes it only run tests matching the given filter.