Skip to content

Commit 80fe7c2

Browse files
committed
CMake: Update README.md with CTest/greentea instructions
The steps for building and running a greentea test have changed since 40154ee. This commit updates the README with the current instructions for building and running greentea tests using CMake/Ninja/CTest.
1 parent df00ed4 commit 80fe7c2

File tree

1 file changed

+45
-15
lines changed

1 file changed

+45
-15
lines changed

tools/cmake/README.md

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,57 @@ If you're running CMake directly, you may need to pass it in yourself as follows
8282
cmake -S <source-dir> -B <build-dir> -DCMAKE_BUILD_TYPE=debug
8383
```
8484
85-
## How to build a greentea test
86-
87-
Install prerequisites suggested in the previous section and follow the below steps to build:
88-
* Set your current directory to the test suite directory
89-
90-
* Run the following command for the configuration CMake module to be generated
91-
```
92-
mbedtools configure -t <TOOLCHAIN> -m <MBED_TARGET> --mbed-os-path /path/to/mbed-os
93-
```
94-
* Build the test binary with the full profile
85+
## How to build and run greentea tests
86+
87+
### Set up
88+
Install the [mbed-hosts-tests](https://pypi.org/project/mbed-host-tests/) python package.
89+
90+
Also install the prerequisites suggested in the previous section.
91+
92+
### Configuring the build system
93+
1. Set your current directory to the mbed-os root.
94+
1. Connect your target and detect it using `mbed-tools`
95+
```
96+
mbedtools detect
97+
```
98+
_Make a note of the mount point and serial port. We will need to pass them to CMake in a later step._
99+
100+
1. Generate an mbed_config.cmake configuration file for your target using `mbed-tools`
101+
```
102+
mbedtools configure -t <TOOLCHAIN> -m <MBED_TARGET> --mbed-os-path . --output-dir __build
103+
```
104+
1. Generate the build system with CMake, configuring it to build greentea tests.
105+
Here you will pass the serial port and mount point you noted in an earlier
106+
step
107+
```
108+
cmake -S . -B __build -G Ninja -DBUILD_GREENTEA_TESTS=ON -DCMAKE_CTEST_ARGUMENTS="--output-on-failure;-V" -DMBED_HTRUN_ARGUMENTS="-p;<serial-port-from-detect>;-d;<mount-point-from-detect>"
109+
```
110+
The `MBED_HTRUN_ARGUMENTS` argument is a semicolon separated list of arguments
111+
to forward to `mbedhtrun`. You can pass any of the optional flags you would
112+
usually pass to `mbedhtrun` by adding them to this list.
113+
114+
The `CMAKE_CTEST_ARGUMENTS` argument is a semicolon separated list of
115+
arguments to forward to CTest, for more details see [the CMake documentation.](https://cmake.org/cmake/help/latest/variable/CMAKE_CTEST_ARGUMENTS.html)
116+
117+
If you want to build with the "bare-metal" profile, append
118+
`-DMBED_GREENTEA_TEST_BAREMETAL=ON` to the above command.
119+
120+
### Build and run tests
121+
To build and run the tests run the following commands
95122
```
96-
cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja && cmake --build .
123+
cmake --build __build && cmake --build __build --target test
97124
```
98-
Or build the test binary with the baremetal profile
125+
Alternatively you can run ctest directly
99126
```
100-
cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja -DMBED_GREENTEA_TEST_BAREMETAL=ON && cmake --build .
127+
cmake --build __build
128+
cd __build
129+
ctest -V
101130
```
131+
This will build the tests and run them using `mbedhtrun` to communicate with the target.
132+
For more information on `ctest` and the options it offers, see [the ctest documentation.](https://cmake.org/cmake/help/latest/manual/ctest.1.html)
102133
103134
Notes:
104-
* These steps will change when `mbedtools` implements a sub-command to invoke Greentea tests
105-
* Some Greentea tests require specific application configuration files in order to build and run successfully. For example, the `connectivity/mbedtls/tests/TESTS/mbedtls/sanity` test requires the configuration file found at `TESTs/configs/experimental.json`.
135+
* Some Greentea tests require specific application configuration files in order to build and run successfully. For example, the `connectivity/mbedtls/tests/TESTS/mbedtls/sanity` test requires the configuration file found at `TESTs/configs/experimental.json`. The config should be passed to `mbed-tools configure` using the `--app-config` argument.
106136
107137
## Naming convention
108138

0 commit comments

Comments
 (0)