New testpoint mechanism to instrument binaries for testing
authorChristian Babeux <christian.babeux@efficios.com>
Fri, 14 Sep 2012 19:00:30 +0000 (15:00 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Tue, 2 Oct 2012 19:32:50 +0000 (15:32 -0400)
commit6242251b39f531a2485b758edcb455e220267fdd
tree3fdadfe9e0e9ab35415f0600c106596a2274d10f
parentdb8870edf473e2a2f69e488375d32405ea324017
New testpoint mechanism to instrument binaries for testing

This commit introduce two new macros: TESTPOINT_DECL(name) and
testpoint(name).

Here a quick example that show how to use the testpoint mechanism:

file: main.c

/* Testpoint declaration */
TESTPOINT_DECL(interesting_function)

void interesting_function(void)
{
        testpoint(interesting_function);
        /* Some processing that can fail */
        ...
}

int main(int argc, char *argv[])
{
        interesting_function();
        ...
        printf("End");
}

file: testpoint.c
void __testpoint_interesting_function(void)
{
        printf("In testpoint of interesting function!");
}

Compile:
gcc -o test main.c
gcc -fPIC -shared -o testpoint.so testpoint.c

Run:
> ./test
  End
> export LTTNG_TESTPOINT_ENABLE=1
> LD_PRELOAD=testpoint.so ./test
  In testpoint of interesting function!
  End
> export LTTNG_TESTPOINT_ENABLE=0
> LD_PRELOAD=testpoint.so ./test
  End

The testpoint mechanism is triggered via the preloading of a shared
object containing the appropriate testpoint symbols and by setting the
LTTNG_TESTPOINT_ENABLE environment variable.

The check on this environment variable is done on the application
startup with the help of a constructor (lttng_testpoint_check) which
toggle a global state variable indicating whether or not the testpoints
should be activated.

When enabled, the testpoint() macro calls an underlying wrapper specific
to the testpoint and simply try to lookup the testpoint symbol via a
dlsym() call.

When disabled, the testpoint() call will only incur an additionnal test
per testpoint on a global variable. This performance 'hit' should be
acceptable for production use.

The testpoint mechanism should be *always on*. It can be explicitly
disabled via CFLAGS="-DNTESTPOINT" in a way similar to NDEBUG and
assert().

Please refer to 0005-testpoint-mechanism.txt for more information.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
configure.ac
src/common/Makefile.am
src/common/testpoint/Makefile.am [new file with mode: 0644]
src/common/testpoint/testpoint.c [new file with mode: 0644]
src/common/testpoint/testpoint.h [new file with mode: 0644]
This page took 0.025947 seconds and 4 git commands to generate.