Add __wrap prefix to mocked functions with Cmock

345 views Asked by At

I have generated mock_foo.h and mock_foo.c from my foo.h header using Ceedling. The problem is that in generated file there are function names the same as in 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.

Is it possible to add some option in project.yml in order to generate function which already have that prefix, ie. __wrap_foo_function()?

1

There are 1 answers

0
Blue On BEST ANSWER

CMock has currently no option to add a user-defined prefix (like __wrap) to function names. 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.

Issue #32 even proposed a patch but I guess this will not be easily applicable anymore to the current code basis.

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. With such a modified header CMock would generate a mock_foo.c with the appropriate function names.

For Python exists the pycparser project which might be helpful for this task. Especially the func_defs.py example looks like a promising starting point.