From 81b665713abfa9e1afa39518c3e8f817194486bd Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Wed, 8 Aug 2012 08:45:38 +0100 Subject: [PATCH] Re: [PATCH 2/3] test: add generator for random "stub" messages --- c5/57cb9e316cb31ae977a62610d058e25fe7565a | 382 ++++++++++++++++++++++ 1 file changed, 382 insertions(+) create mode 100644 c5/57cb9e316cb31ae977a62610d058e25fe7565a diff --git a/c5/57cb9e316cb31ae977a62610d058e25fe7565a b/c5/57cb9e316cb31ae977a62610d058e25fe7565a new file mode 100644 index 000000000..9bd6f5514 --- /dev/null +++ b/c5/57cb9e316cb31ae977a62610d058e25fe7565a @@ -0,0 +1,382 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 2C119431FAF + for ; Wed, 8 Aug 2012 00:45:48 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -1.098 +X-Spam-Level: +X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id Je9eDjexR187 for ; + Wed, 8 Aug 2012 00:45:47 -0700 (PDT) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id B1841431FAE + for ; Wed, 8 Aug 2012 00:45:46 -0700 (PDT) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1Sz0xc-0004fh-CK; Wed, 08 Aug 2012 08:45:44 +0100 +Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223] + helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) + (envelope-from ) + id 1Sz0xb-000168-Mb; Wed, 08 Aug 2012 08:45:44 +0100 +From: Mark Walters +To: david@tethera.net, notmuch@notmuchmail.org +Subject: Re: [PATCH 2/3] test: add generator for random "stub" messages +In-Reply-To: <1344190393-22497-3-git-send-email-david@tethera.net> +References: <1344190393-22497-1-git-send-email-david@tethera.net> + <1344190393-22497-3-git-send-email-david@tethera.net> +User-Agent: Notmuch/0.13.2+96~g634443c (http://notmuchmail.org) Emacs/23.4.1 + (x86_64-pc-linux-gnu) +Date: Wed, 08 Aug 2012 08:45:38 +0100 +Message-ID: <87393x3jz1.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 94.192.233.223 +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: cf197f392d6b8db2e5d884d1ac31f9dd (of first 20000 bytes) +X-SpamAssassin-Score: -1.8 +X-SpamAssassin-SpamBar: - +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored -1.8 points. + Summary of the scoring: + * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, + * medium trust + * [138.37.6.40 listed in list.dnswl.org] + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay + * domain + * 0.5 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +Cc: David Bremner +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Wed, 08 Aug 2012 07:45:48 -0000 + + +Hi I don't think I know enough Xapian to sensibly review the first patch +in this series. + +On Sun, 05 Aug 2012, david@tethera.net wrote: +> From: David Bremner +> +> Initial use case is testing dump and restore, so we only have +> message-ids and tags. +> +> The message ID's are nothing like RFC compliant, but it doesn't seem +> any harder to roundtrip random UTF-8 strings than RFC-compliant ones. +> +> Tags are UTF-8, even though notmuch is in principle more generous than +> that. +> --- +> test/.gitignore | 1 + +> test/Makefile.local | 14 +++- +> test/basic | 2 +- +> test/random-corpus.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++ +> 4 files changed, 216 insertions(+), 2 deletions(-) +> create mode 100644 test/random-corpus.c +> +> diff --git a/test/.gitignore b/test/.gitignore +> index e63c689..e23017b 100644 +> --- a/test/.gitignore +> +++ b/test/.gitignore +> @@ -3,4 +3,5 @@ corpus.mail +> smtp-dummy +> symbol-test +> arg-test +> +random-corpus +> tmp.* +> diff --git a/test/Makefile.local b/test/Makefile.local +> index c7f1435..586efc6 100644 +> --- a/test/Makefile.local +> +++ b/test/Makefile.local +> @@ -13,6 +13,13 @@ smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o) +> $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a +> $(call quiet,CC) -I. $^ -o $@ +> +> +random_corpus_deps = $(dir)/random-corpus.o $(dir)/database-test.o \ +> + notmuch-config.o command-line-arguments.o \ +> + lib/libnotmuch.a util/libutil.a +> + +> +$(dir)/random-corpus: $(random_corpus_deps) +> + $(call quiet,CC) $(CFLAGS_FINAL) $^ -o $@ $(CONFIGURE_LDFLAGS) +> + +> $(dir)/smtp-dummy: $(smtp_dummy_modules) +> $(call quiet,CC) $^ -o $@ +> +> @@ -21,7 +28,12 @@ $(dir)/symbol-test: $(dir)/symbol-test.o +> +> .PHONY: test check +> +> -test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test +> +TEST_BINARIES=$(dir)/arg-test \ +> + $(dir)/random-corpus \ +> + $(dir)/smtp-dummy \ +> + $(dir)/symbol-test +> + +> +test-binaries: $(TEST_BINARIES) +> +> test: all test-binaries +> @${dir}/notmuch-test $(OPTIONS) +> diff --git a/test/basic b/test/basic +> index d6aed24..589c4e2 100755 +> --- a/test/basic +> +++ b/test/basic +> @@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test' +> eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test) +> tests_in_suite=$(for i in $TESTS; do echo $i; done | sort) +> available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \ +> - sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test)$/d" | \ +> + sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|random-corpus)$/d" | \ +> sort) +> test_expect_equal "$tests_in_suite" "$available" +> +> diff --git a/test/random-corpus.c b/test/random-corpus.c +> new file mode 100644 +> index 0000000..ae900a6 +> --- /dev/null +> +++ b/test/random-corpus.c +> @@ -0,0 +1,201 @@ +> +/* +> + * Generate a random corpus of stub messages. +> + * +> + * Initial use case is testing dump and restore, so we only have +> + * message-ids and tags. +> + * +> + * Generated message-id's and tags are intentionally nasty. +> + * +> + * Copyright (c) 2012 David Bremner +> + * +> + * This program is free software: you can redistribute it and/or modify +> + * it under the terms of the GNU General Public License as published by +> + * the Free Software Foundation, either version 3 of the License, or +> + * (at your option) any later version. +> + * +> + * This program is distributed in the hope that it will be useful, +> + * but WITHOUT ANY WARRANTY; without even the implied warranty of +> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +> + * GNU General Public License for more details. +> + * +> + * You should have received a copy of the GNU General Public License +> + * along with this program. If not, see http://www.gnu.org/licenses/ . +> + * +> + * Author: David Bremner +> + */ +> + +> +#include +> +#include +> +#include +> +#include +> +#include +> +#include +> + +> +#include "notmuch-client.h" +> +#include "command-line-arguments.h" +> +#include "database-test.h" +> + +> +/* Current largest UTF-32 value defined. Note that most of these will +> + * be printed as boxes in most fonts. +> + */ +> + +> +#define GLYPH_MAX 0x10FFFE +> + +> +static gunichar +> +random_unichar () +> +{ +> + int start=1, stop=GLYPH_MAX; +> + int class = random() % 4; +> + +> + switch (class) { +> + case 0: +> + /* control */ +> + start=0x01; +> + stop=0x20; +> + break; +> + case 1: +> + start=0x21; +> + stop=0x7E; +> + break; +> + case 2: +> + start=0x41; +> + stop=0x7a; +> + break; +> + case 3: +> + start=0x7F; +> + stop=GLYPH_MAX; +> + } + +I think comments on other the classes might be helpful: I think Case 2 +is Ascii A-z but that has a few characters between Z and a. Of course +since you are generating a random character it doesn't "matter". + +> + +> + return start + (random() % (start - stop + 1)); +> +} + +I think you mean % (stop - start + 1)? + +Otherwise this looks fine (I haven't actually run it yet). + +Best wishes + +Mark + +> +static char * +> +random_utf8_string (void *ctx, size_t char_count) +> +{ +> + +> + gchar *buf = NULL; +> + size_t buf_size = 0; +> + +> + size_t offset = 0; +> + +> + size_t i; +> + +> + buf = talloc_realloc (ctx, NULL, gchar, char_count); +> + buf_size = char_count; +> + +> + for (i = 0; i < char_count; i++) { +> + gunichar randomchar; +> + size_t written; +> + +> + /* 6 for one glyph, one for null */ +> + if (buf_size - offset < 8) { +> + buf_size += 16; +> + buf = talloc_realloc (ctx, buf, gchar, buf_size); +> + } +> + +> + randomchar = random_unichar(); +> + +> + written = g_unichar_to_utf8 (randomchar, buf + offset); +> + +> + if (written <= 0) { +> + fprintf (stderr, "error converting to utf8\n"); +> + exit (1); +> + } +> + +> + offset += written; +> + +> + } +> + buf[offset] = 0; +> + return buf; +> +} +> + +> + +> +int +> +main (int argc, char **argv) +> +{ +> + +> + void *ctx = talloc_new (NULL); +> + +> + char *config_path = NULL; +> + notmuch_config_t *config; +> + notmuch_database_t *notmuch; +> + +> + int num_messages = 500; +> + int max_tags = 10; +> + // leave room for UTF-8 encoding. +> + int tag_len = NOTMUCH_TAG_MAX / 6; +> + // NOTMUCH_MESSAGE_ID_MAX is not exported, so we make a +> + // conservative guess. +> + int message_id_len = (NOTMUCH_TAG_MAX - 20) / 6; +> + +> + int seed = 734569; +> + +> + notmuch_opt_desc_t options[] = { +> + { NOTMUCH_OPT_STRING, &config_path, "config-path", 'c', 0 }, +> + { NOTMUCH_OPT_INT, &num_messages, "num-messages", 'n', 0 }, +> + { NOTMUCH_OPT_INT, &max_tags, "max-tags", 'm', 0 }, +> + { NOTMUCH_OPT_INT, &message_id_len, "message-id-len", 'M', 0 }, +> + { NOTMUCH_OPT_INT, &tag_len, "tag-len", 't', 0 }, +> + { NOTMUCH_OPT_INT, &seed, "seed", 's', 0 }, +> + { 0, 0, 0, 0, 0 } +> + }; +> + +> + int opt_index = parse_arguments (argc, argv, options, 1); +> + +> + if (opt_index < 0) +> + exit (1); +> + +> + if (config_path == NULL) { +> + fprintf (stderr, "configuration path must be specified"); +> + exit (1); +> + } +> + +> + config = notmuch_config_open (ctx, config_path, NULL); +> + if (config == NULL) +> + return 1; +> + +> + if (notmuch_database_open (notmuch_config_get_database_path (config), +> + NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much)) +> + return 1; +> + +> + srandom (seed); +> + +> + int count; +> + for (count = 0; count < num_messages; count++) { +> + int j; +> + int num_tags = random () % (max_tags + 1); +> + int this_mid_len = random () % message_id_len + 1; +> + const char **tag_list; +> + char *mid; +> + notmuch_status_t status; +> + +> + do { +> + mid = random_utf8_string (ctx, this_mid_len); +> + +> + tag_list = talloc_realloc (ctx, NULL, const char *, num_tags + 2); +> + +> + tag_list[0] = "random-corpus"; +> + +> + for (j = 0; j < num_tags; j++) { +> + int this_tag_len = random () % tag_len + 1; +> + +> + tag_list[j + 1] = random_utf8_string (ctx, this_tag_len); +> + } +> + +> + tag_list[j + 1] = NULL; +> + +> + status = notmuch_database_add_stub_message (notmuch, mid, tag_list); +> + } while (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID); +> + +> + if (status != NOTMUCH_STATUS_SUCCESS) { +> + fprintf (stderr, "error %d adding message", status); +> + exit (status); +> + } +> + } +> + +> + notmuch_database_destroy (notmuch); +> + +> + talloc_free (ctx); +> + +> + return 0; +> +} +> -- +> 1.7.10.4 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2