unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Reduce test suite reliance on gdb
@ 2021-10-25  1:15 David Bremner
  2021-10-25  1:15 ` [PATCH 1/2] test/count: replace use of gdb with a LD_PRELOAD shim David Bremner
  2021-10-25  1:15 ` [PATCH 2/2] test/new: replace use of gdb in vanishing file test David Bremner
  0 siblings, 2 replies; 10+ messages in thread
From: David Bremner @ 2021-10-25  1:15 UTC (permalink / raw)
  To: notmuch

gdb is sometimes a problem for the test suite, either failing
mysteriously in some environments or just being unavailable for
several architectures.  After this series, T380-atomicity is the only
remaining use of gdb in the test suite. In principle that should be
doable with the same approach, although I think this means essentially
translating atomicity.py into C, which might be a bit tedious.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/2] test/count: replace use of gdb with a LD_PRELOAD shim
  2021-10-25  1:15 Reduce test suite reliance on gdb David Bremner
@ 2021-10-25  1:15 ` David Bremner
  2021-10-25 19:04   ` Tomi Ollila
  2021-10-25  1:15 ` [PATCH 2/2] test/new: replace use of gdb in vanishing file test David Bremner
  1 sibling, 1 reply; 10+ messages in thread
From: David Bremner @ 2021-10-25  1:15 UTC (permalink / raw)
  To: notmuch

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
---
 test/T060-count.sh  | 29 +++++++++++++++++------------
 test/notmuch-test.h | 22 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/test/T060-count.sh b/test/T060-count.sh
index 6ad80df9..acf51d88 100755
--- a/test/T060-count.sh
+++ b/test/T060-count.sh
@@ -102,22 +102,27 @@ output=$(sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' OUTPUT)
 test_expect_equal "${output}" "A Xapian exception occurred opening database"
 restore_database
 
-cat <<EOF > count-files.gdb
-set breakpoint pending on
-set logging file count-files-gdb.log
-set logging on
-break count_files
-commands
-shell cp /dev/null ${MAIL_DIR}/.notmuch/xapian/postlist.*
-continue
-end
-run
+make_shim qsm-shim<<EOF
+#include <notmuch-test.h>
+notmuch_status_t
+notmuch_query_search_messages (notmuch_query_t *query, notmuch_messages_t **messages) {
+  static notmuch_status_t (*orig_notmuch_query_search_messages)
+	(notmuch_query_t *query, notmuch_messages_t **messages) = NULL;
+  TEST_SAVE_ORIG(notmuch_query_search_messages);
+
+  /* XXX WARNING THIS CORRUPTS THE DATABASE */
+  int fd = open("target_postlist",O_WRONLY|O_TRUNC);
+  if (fd < 0)
+    exit (8);
+
+  return orig_notmuch_query_search_messages(query, messages);
+}
 EOF
 
 backup_database
 test_begin_subtest "error message from query_search_messages"
-${TEST_GDB} --batch-silent --return-child-result -x count-files.gdb \
-    --args notmuch count --output=files '*' 2>OUTPUT 1>/dev/null
+ln -s ${MAIL_DIR}/.notmuch/xapian/postlist.* target_postlist
+notmuch_with_shim qsm-shim count --output=files '*' 2>OUTPUT 1>/dev/null
 cat <<EOF > EXPECTED
 notmuch count: A Xapian exception occurred
 A Xapian exception occurred performing query
diff --git a/test/notmuch-test.h b/test/notmuch-test.h
index 34dbb8e0..8613a299 100644
--- a/test/notmuch-test.h
+++ b/test/notmuch-test.h
@@ -3,6 +3,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <notmuch.h>
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 inline static void
 expect0 (int line, notmuch_status_t ret)
@@ -14,4 +18,22 @@ expect0 (int line, notmuch_status_t ret)
 }
 
 #define EXPECT0(v)  expect0 (__LINE__, v);
+
+#define TEST_SAVE_ORIG(func) \
+  if (! orig_##func) { \
+    void *handle; \
+    char *error; \
+    handle = dlopen("libnotmuch.so", RTLD_LAZY); \
+    if (! handle) { \
+      fputs(dlerror(), stderr); \
+      exit(1); \
+    } \
+    orig_##func = dlsym(handle, #func); \
+    if ((error = dlerror()) != NULL) { \
+      fprintf(stderr, "%s\n", error); \
+      exit(1); \
+    } \
+  }
+
+
 #endif
-- 
2.33.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] test/new: replace use of gdb in vanishing file test
  2021-10-25  1:15 Reduce test suite reliance on gdb David Bremner
  2021-10-25  1:15 ` [PATCH 1/2] test/count: replace use of gdb with a LD_PRELOAD shim David Bremner
@ 2021-10-25  1:15 ` David Bremner
  2021-10-25 19:14   ` Tomi Ollila
  1 sibling, 1 reply; 10+ messages in thread
From: David Bremner @ 2021-10-25  1:15 UTC (permalink / raw)
  To: notmuch

Because the file to be removed has a predictable name, we can hard
code it in the generated shim.
---
 test/T050-new.sh    | 44 ++++++++++++++++++++++++--------------------
 test/notmuch-test.h |  1 +
 2 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/test/T050-new.sh b/test/T050-new.sh
index 1141c1e3..5a03998b 100755
--- a/test/T050-new.sh
+++ b/test/T050-new.sh
@@ -368,31 +368,35 @@ chmod u+w ${MAIL_DIR}/.notmuch/xapian/*.*
 test_expect_equal "$output" "A Xapian exception occurred opening database"
 
 
+make_shim dif-shim<<EOF
+#include <notmuch-test.h>
+notmuch_status_t
+notmuch_database_index_file (notmuch_database_t *database,
+			     const char *filename,
+			     notmuch_indexopts_t *indexopts,
+			     notmuch_message_t **message)
+{
+  static notmuch_status_t (*orig_notmuch_database_index_file)
+    (notmuch_database_t *database,
+     const char *filename,
+     notmuch_indexopts_t *indexopts,
+     notmuch_message_t **message) = NULL;
+  TEST_SAVE_ORIG(notmuch_database_index_file);
+
+  if (unlink("${MAIL_DIR}/vanish")) {
+     fprintf(stderr, "unlink failed\n");
+     exit(42);
+  }
+  return orig_notmuch_database_index_file(database, filename, indexopts, message);
+}
+EOF
+
 test_begin_subtest "Handle files vanishing between scandir and add_file"
 
 # A file for scandir to find. It won't get indexed, so can be empty.
 touch ${MAIL_DIR}/vanish
-
-# Breakpoint to remove the file before indexing
-cat <<EOF > notmuch-new-vanish.gdb
-set breakpoint pending on
-set logging file notmuch-new-vanish-gdb.log
-set logging on
-break notmuch_database_index_file
-commands
-shell rm -f ${MAIL_DIR}/vanish
-continue
-end
-run
-EOF
-
-${TEST_GDB} --batch-silent --return-child-result -x notmuch-new-vanish.gdb \
-    --args notmuch new 2>OUTPUT 1>/dev/null
+notmuch_with_shim dif-shim new 2>OUTPUT 1>/dev/null
 echo "exit status: $?" >> OUTPUT
-
-# Clean up the file in case gdb isn't available.
-rm -f ${MAIL_DIR}/vanish
-
 cat <<EOF > EXPECTED
 Unexpected error with file ${MAIL_DIR}/vanish
 add_file: Something went wrong trying to read or write a file
diff --git a/test/notmuch-test.h b/test/notmuch-test.h
index 8613a299..94348d69 100644
--- a/test/notmuch-test.h
+++ b/test/notmuch-test.h
@@ -7,6 +7,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <unistd.h>
 
 inline static void
 expect0 (int line, notmuch_status_t ret)
-- 
2.33.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] test/count: replace use of gdb with a LD_PRELOAD shim
  2021-10-25  1:15 ` [PATCH 1/2] test/count: replace use of gdb with a LD_PRELOAD shim David Bremner
@ 2021-10-25 19:04   ` Tomi Ollila
  0 siblings, 0 replies; 10+ messages in thread
From: Tomi Ollila @ 2021-10-25 19:04 UTC (permalink / raw)
  To: David Bremner, notmuch

On Sun, Oct 24 2021, David Bremner wrote:

> 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

Looks like good progress -- some comments...

> ---
>  test/T060-count.sh  | 29 +++++++++++++++++------------
>  test/notmuch-test.h | 22 ++++++++++++++++++++++
>  2 files changed, 39 insertions(+), 12 deletions(-)
>
> diff --git a/test/T060-count.sh b/test/T060-count.sh
> index 6ad80df9..acf51d88 100755
> --- a/test/T060-count.sh
> +++ b/test/T060-count.sh
> @@ -102,22 +102,27 @@ output=$(sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' OUTPUT)
>  test_expect_equal "${output}" "A Xapian exception occurred opening database"
>  restore_database
>  
> -cat <<EOF > count-files.gdb
> -set breakpoint pending on
> -set logging file count-files-gdb.log
> -set logging on
> -break count_files
> -commands
> -shell cp /dev/null ${MAIL_DIR}/.notmuch/xapian/postlist.*
> -continue
> -end
> -run
> +make_shim qsm-shim<<EOF
> +#include <notmuch-test.h>
> +notmuch_status_t
> +notmuch_query_search_messages (notmuch_query_t *query, notmuch_messages_t **messages) {
> +  static notmuch_status_t (*orig_notmuch_query_search_messages)
> +	(notmuch_query_t *query, notmuch_messages_t **messages) = NULL;
> +  TEST_SAVE_ORIG(notmuch_query_search_messages);

The C preprocessor macro could do both of the lines above, deduplicating
orig_notmuch_query_search_messages and notmuch_query_search_messages to
one, but perhaps this way is clearer...(?)

> +
> +  /* XXX WARNING THIS CORRUPTS THE DATABASE */
> +  int fd = open("target_postlist",O_WRONLY|O_TRUNC);
missing space after ,

> +  if (fd < 0)
> +    exit (8);

close(fd) ?

> +
> +  return orig_notmuch_query_search_messages(query, messages);
> +}
>  EOF
>  
>  backup_database
>  test_begin_subtest "error message from query_search_messages"
> -${TEST_GDB} --batch-silent --return-child-result -x count-files.gdb \
> -    --args notmuch count --output=files '*' 2>OUTPUT 1>/dev/null
> +ln -s ${MAIL_DIR}/.notmuch/xapian/postlist.* target_postlist
> +notmuch_with_shim qsm-shim count --output=files '*' 2>OUTPUT 1>/dev/null
>  cat <<EOF > EXPECTED
>  notmuch count: A Xapian exception occurred
>  A Xapian exception occurred performing query
> diff --git a/test/notmuch-test.h b/test/notmuch-test.h
> index 34dbb8e0..8613a299 100644
> --- a/test/notmuch-test.h
> +++ b/test/notmuch-test.h
> @@ -3,6 +3,10 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <notmuch.h>
> +#include <dlfcn.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
>  
>  inline static void
>  expect0 (int line, notmuch_status_t ret)
> @@ -14,4 +18,22 @@ expect0 (int line, notmuch_status_t ret)
>  }
>  
>  #define EXPECT0(v)  expect0 (__LINE__, v);
> +
> +#define TEST_SAVE_ORIG(func) \
> +  if (! orig_##func) { \
> +    void *handle; \
> +    char *error; \
> +    handle = dlopen("libnotmuch.so", RTLD_LAZY); \

could have void *handle = dlopen... to reduce one macro line

> +    if (! handle) { \
> +      fputs(dlerror(), stderr); \
> +      exit(1); \
> +    } \
> +    orig_##func = dlsym(handle, #func); \
> +    if ((error = dlerror()) != NULL) { \
> +      fprintf(stderr, "%s\n", error); \
> +      exit(1); \
> +    } \
> +  }
> +
> +
>  #endif
> -- 
> 2.33.0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] test/new: replace use of gdb in vanishing file test
  2021-10-25  1:15 ` [PATCH 2/2] test/new: replace use of gdb in vanishing file test David Bremner
@ 2021-10-25 19:14   ` Tomi Ollila
  2021-10-28 13:46     ` [PATCH v2 1/3] test: move system includes to notmuch-test.h David Bremner
  0 siblings, 1 reply; 10+ messages in thread
From: Tomi Ollila @ 2021-10-25 19:14 UTC (permalink / raw)
  To: David Bremner, notmuch

On Sun, Oct 24 2021, David Bremner wrote:

> Because the file to be removed has a predictable name, we can hard
> code it in the generated shim.

I am not sure about the message above -- the file name is as predictable
as it was before -- and the shim code is created dynamically, with same
amout of flexibility as it was w/ the gdb script

Anyway I ignore if the same message appears in style-fixed email
(see below)...

Tomi

> ---
>  test/T050-new.sh    | 44 ++++++++++++++++++++++++--------------------
>  test/notmuch-test.h |  1 +
>  2 files changed, 25 insertions(+), 20 deletions(-)
>
> diff --git a/test/T050-new.sh b/test/T050-new.sh
> index 1141c1e3..5a03998b 100755
> --- a/test/T050-new.sh
> +++ b/test/T050-new.sh
> @@ -368,31 +368,35 @@ chmod u+w ${MAIL_DIR}/.notmuch/xapian/*.*
>  test_expect_equal "$output" "A Xapian exception occurred opening database"
>  
>  
> +make_shim dif-shim<<EOF
> +#include <notmuch-test.h>
> +notmuch_status_t
> +notmuch_database_index_file (notmuch_database_t *database,
> +			     const char *filename,
> +			     notmuch_indexopts_t *indexopts,
> +			     notmuch_message_t **message)
> +{
> +  static notmuch_status_t (*orig_notmuch_database_index_file)
> +    (notmuch_database_t *database,
> +     const char *filename,
> +     notmuch_indexopts_t *indexopts,
> +     notmuch_message_t **message) = NULL;
> +  TEST_SAVE_ORIG(notmuch_database_index_file);
> +
> +  if (unlink("${MAIL_DIR}/vanish")) {
> +     fprintf(stderr, "unlink failed\n");
> +     exit(42);

style not 'exit (42)' like in sources, and in previous change -- mostly
in previous change, there was also at least one fn() use, which I failed
to comment... anyway, asking for consistent style.

> +  }
> +  return orig_notmuch_database_index_file(database, filename, indexopts, message);
> +}
> +EOF
> +
>  test_begin_subtest "Handle files vanishing between scandir and add_file"
>  
>  # A file for scandir to find. It won't get indexed, so can be empty.
>  touch ${MAIL_DIR}/vanish
> -
> -# Breakpoint to remove the file before indexing
> -cat <<EOF > notmuch-new-vanish.gdb
> -set breakpoint pending on
> -set logging file notmuch-new-vanish-gdb.log
> -set logging on
> -break notmuch_database_index_file
> -commands
> -shell rm -f ${MAIL_DIR}/vanish
> -continue
> -end
> -run
> -EOF
> -
> -${TEST_GDB} --batch-silent --return-child-result -x notmuch-new-vanish.gdb \
> -    --args notmuch new 2>OUTPUT 1>/dev/null
> +notmuch_with_shim dif-shim new 2>OUTPUT 1>/dev/null
>  echo "exit status: $?" >> OUTPUT
> -
> -# Clean up the file in case gdb isn't available.
> -rm -f ${MAIL_DIR}/vanish
> -
>  cat <<EOF > EXPECTED
>  Unexpected error with file ${MAIL_DIR}/vanish
>  add_file: Something went wrong trying to read or write a file
> diff --git a/test/notmuch-test.h b/test/notmuch-test.h
> index 8613a299..94348d69 100644
> --- a/test/notmuch-test.h
> +++ b/test/notmuch-test.h
> @@ -7,6 +7,7 @@
>  #include <sys/types.h>
>  #include <sys/stat.h>
>  #include <fcntl.h>
> +#include <unistd.h>
>  
>  inline static void
>  expect0 (int line, notmuch_status_t ret)
> -- 
> 2.33.0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/3] test: move system includes to notmuch-test.h
  2021-10-25 19:14   ` Tomi Ollila
@ 2021-10-28 13:46     ` David Bremner
  2021-10-28 13:46       ` [PATCH v2 2/3] test/count: replace use of gdb with a LD_PRELOAD shim David Bremner
                         ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: David Bremner @ 2021-10-28 13:46 UTC (permalink / raw)
  To: Tomi Ollila, David Bremner, notmuch

This removes some redudant includes, and will also make it easier to
introduce "#define _GNU_SOURCE", which must come before all system
includes.
---
 test/T562-lib-database.sh      | 4 +---
 test/T563-lib-directory.sh     | 4 +---
 test/T564-lib-query.sh         | 4 +---
 test/T566-lib-message.sh       | 3 +--
 test/T568-lib-thread.sh        | 3 +--
 test/T590-libconfig.sh         | 4 ----
 test/T595-reopen.sh            | 2 --
 test/T610-message-property.sh  | 4 ----
 test/T620-lock.sh              | 3 ---
 test/T640-database-modified.sh | 5 +----
 test/notmuch-test.h            | 6 ++++++
 11 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/test/T562-lib-database.sh b/test/T562-lib-database.sh
index 769fe86e..d9f5d18e 100755
--- a/test/T562-lib-database.sh
+++ b/test/T562-lib-database.sh
@@ -9,10 +9,8 @@ test_begin_subtest "building database"
 test_expect_success "NOTMUCH_NEW"
 
 cat <<EOF > c_head
-#include <stdio.h>
-#include <notmuch.h>
 #include <notmuch-test.h>
-#include <talloc.h>
+
 int main (int argc, char** argv)
 {
    notmuch_database_t *db;
diff --git a/test/T563-lib-directory.sh b/test/T563-lib-directory.sh
index 28325ff2..ad390c1c 100755
--- a/test/T563-lib-directory.sh
+++ b/test/T563-lib-directory.sh
@@ -9,10 +9,8 @@ test_begin_subtest "building database"
 test_expect_success "NOTMUCH_NEW"
 
 cat <<EOF > c_head
-#include <stdio.h>
-#include <notmuch.h>
 #include <notmuch-test.h>
-#include <talloc.h>
+
 int main (int argc, char** argv)
 {
    notmuch_database_t *db;
diff --git a/test/T564-lib-query.sh b/test/T564-lib-query.sh
index 50b0a88e..ff1d4984 100755
--- a/test/T564-lib-query.sh
+++ b/test/T564-lib-query.sh
@@ -9,10 +9,8 @@ test_begin_subtest "building database"
 test_expect_success "NOTMUCH_NEW"
 
 cat <<EOF > c_head
-#include <stdio.h>
-#include <notmuch.h>
 #include <notmuch-test.h>
-#include <talloc.h>
+
 int main (int argc, char** argv)
 {
    notmuch_database_t *db;
diff --git a/test/T566-lib-message.sh b/test/T566-lib-message.sh
index ee55ef29..8b61d182 100755
--- a/test/T566-lib-message.sh
+++ b/test/T566-lib-message.sh
@@ -19,9 +19,8 @@ cat <<'EOF' > c_tail
 EOF
 
 cat <<EOF > c_head0
-#include <stdio.h>
-#include <notmuch.h>
 #include <notmuch-test.h>
+
 int main (int argc, char** argv)
 {
    notmuch_database_t *db;
diff --git a/test/T568-lib-thread.sh b/test/T568-lib-thread.sh
index 088e66dd..b45836cd 100755
--- a/test/T568-lib-thread.sh
+++ b/test/T568-lib-thread.sh
@@ -24,9 +24,8 @@ cat <<'EOF' > c_tail
 EOF
 
 cat <<EOF > c_head
-#include <stdio.h>
-#include <notmuch.h>
 #include <notmuch-test.h>
+
 int main (int argc, char** argv)
 {
    notmuch_database_t *db;
diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
index a9566c13..0d890ca0 100755
--- a/test/T590-libconfig.sh
+++ b/test/T590-libconfig.sh
@@ -23,8 +23,6 @@ EOF
 }
 
 cat <<EOF > c_head
-#include <string.h>
-#include <stdlib.h>
 #include <notmuch-test.h>
 
 int main (int argc, char** argv)
@@ -616,8 +614,6 @@ cp notmuch-config.bak notmuch-config
 test_expect_equal_file EXPECTED OUTPUT
 
 cat <<EOF > c_head2
-#include <string.h>
-#include <stdlib.h>
 #include <notmuch-test.h>
 
 int main (int argc, char** argv)
diff --git a/test/T595-reopen.sh b/test/T595-reopen.sh
index 7375e2ac..1a517423 100755
--- a/test/T595-reopen.sh
+++ b/test/T595-reopen.sh
@@ -6,8 +6,6 @@ test_description="library reopen API"
 add_email_corpus
 
 cat <<EOF > c_head
-#include <string.h>
-#include <stdlib.h>
 #include <notmuch-test.h>
 
 int main (int argc, char** argv)
diff --git a/test/T610-message-property.sh b/test/T610-message-property.sh
index d0e52f4a..4ec85474 100755
--- a/test/T610-message-property.sh
+++ b/test/T610-message-property.sh
@@ -6,10 +6,6 @@ test_description="message property API"
 add_email_corpus
 
 cat <<EOF > c_head
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <talloc.h>
 #include <notmuch-test.h>
 
 void print_properties (notmuch_message_t *message, const char *prefix, notmuch_bool_t exact) {
diff --git a/test/T620-lock.sh b/test/T620-lock.sh
index 7aaaff2a..8f4c380f 100755
--- a/test/T620-lock.sh
+++ b/test/T620-lock.sh
@@ -9,9 +9,6 @@ if [ $NOTMUCH_HAVE_XAPIAN_DB_RETRY_LOCK -ne 1 ]; then
     test_subtest_known_broken
 fi
 test_C ${MAIL_DIR} <<'EOF'
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/wait.h>
 #include <notmuch-test.h>
 
 void
diff --git a/test/T640-database-modified.sh b/test/T640-database-modified.sh
index 274105c7..636b20c7 100755
--- a/test/T640-database-modified.sh
+++ b/test/T640-database-modified.sh
@@ -10,11 +10,8 @@ test_begin_subtest "catching DatabaseModifiedError in _notmuch_message_ensure_me
 first_id=$(notmuch search --output=messages '*'| head -1 | sed s/^id://)
 
 test_C ${MAIL_DIR} <<EOF
-#include <unistd.h>
-#include <stdlib.h>
 #include <notmuch-test.h>
-#include <talloc.h>
-#include <assert.h>
+
 int
 main (int argc, char **argv)
 {
diff --git a/test/notmuch-test.h b/test/notmuch-test.h
index 34dbb8e0..3a0e90a3 100644
--- a/test/notmuch-test.h
+++ b/test/notmuch-test.h
@@ -1,7 +1,13 @@
 #ifndef _NOTMUCH_TEST_H
 #define _NOTMUCH_TEST_H
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <talloc.h>
+#include <unistd.h>
+
 #include <notmuch.h>
 
 inline static void
-- 
2.33.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/3] test/count: replace use of gdb with a LD_PRELOAD shim
  2021-10-28 13:46     ` [PATCH v2 1/3] test: move system includes to notmuch-test.h David Bremner
@ 2021-10-28 13:46       ` David Bremner
  2021-10-28 13:46       ` [PATCH v2 3/3] test/new: replace use of gdb in vanishing file test David Bremner
  2021-12-04 16:51       ` [PATCH v2 1/3] test: move system includes to notmuch-test.h David Bremner
  2 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2021-10-28 13:46 UTC (permalink / raw)
  To: Tomi Ollila, David Bremner, notmuch

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
---
 test/T060-count.sh  | 27 +++++++++++++++------------
 test/notmuch-test.h | 27 +++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/test/T060-count.sh b/test/T060-count.sh
index 6ad80df9..48146706 100755
--- a/test/T060-count.sh
+++ b/test/T060-count.sh
@@ -102,22 +102,25 @@ output=$(sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' OUTPUT)
 test_expect_equal "${output}" "A Xapian exception occurred opening database"
 restore_database
 
-cat <<EOF > count-files.gdb
-set breakpoint pending on
-set logging file count-files-gdb.log
-set logging on
-break count_files
-commands
-shell cp /dev/null ${MAIL_DIR}/.notmuch/xapian/postlist.*
-continue
-end
-run
+make_shim qsm-shim<<EOF
+#include <notmuch-test.h>
+
+WRAP_DLFUNC (notmuch_status_t, notmuch_query_search_messages, (notmuch_query_t *query, notmuch_messages_t **messages))
+
+  /* XXX WARNING THIS CORRUPTS THE DATABASE */
+  int fd = open ("target_postlist", O_WRONLY|O_TRUNC);
+  if (fd < 0)
+    exit (8);
+  close (fd);
+
+  return notmuch_query_search_messages_orig(query, messages);
+}
 EOF
 
 backup_database
 test_begin_subtest "error message from query_search_messages"
-${TEST_GDB} --batch-silent --return-child-result -x count-files.gdb \
-    --args notmuch count --output=files '*' 2>OUTPUT 1>/dev/null
+ln -s ${MAIL_DIR}/.notmuch/xapian/postlist.* target_postlist
+notmuch_with_shim qsm-shim count --output=files '*' 2>OUTPUT 1>/dev/null
 cat <<EOF > EXPECTED
 notmuch count: A Xapian exception occurred
 A Xapian exception occurred performing query
diff --git a/test/notmuch-test.h b/test/notmuch-test.h
index 3a0e90a3..ed713099 100644
--- a/test/notmuch-test.h
+++ b/test/notmuch-test.h
@@ -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
-- 
2.33.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 3/3] test/new: replace use of gdb in vanishing file test
  2021-10-28 13:46     ` [PATCH v2 1/3] test: move system includes to notmuch-test.h David Bremner
  2021-10-28 13:46       ` [PATCH v2 2/3] test/count: replace use of gdb with a LD_PRELOAD shim David Bremner
@ 2021-10-28 13:46       ` David Bremner
  2021-10-28 13:50         ` David Bremner
  2021-12-04 16:51       ` [PATCH v2 1/3] test: move system includes to notmuch-test.h David Bremner
  2 siblings, 1 reply; 10+ messages in thread
From: David Bremner @ 2021-10-28 13:46 UTC (permalink / raw)
  To: Tomi Ollila, David Bremner, notmuch

Unlike the similar change in T060-new, no symlink creation is needed
here.
---
 test/T050-new.sh | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)

diff --git a/test/T050-new.sh b/test/T050-new.sh
index 1141c1e3..fd1a7695 100755
--- a/test/T050-new.sh
+++ b/test/T050-new.sh
@@ -368,31 +368,26 @@ chmod u+w ${MAIL_DIR}/.notmuch/xapian/*.*
 test_expect_equal "$output" "A Xapian exception occurred opening database"
 
 
+make_shim dif-shim<<EOF
+#include <notmuch-test.h>
+
+WRAP_DLFUNC(notmuch_status_t, notmuch_database_index_file, \
+ (notmuch_database_t *database, const char *filename, notmuch_indexopts_t *indexopts, notmuch_message_t **message))
+
+  if (unlink ("${MAIL_DIR}/vanish")) {
+     fprintf (stderr, "unlink failed\n");
+     exit(42);
+  }
+  return notmuch_database_index_file_orig (database, filename, indexopts, message);
+}
+EOF
+
 test_begin_subtest "Handle files vanishing between scandir and add_file"
 
 # A file for scandir to find. It won't get indexed, so can be empty.
 touch ${MAIL_DIR}/vanish
-
-# Breakpoint to remove the file before indexing
-cat <<EOF > notmuch-new-vanish.gdb
-set breakpoint pending on
-set logging file notmuch-new-vanish-gdb.log
-set logging on
-break notmuch_database_index_file
-commands
-shell rm -f ${MAIL_DIR}/vanish
-continue
-end
-run
-EOF
-
-${TEST_GDB} --batch-silent --return-child-result -x notmuch-new-vanish.gdb \
-    --args notmuch new 2>OUTPUT 1>/dev/null
+notmuch_with_shim dif-shim new 2>OUTPUT 1>/dev/null
 echo "exit status: $?" >> OUTPUT
-
-# Clean up the file in case gdb isn't available.
-rm -f ${MAIL_DIR}/vanish
-
 cat <<EOF > EXPECTED
 Unexpected error with file ${MAIL_DIR}/vanish
 add_file: Something went wrong trying to read or write a file
-- 
2.33.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 3/3] test/new: replace use of gdb in vanishing file test
  2021-10-28 13:46       ` [PATCH v2 3/3] test/new: replace use of gdb in vanishing file test David Bremner
@ 2021-10-28 13:50         ` David Bremner
  0 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2021-10-28 13:50 UTC (permalink / raw)
  To: Tomi Ollila, notmuch

David Bremner <david@tethera.net> writes:

> +  if (unlink ("${MAIL_DIR}/vanish")) {
> +     fprintf (stderr, "unlink failed\n");
> +     exit(42);

Oops, missing space added in git.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/3] test: move system includes to notmuch-test.h
  2021-10-28 13:46     ` [PATCH v2 1/3] test: move system includes to notmuch-test.h David Bremner
  2021-10-28 13:46       ` [PATCH v2 2/3] test/count: replace use of gdb with a LD_PRELOAD shim David Bremner
  2021-10-28 13:46       ` [PATCH v2 3/3] test/new: replace use of gdb in vanishing file test David Bremner
@ 2021-12-04 16:51       ` David Bremner
  2 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2021-12-04 16:51 UTC (permalink / raw)
  To: Tomi Ollila, notmuch

David Bremner <david@tethera.net> writes:

> This removes some redudant includes, and will also make it easier to
> introduce "#define _GNU_SOURCE", which must come before all system
> includes.

series applied to master

d

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-12-04 16:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-25  1:15 Reduce test suite reliance on gdb David Bremner
2021-10-25  1:15 ` [PATCH 1/2] test/count: replace use of gdb with a LD_PRELOAD shim David Bremner
2021-10-25 19:04   ` Tomi Ollila
2021-10-25  1:15 ` [PATCH 2/2] test/new: replace use of gdb in vanishing file test David Bremner
2021-10-25 19:14   ` Tomi Ollila
2021-10-28 13:46     ` [PATCH v2 1/3] test: move system includes to notmuch-test.h David Bremner
2021-10-28 13:46       ` [PATCH v2 2/3] test/count: replace use of gdb with a LD_PRELOAD shim David Bremner
2021-10-28 13:46       ` [PATCH v2 3/3] test/new: replace use of gdb in vanishing file test David Bremner
2021-10-28 13:50         ` David Bremner
2021-12-04 16:51       ` [PATCH v2 1/3] test: move system includes to notmuch-test.h David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).