DEV Community

Discussion on: CMake on SMT32 | Episode 7: unit tests

Collapse
 
danielsalyi profile image
Dániel Sályi

also, how to use ctests?

Collapse
 
pgradot profile image
Pierre Gradot

About embedded tests

It's not very easy to elaborate this topic without jumping into a particular case.

For my experience, I can tell that it is possible to use Catch2 (at least the 2.x branch) on a STM32 MCU. You need to have printf() working (probably through a UART connected to your computer with a USB-UART cable). You need to compile a program that is small enough to fit in the ROM of the MCU and provide the compiler with the necessary functions it needs to link the program. When you power-on the board, the tests will run and the output on the UART will be similar to the output you could get while running the tests directly on your computer.

About ctest

The unit tests running on the computer described in this article are of course usable with ctest. You just need to add these 2 lines to the CMakeLists.txt:

enable_testing()
add_test(NAME tests COMMAND tests)
Enter fullscreen mode Exit fullscreen mode

Then you can call ctest from the command-line in the build directory.

See the documentation cmake.org/cmake/help/book/masterin...