From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id SOKiD0EFdmFMLAAAgWs5BA (envelope-from ) for ; Mon, 25 Oct 2021 03:15:45 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id YBlJC0EFdmG1HgAAB5/wlQ (envelope-from ) for ; Mon, 25 Oct 2021 01:15:45 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (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 874C23AFAB for ; Mon, 25 Oct 2021 03:15:44 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 47C101F4E2; Sun, 24 Oct 2021 21:15:29 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id CEF021F4D6 for ; Sun, 24 Oct 2021 21:15:24 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 9D7055FC48; Sun, 24 Oct 2021 21:15:24 -0400 (EDT) Received: (nullmailer pid 2533943 invoked by uid 1000); Mon, 25 Oct 2021 01:15:20 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 1/2] test/count: replace use of gdb with a LD_PRELOAD shim Date: Sun, 24 Oct 2021 22:15:14 -0300 Message-Id: <20211025011515.2533779-2-david@tethera.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211025011515.2533779-1-david@tethera.net> References: <20211025011515.2533779-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: YUCYCDIECY43YFXJAGOJDZQJTF2Q5A27 X-Message-ID-Hash: YUCYCDIECY43YFXJAGOJDZQJTF2Q5A27 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=1635124544; 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=25AWyBBF/7Vqs7NjDiqvrCOgS7R51wGV0MCHVF39o8s=; b=g4Vy/uY3KFmNv0+IZNg2IgBmiuicB9Z7o/ICp8mwvpre9jyTSfurXHxjAMPg2bMw2fREmM VX/273p/TFHIAIrsFRHqEfzXzc3icvS50p0mD3VhS3njWLAaa0rHehdiud2vkz+VlKbBkG njuhvMXZNnZiFKBVh1B5FkoICS+YjKbhLN1/7gWYr7ajDGcQ7vha9D2LnQOgS7J8C2sfoJ 7LPMEI4MGx+zSC0NrunhH71IrYqIjNruacgSBQmBqlNTSGChejDtpVRKL6zfK5BTXpGm+Q PaQ0eBmvtcr/gYGJMPtg20a867rpAw8R7M7iI+u/2Cob6pHACpSYghr9e6Ld3Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1635124544; a=rsa-sha256; cv=none; b=GDl4tLm+DKpV3YLllvGM+31L9CRiqq3yxYJ59o/tdfX85Ipwvzn2bct05ui6iEKPS21ZTJ UV7T+PZmZPMsHoUs2HskKum0xN3Zgin8x6C++8ab53FydzeUFCIoQahL6NQM20Mo8fHrkn i0n+Cr1ZPj59Jp2ihEm2v9zvaUR0lEoLuy04DJnjYKlnAVH6KN8AnM2P8YDMqZrKYfMx11 6W5LLVlZPI4ovNUqTESMeZpJy9VDYsqDGDmPMhcbzuvgHXHcxiULEgUed16xghwiXK/32U l0cu69olw6xSqv0VR22nHCYFiX1tKR17XXIwL7wXc09hp42IhG1xg/4mp2DPjA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.15 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 874C23AFAB X-Spam-Score: -1.15 X-Migadu-Scanner: scn1.migadu.com X-TUID: RkbcZ4d5U+Ia 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 < 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< +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 < 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 #include #include +#include +#include +#include +#include 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