Re: [PATCH v3 09/10] random-dump.c: new test-binary to generate dump files
authorMark Walters <markwalters1009@gmail.com>
Sun, 5 Feb 2012 01:04:13 +0000 (01:04 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:44:07 +0000 (09:44 -0800)
16/bae731cb01caaa1d70bfd9169757a54baff896 [new file with mode: 0644]

diff --git a/16/bae731cb01caaa1d70bfd9169757a54baff896 b/16/bae731cb01caaa1d70bfd9169757a54baff896
new file mode 100644 (file)
index 0000000..2deefa1
--- /dev/null
@@ -0,0 +1,292 @@
+Return-Path: <m.walters@qmul.ac.uk>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id AAD89431FAF\r
+       for <notmuch@notmuchmail.org>; Sat,  4 Feb 2012 17:03:07 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+       tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+       NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id cY34u9ZF5Svz for <notmuch@notmuchmail.org>;\r
+       Sat,  4 Feb 2012 17:03:06 -0800 (PST)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 7FD3E431FAE\r
+       for <notmuch@notmuchmail.org>; Sat,  4 Feb 2012 17:03:06 -0800 (PST)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+       by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1RtqVT-0004i3-Kf; Sun, 05 Feb 2012 01:03:04 +0000\r
+Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
+       helo=localhost)\r
+       by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1RtqVS-0001AM-Tw; Sun, 05 Feb 2012 01:03:03 +0000\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v3 09/10] random-dump.c: new test-binary to generate dump\r
+       files\r
+In-Reply-To: <1326591624-15493-10-git-send-email-david@tethera.net>\r
+References: <874nwxbkhr.fsf@zancas.localnet>\r
+       <1326591624-15493-1-git-send-email-david@tethera.net>\r
+       <1326591624-15493-10-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.11+154~ged6d37e (http://notmuchmail.org) Emacs/23.2.1\r
+       (i486-pc-linux-gnu)\r
+Date: Sun, 05 Feb 2012 01:04:13 +0000\r
+Message-ID: <87pqduozua.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.192.233.223\r
+X-QM-SPAM-Info: Sender has good ham record.  :)\r
+X-QM-Body-MD5: 3d9f4a4d652b1de39be6b3fa8d4da618 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+       determine if it is\r
+       spam. We require at least 5.0 points to mark a message as spam.\r
+       This message scored -1.8 points.\r
+       Summary of the scoring: \r
+       * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+       *      medium trust\r
+       *      [138.37.6.40 listed in list.dnswl.org]\r
+       * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+       provider *      (markwalters1009[at]gmail.com)\r
+       * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+       *      domain\r
+       *  0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\r
+Cc: David Bremner <bremner@debian.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 05 Feb 2012 01:03:07 -0000\r
+\r
+On Sat, 14 Jan 2012 21:40:23 -0400, David Bremner <david@tethera.net> wrote:\r
+> From: David Bremner <bremner@debian.org>\r
+> \r
+> This binary creates a "torture test" dump file for the new dump\r
+> format.\r
+> ---\r
+>  test/Makefile.local |    4 ++\r
+>  test/basic          |    2 +-\r
+>  test/random-dump.c  |  144 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
+>  3 files changed, 149 insertions(+), 1 deletions(-)\r
+>  create mode 100644 test/random-dump.c\r
+> \r
+> diff --git a/test/Makefile.local b/test/Makefile.local\r
+> index ba697f4..b59f837 100644\r
+> --- a/test/Makefile.local\r
+> +++ b/test/Makefile.local\r
+> @@ -16,6 +16,9 @@ $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a\r
+>  $(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a\r
+>      $(call quiet,CC) -I. $^ -o $@ -ltalloc\r
+>  \r
+> +$(dir)/random-dump:  $(dir)/random-dump.o command-line-arguments.o util/libutil.a\r
+> +    $(call quiet,CC) -I. $^ -o $@ -ltalloc -lm\r
+> +\r
+>  $(dir)/smtp-dummy: $(smtp_dummy_modules)\r
+>      $(call quiet,CC) $^ -o $@\r
+>  \r
+> @@ -25,6 +28,7 @@ $(dir)/symbol-test: $(dir)/symbol-test.o\r
+>  .PHONY: test check\r
+>  \r
+>  test-binaries: $(dir)/arg-test $(dir)/hex-xcode \\r
+> +    $(dir)/random-dump \\r
+>       $(dir)/smtp-dummy $(dir)/symbol-test\r
+>  \r
+>  test:       all test-binaries\r
+> diff --git a/test/basic b/test/basic\r
+> index af57026..e3a6cef 100755\r
+> --- a/test/basic\r
+> +++ b/test/basic\r
+> @@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'\r
+>  eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)\r
+>  tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)\r
+>  available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \\r
+> -    sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|hex-xcode)$/d" | \\r
+> +    sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|hex-xcode|random-dump)$/d" | \\r
+>      sort)\r
+>  test_expect_equal "$tests_in_suite" "$available"\r
+>  \r
+> diff --git a/test/random-dump.c b/test/random-dump.c\r
+> new file mode 100644\r
+> index 0000000..1949425\r
+> --- /dev/null\r
+> +++ b/test/random-dump.c\r
+> @@ -0,0 +1,144 @@\r
+> +/*\r
+> +   Generate a random dump file in 'notmuch' format.\r
+> +   Generated message-id's and tags are intentionally nasty.\r
+> +\r
+> +   We restrict ourselves to 7 bit message-ids, because generating\r
+> +   random valid UTF-8 seems like work. And invalid UTF-8 can't be\r
+> +   round-tripped via Xapian.\r
+> +\r
+> + */\r
+> +\r
+> +#include <stdlib.h>\r
+> +#include <assert.h>\r
+> +#include <talloc.h>\r
+> +#include <string.h>\r
+> +#include "math.h"\r
+> +#include "hex-escape.h"\r
+> +#include "command-line-arguments.h"\r
+> +\r
+> +static void\r
+> +hex_out (void *ctx, char *buf)\r
+> +{\r
+> +    static char *encoded_buf = NULL;\r
+> +    static size_t encoded_buf_size = 0;\r
+> +\r
+> +    if (hex_encode (ctx, buf, &encoded_buf, &encoded_buf_size) != HEX_SUCCESS) {\r
+> +    fprintf (stderr, "Hex encoding failed");\r
+> +    exit (1);\r
+> +    }\r
+> +\r
+> +    fputs (encoded_buf, stdout);\r
+> +}\r
+> +\r
+> +static void\r
+> +random_chars (char *buf, int from, int stop, int max_char,\r
+> +          const char *blacklist)\r
+> +{\r
+> +    int i;\r
+> +\r
+> +    for (i = from; i < stop; i++) {\r
+> +    do {\r
+> +        buf[i] = ' ' + (random () % (max_char - ' '));\r
+> +    } while (blacklist && strchr (blacklist, buf[i]));\r
+> +    }\r
+> +}\r
+> +\r
+> +static void\r
+> +random_tag (void *ctx, size_t len)\r
+> +{\r
+> +    static char *buf = NULL;\r
+> +    static size_t buf_len = 0;\r
+> +\r
+> +    int use = (random () % (len - 1)) + 1;\r
+> +\r
+> +    if (len > buf_len) {\r
+> +    buf = talloc_realloc (ctx, buf, char, len);\r
+> +    buf_len = len;\r
+> +    }\r
+> +\r
+> +    random_chars (buf, 0, use, 255, NULL);\r
+> +\r
+> +    buf[use] = '\0';\r
+> +\r
+> +    hex_out (ctx, buf);\r
+> +}\r
+> +\r
+> +static void\r
+> +random_message_id (void *ctx, size_t len)\r
+> +{\r
+> +    static char *buf = NULL;\r
+> +    static size_t buf_len = 0;\r
+> +\r
+> +    int lhs_len = (random () % (len / 2 - 1)) + 1;\r
+> +\r
+> +    int rhs_len = (random () % len / 2) + 1;\r
+> +\r
+> +    const char *blacklist = "\n\r@<>[]()";\r
+> +\r
+> +    if (len > buf_len) {\r
+> +    buf = talloc_realloc (ctx, buf, char, len);\r
+> +    buf_len = len;\r
+> +    }\r
+> +\r
+> +    random_chars (buf, 0, lhs_len, 127, blacklist);\r
+> +\r
+> +    buf[lhs_len] = '@';\r
+> +\r
+> +    random_chars (buf, lhs_len + 1, lhs_len + rhs_len + 1, 127, blacklist);\r
+> +\r
+> +    hex_out (ctx, buf);\r
+> +}\r
+> +\r
+> +int\r
+> +main (int argc, char **argv)\r
+> +{\r
+> +\r
+> +    void *ctx = talloc_new (NULL);\r
+> +    int num_lines = 500;\r
+> +    int max_tags = 10;\r
+> +    int message_id_len = 100;\r
+> +    int tag_len = 50;\r
+> +    int seed = 734569;\r
+> +\r
+> +    int pad_tag = 0, pad_mid = 0;\r
+> +\r
+> +    notmuch_opt_desc_t options[] = {\r
+> +    { NOTMUCH_OPT_INT, &num_lines, "num-lines", 'n', 0 },\r
+> +    { NOTMUCH_OPT_INT, &max_tags, "max-tags", 'm', 0 },\r
+> +    { NOTMUCH_OPT_INT, &message_id_len, "message-id-len", 'M', 0 },\r
+> +    { NOTMUCH_OPT_INT, &tag_len, "tag-len", 't', 0 },\r
+> +    { NOTMUCH_OPT_INT, &seed, "tag-len", 't', 0 },\r
+> +    { 0, 0, 0, 0, 0 }\r
+> +    };\r
+> +\r
+> +    int opt_index = parse_arguments (argc, argv, options, 1);\r
+> +\r
+> +    if (opt_index < 0)\r
+> +    exit (1);\r
+> +\r
+> +    pad_mid = ((int) log10 (num_lines) + 1);\r
+> +    pad_tag = ((int) log10 (max_tags)) + 1;\r
+> +\r
+> +    srandom (seed);\r
+> +\r
+> +    int line;\r
+> +    for (line = 0; line < num_lines; line++) {\r
+> +\r
+> +    printf ("%0*d-", pad_mid, line);\r
+> +\r
+> +    random_message_id (ctx, message_id_len);\r
+> +\r
+> +    int num_tags = random () % (max_tags + 1);\r
+> +\r
+> +    int j;\r
+> +    for (j = 0; j < num_tags; j++) {\r
+> +        printf (" %0*d-", pad_tag, j);\r
+> +        random_tag (ctx, tag_len);\r
+> +    }\r
+> +    putchar ('\n');\r
+> +    }\r
+> +\r
+> +    talloc_free (ctx);\r
+> +\r
+> +    return 0;\r
+> +}\r
+\r
+Hi\r
+\r
+Just a thought on this and the next test. Could you add messages with\r
+the random ids and tags from the above code to the Xapian database\r
+directly by calling whatever notmuch-new calls. Then test by doing dump,\r
+restore and dump and check the two dumps are equal? It might avoid your\r
+gmime concern from the next patch and you could have arbitrary\r
+(non-null) strings including all sorts of malformed utf-8.\r
+\r
+I guess Xapian might do bizarre things on the malformed utf-8 but, if it\r
+does, it might mean the correct place to fix it is in notmuch-new.\r
+\r
+Best wishes\r
+\r
+Mark\r