Sergey Sergey - 1 year ago 134
C++ Question

Google test on bare-metal stm32 MCU

I use Google test on almost all parts of my project except MCU (STM32F1) firmware. Now I want to use it for tests directly on MCU to ensure I didn't make any machine-dependent bugs, which may pass tests on x64, but fail on the MCU. Google test requires libpthread, which is obviously not present on the MCU. I use sophisticated gcc 5.2.1 toolchain, so it's

g++
should be able to build google test. System calls are also properly defined, so tests output should be successfully compiled and printed to serial console.

Is it possible to disable libpthread in Google test and build it for a bare-metal microcontroller? Does anyone have any experience in using unit-tests this way?

Answer Source

From gtest's document:

Linux Requirements

These are the base requirements to build and use Google Test from a source package (as described below):

GNU-compatible Make or gmake
POSIX-standard shell
POSIX(-2) Regular Expressions (regex.h)
A C++98-standard-compliant compiler

pthread is not mandatory to build gtest. You can disable it by -DGTEST_HAS_PTHREAD=0 when building gtest.

So check your environment and see if it meets the requirements (especially for regex.h).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download