Adding a preamble to mocked function name #116
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The change in this patch modifies fff macro generation script to support a CLI option
--preamble that can be used to set a preamble for generated mock function names.
On some embedded systems if we want to perform testing with HW in the loop, there are
system functions or driver functions that cannot be mocked safely. For example
the SW running on a micro-controller may need to maintain communication with another
subsystem, replacing the functions that do this with mocks will put the system in a bad state.
To be able to mock such functions and keep the system in a good state we prepend a preamble to
the mock function name and inside the mock function do intrumentation and then call the real
function to keep the system in a good state. We can leverage the 'custom_fake' field created by
fff to call the real function.
For example, we can name the mock of function XYZ() as __wrap_XYZ() and use the GNU linker option
-Wl,--wrap XYZ to re-route all references to XYZ() to __wrap_XYZ() (see
https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_3.html). Now, inside
__wrap_XYZ() we can invoke XYZ() in addition to instrumentation. We can leverage the
'custom_fake' field created by fff to call the real version of XYZ(), this will be named as
__real_XYZ(). Note, this is just an example the same can be acheived by custom tooling and not
using GNU linkers --wrap flag.
Signed-off-by: Ramzi El-khater [email protected]
Thank you for your contribution.
Before submitting this PR, please make sure: