mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 18:38:08 +01:00
test/count: replace use of gdb with a LD_PRELOAD shim
There is a certain amount of boilerplate to pass the call on the original function, so abstract it out as a C preprocessor macro, plus some extra includes in notmuch-test.h
This commit is contained in:
parent
1643c0459a
commit
9397e7e8eb
2 changed files with 42 additions and 12 deletions
|
@ -102,22 +102,25 @@ output=$(sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' OUTPUT)
|
||||||
test_expect_equal "${output}" "A Xapian exception occurred opening database"
|
test_expect_equal "${output}" "A Xapian exception occurred opening database"
|
||||||
restore_database
|
restore_database
|
||||||
|
|
||||||
cat <<EOF > count-files.gdb
|
make_shim qsm-shim<<EOF
|
||||||
set breakpoint pending on
|
#include <notmuch-test.h>
|
||||||
set logging file count-files-gdb.log
|
|
||||||
set logging on
|
WRAP_DLFUNC (notmuch_status_t, notmuch_query_search_messages, (notmuch_query_t *query, notmuch_messages_t **messages))
|
||||||
break count_files
|
|
||||||
commands
|
/* XXX WARNING THIS CORRUPTS THE DATABASE */
|
||||||
shell cp /dev/null ${MAIL_DIR}/.notmuch/xapian/postlist.*
|
int fd = open ("target_postlist", O_WRONLY|O_TRUNC);
|
||||||
continue
|
if (fd < 0)
|
||||||
end
|
exit (8);
|
||||||
run
|
close (fd);
|
||||||
|
|
||||||
|
return notmuch_query_search_messages_orig(query, messages);
|
||||||
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
backup_database
|
backup_database
|
||||||
test_begin_subtest "error message from query_search_messages"
|
test_begin_subtest "error message from query_search_messages"
|
||||||
${TEST_GDB} --batch-silent --return-child-result -x count-files.gdb \
|
ln -s ${MAIL_DIR}/.notmuch/xapian/postlist.* target_postlist
|
||||||
--args notmuch count --output=files '*' 2>OUTPUT 1>/dev/null
|
notmuch_with_shim qsm-shim count --output=files '*' 2>OUTPUT 1>/dev/null
|
||||||
cat <<EOF > EXPECTED
|
cat <<EOF > EXPECTED
|
||||||
notmuch count: A Xapian exception occurred
|
notmuch count: A Xapian exception occurred
|
||||||
A Xapian exception occurred performing query
|
A Xapian exception occurred performing query
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
#ifndef _NOTMUCH_TEST_H
|
#ifndef _NOTMUCH_TEST_H
|
||||||
#define _NOTMUCH_TEST_H
|
#define _NOTMUCH_TEST_H
|
||||||
|
#ifndef _GNU_SOURCE
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <talloc.h>
|
#include <talloc.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -20,4 +28,23 @@ expect0 (int line, notmuch_status_t ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EXPECT0(v) expect0 (__LINE__, v);
|
#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
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue