C++ Testing using spies and fakes for isolation and simulation

Related tags

Testing elfspy
Overview

ELFspy is a library for linux for writing tests using fakes and spies in C++. For very large call graphs, the testing of the higher nodes can be difficult due to the sum of dependencies of lower nodes e.g. databases, network connections etc. Adding fakes and spies to the callees of a function allows it to be tested in isolation without the inherited dependencies.

ELFspy works by allowing code to externally modify an existing implementation/library of a program. This is achieved by changing function addresses in the global offset tables of the running program, so that these are redirected to a different function created by ELFspy. This allows new functions to be interjected between the caller and the callee to spy on the arguments and return value. In addition the original function can be replaced with a simulation (fake) of the original. The code under test needs no changes and is unaware of the additional calls that are being made in between a caller and a callee.

Call graph before change

External code:

auto add_spy = SPY(&add);

Call graph after change(the code does not change, but the runtime execution does)

This technique relies on code being compiled as position independent code and uses the Executable and Linking Format(ELF) information found in the executable and its shared libraries to find the global offset table entries and modify them.

To see how ELFspy can be used start by reading this example

You might also like...
UT: C++20 μ(micro)/Unit Testing Framework
UT: C++20 μ(micro)/Unit Testing Framework

"If you liked it then you "should have put a"_test on it", Beyonce rule UT / μt | Motivation | Quick Start | Overview | Tutorial | Examples | User Gui

A micro unit-testing library for C/C++

µ-test A micro unit testing framework for C/C++ to get you up and running with unit-testing ASAP (even without libc). Usage Simply include the C and h

A tool to help in testing client/server robustness in the presence of malformed data.

Tool to assist in testing robustness of network-attached services in the presence of malformed data.

Bayesian A/B testing calculations for C++

BayesTest C++ Bayesian A/B testing calculations for C++ Based on this post by Evan Miller Also available in Rust Installation Include the header in yo

5G core testing solution

CoreScope CoreScope combines gNodeB and UE components without any radio transmission. It behaves like a UE and exposes an IP interface, but to the cor

A complete unit testing framework in a header

liblittletest A complete unit testing framework in a header liblittletest is an easy to use all-in-an-header testing framework; all you have to do in

Simple C testing framework

MrTest Simple C testing framework Usage Copy the mrtest.c and mrtest.h file into your project. In order to use the mrtest main: create a .c file that

Testing memleaks with /usr/share/bcc/tools/memleak

Testing memleaks with /usr/share/bcc/tools/memleak

xtest is a C++ testing framework inspired by googletest.
xtest is a C++ testing framework inspired by googletest.

xtest C++ testing framework inspired by googletest Explore the docs » Wiki · Report Bug · Request Feature Contents xtest Commence Prerequisites Ubuntu

Comments
  • Faking read, write and open

    Faking read, write and open

    Hi, I've made some examples that fake unix functions successfully (i.e. socket, close or pipe). However, when I try to fake the read() and write() functions included in <unistd.h>, the fake functions are never executed, but just the original ones.

    Regarding open(), the problem arises at compilation-time because of the signature of the function:

    int open(const char *, int flags, ...);

    It seems that the variable arguments in functions are not allowed in this versión of elfspy. Definitely it would be nice to support this kind of signatures.

    Best regards and thanks for this fantastic library, Jesus

    opened by jmcruz-uma 1
  • Fakes with virtual inheritance do not work

    Fakes with virtual inheritance do not work

    example7.cpp contains code to test for this. Currently the virtual methods from the virtual base class cannot be found and also it looks like the wrong virtual methods are found for the remaining methods of a class with a virtual base class.

    opened by mollismerx 0
Owner
Robin Nicholson
Robin Nicholson
C++ Unit Testing Easier: A Header-only C++ unit testing framework

CUTE C++ Unit Testing Easier: A Header-only C++ unit testing framework usually available as part of the Cevelop C++ IDE (http://cevelop.com) Dependenc

Peter Sommerlad 35 Aug 31, 2022
Googletest - Google Testing and Mocking Framework

GoogleTest OSS Builds Status Announcements Release 1.10.x Release 1.10.x is now available. Coming Soon Post 1.10.x googletest will follow Abseil Live

Google 27.6k Sep 24, 2022
Practical mutation testing tool for C and C++

Mull Mull is a tool for Mutation Testing based on LLVM/Clang with a strong focus on C and C++ languages. For installation and usage please refer to th

Mull Project 641 Sep 15, 2022
Modern c++17 unit testing framework on Microsoft Windows, Apple macOS, Linux, iOS and android.

tunit Modern c++17 unit testing framework on Windows, macOS, Linux, iOS and android. Continuous Integration build status Operating system Status Windo

Gammasoft 8 Apr 5, 2022
testing joystick under Linux environment, support monitoring disconnection state and auto recovery mode

qjoystick This qjoystick class is rewritten based on the library: https://github.com/drewnoakes/joystick. Please look at this library if you want to s

ibov 1 Oct 30, 2021
Header-only C++11 library for property-based testing.

autocheck Header-only C++11 library for QuickCheck (and later, SmallCheck) testing. Please consult the wiki for documentation. Install conan remote ad

John Freeman 119 Apr 18, 2022
The fastest feature-rich C++11/14/17/20 single-header testing framework

master branch Windows All dev branch Windows All doctest is a new C++ testing framework but is by far the fastest both in compile times (by orders of

Viktor Kirilov 4.2k Sep 26, 2022
C++ xUnit-like testing framework without macros

tst C++ testing framework. Installation, documentation, tutorials See WiKi. Features xUnit-like concepts minimal use of preprocessor macros declarativ

cppfw 8 Jan 24, 2022
proftest is a C application for testing the quality of different operating system APIs for profiling.

proftest is a C application for testing the quality of different operating system APIs for profiling.

Felix Geisendörfer 5 Jul 23, 2021
c++ testing framework

iutest iutest - iris unit test framework Welcome to the iutest iutest is framework for writing C++ tests. Features An XUnit test framework. Header onl

srz_zumix 60 Sep 12, 2022