Google裸机stm32单片机测试

Google test on bare-metal stm32 MCU

除了 MCU (STM32F1) 固件之外,我对项目的几乎所有部分都使用 Google 测试。现在我想直接在 MCU 上使用它进行测试,以确保我没有产生任何与机器相关的错误,这些错误可能会在 x64 上通过测试,但在 MCU 上会失败。 Google 测试需要 libpthread,显然 MCU 上没有。我使用复杂的 gcc 5.2.1 工具链,所以它 g++ 应该能够构建 google 测试。系统调用也被正确定义,因此测试输出应该被成功编译并打印到串行控制台。

是否可以在 Google 测试中禁用 libpthread 并为裸机微控制器构建它?有没有人有这样使用单元测试的经验?

来自 gtest 的文档:

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 不是构建 gtest 所必需的。您可以在构建 gtest 时通过 -DGTEST_HAS_PTHREAD=0 禁用它。

所以检查一下你的环境,看是否符合要求(尤其是regex.h)。