Compile-Time Function Call Interception for Testing in C/C++
Abstract
In C/C++, during the test development process we often have
to modify the public interface of a class to replace existing dependencies;
e.g. supplementary setter or constructor functions or extra template pa-
rameters are added for dependency injection. These solutions may have
serious detrimental effects on the code structure and sometimes on the
run-time performance as well. We introduce a new technique that makes
dependency replacement possible without the modification of the produc-
tion code, thus it provides an alternative way to add unit tests. Our new
compile-time instrumentation technique enables us to intercept function
calls and replace them in runtime. Contrary to existing function call in-
terception (FCI) methods, we instrument the call expression instead of
the callee, thus we can avoid the modification and recompilation of the
function in order to intercept the call. This has a clear advantage in case
of system libraries and third party shared libraries, thus it provides an
alternative way to automatize tests for legacy software. We created a pro-
totype implementation based on the LLVM compiler infrastructure which
is publicly available for testing.
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
When the article is accepted for publication, I, as the author and representative of the coauthors, hereby agree to transfer to Studia Universitatis Babes-Bolyai, Series Informatica, all rights, including those pertaining to electronic forms and transmissions, under existing copyright laws, except for the following, which the author specifically retain: the right to make further copies of all or part of the published article for my use in classroom teaching; the right to reuse all or part of this material in a review or in a textbook of which I am the author; the right to make copies of the published work for internal distribution within the institution that employs me.