简体   繁体   English

为 STM32 单元测试存根 HAL 库

[英]Stubbing the HAL library for STM32 Unit tests

To get unit tests working for my STM32 project I am mocking the Hal library.为了让单元测试适用于我的 STM32 项目,我正在模拟 Hal 库。 So far we have managed to Mock it and create dummy files.到目前为止,我们已经成功地模拟了它并创建了虚拟文件。 However I am running into an issue.但是我遇到了一个问题。 At this point we have 3 .h files, one for #defines, one for functions and the other is a straight copy of a HAL file.此时我们有 3 个 .h 文件,一个用于 #defines,一个用于函数,另一个是 HAL 文件的直接副本。 The program seems to compile and is giving me linking errors.该程序似乎可以编译并给我链接错误。

The error it is giving is "Multiple definition of", but not one error.它给出的错误是“多重定义”,但不是一个错误。 Like roughly 200. It is giving an error on all the functions in hal_stub_functions.h It even seems to loop a couple of times.大概是 200。它在 hal_stub_functions.h 中的所有函数上都出错了它甚至似乎循环了几次。 We have checked all files.我们已经检查了所有文件。 None include the wrong files or each other.没有包含错误的文件或彼此。 All files contain If/Def/Endif.所有文件都包含 If/Def/Endif。 The 3 files do not include each other.这 3 个文件不包含彼此。 The functions file includes the #Defines file.函数文件包括#Defines 文件。 I have no idea where to start looking for this.我不知道从哪里开始寻找这个。 Tried the general stuff, as mentioned checking includes.尝试了一般的东西,如上所述检查包括。 Project settings are all correct.项目设置都正确。 If anybody has any help or ideas id greatly appreciate it.如果有人有任何帮助或想法,我将不胜感激。

EDIT: Think I may have found something weird.编辑:想我可能发现了一些奇怪的东西。 Image here Seems like Eclipse is finding every function twice.此处的图像似乎 Eclipse 正在两次查找每个函数。 On the same spot.在同一个地方。 How do i fix this?我该如何解决?

EDIT 2: I think the general problem is that the linker is somehow finding files twice.编辑 2:我认为一般的问题是链接器以某种方式查找文件两次。

Thanks in advance :)提前致谢 :)

Solution: Make all functions static.解决方案:将所有函数设为静态。 As multiple files were including the .h file they were constantly redefining the functions.由于多个文件包含 .h 文件,因此他们不断地重新定义函数。 Even tho #ifdef was applied.即使应用了#ifdef。 #pragma once did not help either. #pragma once 也没有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM