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.
Transfer of copyright agreement: When the article is accepted for publication, I, as the author and the 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 authors specifically retain: the authors can use the material however they want as long as it fits the NC ND terms of the license. The authors have all rights for reuse according to the below license.