Compile-Time Function Call Interception for Testing in C/C++

  • G. Marton Faculty of Informatics, Eötvös Loránd University, Budapest, Hungary
  • Z. Porkolab Faculty of Informatics, Eötvös Loránd University, Budapest, Hungary

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.

Published
2018-06-19
How to Cite
MARTON, G.; PORKOLAB, Z.. Compile-Time Function Call Interception for Testing in C/C++. Studia Universitatis Babeș-Bolyai Informatica, [S.l.], v. 63, n. 1, p. 17-32, june 2018. ISSN 2065-9601. Available at: <https://www.cs.ubbcluj.ro/~studia-i/journal/journal/article/view/19>. Date accessed: 29 mar. 2024. doi: https://doi.org/10.24193/subbi.2018.1.02.
Section
Articles