简体   繁体   English

使用 Cmock 为模拟函数添加 __wrap 前缀

[英]Add __wrap prefix to mocked functions with Cmock

I have generated mock_foo.h and mock_foo.c from my foo.h header using Ceedling.我使用mock_foo.c从我的foo.h标头生成mock_foo.h和 mock_foo.c。 The problem is that in generated file there are function names the same as in foo.c .问题是在生成的文件中有与foo.c相同的函数名。 For example, foo_function() is now in both foo.c and mock_foo.c , and I have to manually add __wrap prefix so that linker doesn't complain about multiple definitions.例如, foo_function()现在在foo.cmock_foo.c中,我必须手动添加__wrap前缀,这样链接器就不会抱怨多个定义。

Is it possible to add some option in project.yml in order to generate function which already have that prefix, ie.是否可以在project.yml中添加一些选项以生成已经具有该前缀的函数,即。 __wrap_foo_function() ? __wrap_foo_function()

CMock has currently no option to add a user-defined prefix (like __wrap ) to function names. CMock 目前没有选项可以将用户定义的前缀(如__wrap )添加到函数名称。 Such a feature has been discussed twice back in 2014 (see Issue #32 ) and 2017 ( Issue #137 ), but unfortunately the discussion dried out too early to add the feature to the project.早在 2014 年(参见Issue #32 )和 2017 年( Issue #137 )就已经讨论过两次这样的功能,但不幸的是,讨论过早结束,无法将该功能添加到项目中。

Issue #32 even proposed a patch but I guess this will not be easily applicable anymore to the current code basis.问题 #32甚至提出了一个补丁,但我想这将不再适用于当前的代码基础。

A possible workaround might be to write a script that generates a modified version of the modules header file foo.h by adding the __wrap prefix to all function declarations within the file.一种可能的解决方法可能是编写一个脚本,通过将__wrap前缀添加到文件中的所有函数声明来生成模块头文件foo.h的修改版本。 With such a modified header CMock would generate a mock_foo.c with the appropriate function names.有了这样一个修改过的头文件,CMock 会生成一个带有适当函数名的mock_foo.c

For Python exists the pycparser project which might be helpful for this task.对于 Python,存在pycparser项目,它可能对这项任务有帮助。 Especially the func_defs.py example looks like a promising starting point.尤其是func_defs.py示例看起来是一个很有希望的起点。

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

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