From: Christian Babeux Date: Fri, 14 Sep 2012 19:00:30 +0000 (-0400) Subject: New testpoint mechanism to instrument binaries for testing X-Git-Tag: v2.1.0-rc5~39 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=6242251b39f531a2485b758edcb455e220267fdd;hp=6242251b39f531a2485b758edcb455e220267fdd 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 Signed-off-by: David Goulet ---