3 test_directory=$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null && pwd)
5 test_description='run code with TSan enabled against the library'
6 # Note it is hard to ensure race conditions are deterministic so this
7 # only provides best effort detection.
9 . "$test_directory"/test-lib.sh || exit 1
11 if [ "${NOTMUCH_HAVE_TSAN-0}" != "1" ]; then
12 printf "Skipping due to missing TSan support\n"
16 export TSAN_OPTIONS="suppressions=$test_directory/T810-tsan.suppressions"
17 TEST_CFLAGS="${TEST_CFLAGS:-} -fsanitize=thread"
19 cp -r ${MAIL_DIR} ${MAIL_DIR}-2
21 test_begin_subtest "create"
22 test_C ${MAIL_DIR} ${MAIL_DIR}-2 <<EOF
23 #include <notmuch-test.h>
26 void *thread (void *arg) {
29 * Calls into notmuch_query_search_messages which was using the thread-unsafe
30 * Xapian::Query::MatchAll.
32 EXPECT0(notmuch_database_create (mail_dir, NULL));
36 int main (int argc, char **argv) {
38 EXPECT0(pthread_create (&t1, NULL, thread, argv[1]));
39 EXPECT0(pthread_create (&t2, NULL, thread, argv[2]));
40 EXPECT0(pthread_join (t1, NULL));
41 EXPECT0(pthread_join (t2, NULL));
49 test_expect_equal_file EXPECTED OUTPUT
53 cp -r ${MAIL_DIR} ${MAIL_DIR}-2
55 test_begin_subtest "query"
56 test_C ${MAIL_DIR} ${MAIL_DIR}-2 <<EOF
57 #include <notmuch-test.h>
60 void *thread (void *arg) {
62 notmuch_database_t *db;
64 * 'from' is NOTMUCH_FIELD_PROBABILISTIC | NOTMUCH_FIELD_PROCESSOR and an
65 * empty string gets us to RegexpFieldProcessor::operator which was using
66 * the tread-unsafe Xapian::Query::MatchAll.
68 EXPECT0(notmuch_database_open_with_config (mail_dir,
69 NOTMUCH_DATABASE_MODE_READ_ONLY,
70 NULL, NULL, &db, NULL));
71 notmuch_query_t *query = notmuch_query_create (db, "from:\"\"");
72 notmuch_messages_t *messages;
73 EXPECT0(notmuch_query_search_messages (query, &messages));
77 int main (int argc, char **argv) {
79 EXPECT0(pthread_create (&t1, NULL, thread, argv[1]));
80 EXPECT0(pthread_create (&t2, NULL, thread, argv[2]));
81 EXPECT0(pthread_join (t1, NULL));
82 EXPECT0(pthread_join (t2, NULL));
90 test_expect_equal_file EXPECTED OUTPUT