]> git.notmuchmail.org Git - notmuch/blobdiff - test/notmuch-test.h
test/count: replace use of gdb with a LD_PRELOAD shim
[notmuch] / test / notmuch-test.h
index 3a0e90a3ecf93200e5f38a854e2c57183dacda8b..ed713099b1d3b435024abae6d100d6c1ddf75a4d 100644 (file)
@@ -1,9 +1,17 @@
 #ifndef _NOTMUCH_TEST_H
 #define _NOTMUCH_TEST_H
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
 #include <assert.h>
+#include <dlfcn.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <sys/wait.h>
 #include <talloc.h>
 #include <unistd.h>
@@ -20,4 +28,23 @@ expect0 (int line, notmuch_status_t ret)
 }
 
 #define EXPECT0(v)  expect0 (__LINE__, v);
+
+inline static void *
+dlsym_next (const char *symbol)
+{
+    void *sym = dlsym (RTLD_NEXT, symbol);
+    char *str = dlerror ();
+
+    if (str != NULL) {
+       fprintf (stderr, "finding symbol '%s' failed: %s", symbol, str);
+       exit (77);
+    }
+    return sym;
+}
+
+#define WRAP_DLFUNC(_rtype, _func, _args)                               \
+    _rtype _func _args;                                                 \
+    _rtype _func _args {                                                \
+       static _rtype (*_func##_orig) _args = NULL;                         \
+       if (! _func##_orig ) *(void **) (&_func##_orig) = dlsym_next (#_func);
 #endif