0

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()?

adamm
  • 849
  • 1
  • 6
  • 17
  • Why do you want to include `foo.c` and `mock_foo.c` in your project at the same time? The basic idea of a mock is to replace the original module, i.e. to replace `foo.c` with `mock_foo.c`. That's why the identical function names make sense. – Blue May 20 '22 at 23:20
  • 1
    The build system I'm using sees both files. It's a common problem, you can check [this](https://blog.microjoe.org/2017/unit-tests-c-cmocka-coverage-cmake.html#system-call-mocking-with-wrap) for example. – adamm May 21 '22 at 08:04

1 Answers1

1

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.

Blue
  • 820
  • 4
  • 17