-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a preamble to mocked function name #116
base: master
Are you sure you want to change the base?
Conversation
The change in this patch modifies fff macro generation script to support a CLI option --preamble <string> 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]>
I have not yet added unit-tests, would like to get it reviewed first before spending the time to add the tests. |
This looks good to me, but needs some documentation and tests. Thanks for the contribution! |
Update CMake file to generate "fff_preamble.h" using the cli argument "--preamble __wrap_" and add a test-case that invokes the generated fake function that is now named as "__wrap_voidfunc1()" and verifies the proper call_count gets incremented. Signed-off-by: Ramzi El-khater <[email protected]>
Signed-off-by: Ramzi El-khater <[email protected]>
Thanks, I have added a unit-test that verifies one macro, not sure if we need to verify all again since they are checked in the main test cases. Will work on documentation next. |
b526b38
to
2bf31d3
Compare
Signed-off-by: Ramzi El-khater <[email protected]>
2bf31d3
to
907fb63
Compare
I have added the documentation as well. Please let me know if anything further is needed. Thanks! |
Looks like the workflows have not run due to waiting on maintainer approval. |
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: