]> git.notmuchmail.org Git - notmuch/blob - test/T810-tsan.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T810-tsan.sh
1 #!/usr/bin/env bash
2
3 test_directory=$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null && pwd)
4
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.
8
9 . "$test_directory"/test-lib.sh || exit 1
10
11 if [ "${NOTMUCH_HAVE_TSAN-0}" != "1" ]; then
12     printf "Skipping due to missing TSan support\n"
13     test_done
14 fi
15
16 export TSAN_OPTIONS="suppressions=$test_directory/T810-tsan.suppressions"
17 TEST_CFLAGS="${TEST_CFLAGS:-} -fsanitize=thread"
18
19 cp -r ${MAIL_DIR} ${MAIL_DIR}-2
20
21 test_begin_subtest "create"
22 test_C ${MAIL_DIR} ${MAIL_DIR}-2 <<EOF
23 #include <notmuch-test.h>
24 #include <pthread.h>
25
26 void *thread (void *arg) {
27   char *mail_dir = arg;
28   /*
29    * Calls into notmuch_query_search_messages which was using the thread-unsafe
30    * Xapian::Query::MatchAll.
31    */
32   EXPECT0(notmuch_database_create (mail_dir, NULL));
33   return NULL;
34 }
35
36 int main (int argc, char **argv) {
37   pthread_t t1, t2;
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));
42   return 0;
43 }
44 EOF
45 cat <<EOF > EXPECTED
46 == stdout ==
47 == stderr ==
48 EOF
49 test_expect_equal_file EXPECTED OUTPUT
50
51 add_email_corpus
52 rm -r ${MAIL_DIR}-2
53 cp -r ${MAIL_DIR} ${MAIL_DIR}-2
54
55 test_begin_subtest "query"
56 test_C ${MAIL_DIR} ${MAIL_DIR}-2 <<EOF
57 #include <notmuch-test.h>
58 #include <pthread.h>
59
60 void *thread (void *arg) {
61   char *mail_dir = arg;
62   notmuch_database_t *db;
63   /*
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.
67    */
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));
74   return NULL;
75 }
76
77 int main (int argc, char **argv) {
78   pthread_t t1, t2;
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));
83   return 0;
84 }
85 EOF
86 cat <<EOF > EXPECTED
87 == stdout ==
88 == stderr ==
89 EOF
90 test_expect_equal_file EXPECTED OUTPUT
91
92 test_done