From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id YHNwAs+pemFLaAEAgWs5BA (envelope-from ) for ; Thu, 28 Oct 2021 15:46:55 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id CD+2Oc6pemGAVQAAB5/wlQ (envelope-from ) for ; Thu, 28 Oct 2021 13:46:54 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9B600829B for ; Thu, 28 Oct 2021 15:46:54 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id D6E891FA10; Thu, 28 Oct 2021 09:46:40 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id A32161F75D for ; Thu, 28 Oct 2021 09:46:35 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 670CA5FC42; Thu, 28 Oct 2021 09:46:35 -0400 (EDT) Received: (nullmailer pid 204949 invoked by uid 1000); Thu, 28 Oct 2021 13:46:31 -0000 From: David Bremner To: Tomi Ollila , David Bremner , notmuch@notmuchmail.org Subject: [PATCH v2 2/3] test/count: replace use of gdb with a LD_PRELOAD shim Date: Thu, 28 Oct 2021 10:46:24 -0300 Message-Id: <20211028134625.204930-2-david@tethera.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211028134625.204930-1-david@tethera.net> References: <20211028134625.204930-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: 6GPA5SLS2HOMRX5UNVPUVW75NU7X6EWE X-Message-ID-Hash: 6GPA5SLS2HOMRX5UNVPUVW75NU7X6EWE X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1635428814; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=wwAAL8OeUDiLIFPA1MWAWRfVfeMllR4BIFbMZM4ongA=; b=OLqhCAThLtQLttvWCx+MhAl78M31L1c7jTdZPHpCMZXH/aseLjJ1XulBu/HZU+w2L/AUbT PgeHjnX5yJ/biS+OugJ1oO6JdcOdkxR7F01PNcyUHCFIS5lHAENX3Ax9Fa8DFlpj8qwRi7 YPmpNK29N4f3lg4RYnwChL2jScnppedmjFvxMcjEWDTNL9vtp1u0g2UlVptuiGI6nLv1F4 N8dRbpmgNCu3MbCEEvgmy9j14XxuEZcyM9dnjAMj4iOaeRSK2oYLiNE1C3/SsmwK10zc04 MAYNtoE0OmVEGSg+r3PUj19+FepjnlwXmPlfgyLGMdMk/c1pQijK9OIBRniVPg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1635428814; a=rsa-sha256; cv=none; b=gZH9l8KHNt9nHgUrni8ZA4LHnqyL52gBU1t9mlkmerEa/o6dYvaT7QzX97pyjpOPVl0agT /Ri6TRzB1pWbHAAxt/SfsYGo++c21qm6d/RYRSneLfyFTAsxYecbD/QABXYlF8owOsVVCF rUbX2Cl44jP2EICzHK5FZl0p/1MoHl07GRQpJiyxvd3if5zzwMubDfURVcZlKau2+zlM/9 qfffcipMuImILkmPKrhqRXD5/1uT1ZRq5cy8S3hv5kQwKxCefRgL17f7O8Bh34GEmrdzSL mQ9aeUnar3SqMyEews/0f+lraceEqJOtAphqgNCT9OEqRbewZd+68imLWo0SPg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.16 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 9B600829B X-Spam-Score: -1.16 X-Migadu-Scanner: scn0.migadu.com X-TUID: 2VUAKQ7PTLHL 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 < 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< + +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 < 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 +#include +#include #include #include #include +#include +#include #include #include #include @@ -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