1 Return-Path: <bremner@tethera.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 4C983431FC7
\r
6 for <notmuch@notmuchmail.org>; Sun, 5 Aug 2012 11:13:40 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id QARCMulpjBKv for <notmuch@notmuchmail.org>;
\r
16 Sun, 5 Aug 2012 11:13:38 -0700 (PDT)
\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])
\r
18 (using TLSv1 with cipher AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id EB97B431FB6
\r
21 for <notmuch@notmuchmail.org>; Sun, 5 Aug 2012 11:13:37 -0700 (PDT)
\r
22 Received: from fctnnbsc30w-156034089108.dhcp-dynamic.fibreop.nb.bellaliant.net
\r
23 ([156.34.89.108] helo=zancas.localnet)
\r
24 by tesseract.cs.unb.ca with esmtpsa
\r
25 (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)
\r
26 (envelope-from <bremner@tethera.net>)
\r
27 id 1Sy5KU-0006XL-Ud; Sun, 05 Aug 2012 15:13:35 -0300
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1Sy5KP-0005x4-IH; Sun, 05 Aug 2012 15:13:25 -0300
\r
31 From: david@tethera.net
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH 2/3] test: add generator for random "stub" messages
\r
34 Date: Sun, 5 Aug 2012 15:13:12 -0300
\r
35 Message-Id: <1344190393-22497-3-git-send-email-david@tethera.net>
\r
36 X-Mailer: git-send-email 1.7.10.4
\r
37 In-Reply-To: <1344190393-22497-1-git-send-email-david@tethera.net>
\r
38 References: <1344190393-22497-1-git-send-email-david@tethera.net>
\r
40 Cc: David Bremner <bremner@debian.org>
\r
41 X-BeenThere: notmuch@notmuchmail.org
\r
42 X-Mailman-Version: 2.1.13
\r
44 List-Id: "Use and development of the notmuch mail system."
\r
45 <notmuch.notmuchmail.org>
\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
49 List-Post: <mailto:notmuch@notmuchmail.org>
\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
53 X-List-Received-Date: Sun, 05 Aug 2012 18:13:40 -0000
\r
55 From: David Bremner <bremner@debian.org>
\r
57 Initial use case is testing dump and restore, so we only have
\r
58 message-ids and tags.
\r
60 The message ID's are nothing like RFC compliant, but it doesn't seem
\r
61 any harder to roundtrip random UTF-8 strings than RFC-compliant ones.
\r
63 Tags are UTF-8, even though notmuch is in principle more generous than
\r
66 test/.gitignore | 1 +
\r
67 test/Makefile.local | 14 +++-
\r
69 test/random-corpus.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++
\r
70 4 files changed, 216 insertions(+), 2 deletions(-)
\r
71 create mode 100644 test/random-corpus.c
\r
73 diff --git a/test/.gitignore b/test/.gitignore
\r
74 index e63c689..e23017b 100644
\r
75 --- a/test/.gitignore
\r
76 +++ b/test/.gitignore
\r
77 @@ -3,4 +3,5 @@ corpus.mail
\r
83 diff --git a/test/Makefile.local b/test/Makefile.local
\r
84 index c7f1435..586efc6 100644
\r
85 --- a/test/Makefile.local
\r
86 +++ b/test/Makefile.local
\r
87 @@ -13,6 +13,13 @@ smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o)
\r
88 $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a
\r
89 $(call quiet,CC) -I. $^ -o $@
\r
91 +random_corpus_deps = $(dir)/random-corpus.o $(dir)/database-test.o \
\r
92 + notmuch-config.o command-line-arguments.o \
\r
93 + lib/libnotmuch.a util/libutil.a
\r
95 +$(dir)/random-corpus: $(random_corpus_deps)
\r
96 + $(call quiet,CC) $(CFLAGS_FINAL) $^ -o $@ $(CONFIGURE_LDFLAGS)
\r
98 $(dir)/smtp-dummy: $(smtp_dummy_modules)
\r
99 $(call quiet,CC) $^ -o $@
\r
101 @@ -21,7 +28,12 @@ $(dir)/symbol-test: $(dir)/symbol-test.o
\r
105 -test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test
\r
106 +TEST_BINARIES=$(dir)/arg-test \
\r
107 + $(dir)/random-corpus \
\r
108 + $(dir)/smtp-dummy \
\r
109 + $(dir)/symbol-test
\r
111 +test-binaries: $(TEST_BINARIES)
\r
113 test: all test-binaries
\r
114 @${dir}/notmuch-test $(OPTIONS)
\r
115 diff --git a/test/basic b/test/basic
\r
116 index d6aed24..589c4e2 100755
\r
119 @@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'
\r
120 eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)
\r
121 tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)
\r
122 available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \
\r
123 - sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test)$/d" | \
\r
124 + sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|random-corpus)$/d" | \
\r
126 test_expect_equal "$tests_in_suite" "$available"
\r
128 diff --git a/test/random-corpus.c b/test/random-corpus.c
\r
129 new file mode 100644
\r
130 index 0000000..ae900a6
\r
132 +++ b/test/random-corpus.c
\r
135 + * Generate a random corpus of stub messages.
\r
137 + * Initial use case is testing dump and restore, so we only have
\r
138 + * message-ids and tags.
\r
140 + * Generated message-id's and tags are intentionally nasty.
\r
142 + * Copyright (c) 2012 David Bremner
\r
144 + * This program is free software: you can redistribute it and/or modify
\r
145 + * it under the terms of the GNU General Public License as published by
\r
146 + * the Free Software Foundation, either version 3 of the License, or
\r
147 + * (at your option) any later version.
\r
149 + * This program is distributed in the hope that it will be useful,
\r
150 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
151 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
152 + * GNU General Public License for more details.
\r
154 + * You should have received a copy of the GNU General Public License
\r
155 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
157 + * Author: David Bremner <david@tethera.net>
\r
160 +#include <stdlib.h>
\r
161 +#include <assert.h>
\r
162 +#include <talloc.h>
\r
163 +#include <string.h>
\r
167 +#include "notmuch-client.h"
\r
168 +#include "command-line-arguments.h"
\r
169 +#include "database-test.h"
\r
171 +/* Current largest UTF-32 value defined. Note that most of these will
\r
172 + * be printed as boxes in most fonts.
\r
175 +#define GLYPH_MAX 0x10FFFE
\r
180 + int start=1, stop=GLYPH_MAX;
\r
181 + int class = random() % 4;
\r
202 + return start + (random() % (start - stop + 1));
\r
206 +random_utf8_string (void *ctx, size_t char_count)
\r
209 + gchar *buf = NULL;
\r
210 + size_t buf_size = 0;
\r
212 + size_t offset = 0;
\r
216 + buf = talloc_realloc (ctx, NULL, gchar, char_count);
\r
217 + buf_size = char_count;
\r
219 + for (i = 0; i < char_count; i++) {
\r
220 + gunichar randomchar;
\r
223 + /* 6 for one glyph, one for null */
\r
224 + if (buf_size - offset < 8) {
\r
226 + buf = talloc_realloc (ctx, buf, gchar, buf_size);
\r
229 + randomchar = random_unichar();
\r
231 + written = g_unichar_to_utf8 (randomchar, buf + offset);
\r
233 + if (written <= 0) {
\r
234 + fprintf (stderr, "error converting to utf8\n");
\r
238 + offset += written;
\r
247 +main (int argc, char **argv)
\r
250 + void *ctx = talloc_new (NULL);
\r
252 + char *config_path = NULL;
\r
253 + notmuch_config_t *config;
\r
254 + notmuch_database_t *notmuch;
\r
256 + int num_messages = 500;
\r
257 + int max_tags = 10;
\r
258 + // leave room for UTF-8 encoding.
\r
259 + int tag_len = NOTMUCH_TAG_MAX / 6;
\r
260 + // NOTMUCH_MESSAGE_ID_MAX is not exported, so we make a
\r
261 + // conservative guess.
\r
262 + int message_id_len = (NOTMUCH_TAG_MAX - 20) / 6;
\r
264 + int seed = 734569;
\r
266 + notmuch_opt_desc_t options[] = {
\r
267 + { NOTMUCH_OPT_STRING, &config_path, "config-path", 'c', 0 },
\r
268 + { NOTMUCH_OPT_INT, &num_messages, "num-messages", 'n', 0 },
\r
269 + { NOTMUCH_OPT_INT, &max_tags, "max-tags", 'm', 0 },
\r
270 + { NOTMUCH_OPT_INT, &message_id_len, "message-id-len", 'M', 0 },
\r
271 + { NOTMUCH_OPT_INT, &tag_len, "tag-len", 't', 0 },
\r
272 + { NOTMUCH_OPT_INT, &seed, "seed", 's', 0 },
\r
273 + { 0, 0, 0, 0, 0 }
\r
276 + int opt_index = parse_arguments (argc, argv, options, 1);
\r
278 + if (opt_index < 0)
\r
281 + if (config_path == NULL) {
\r
282 + fprintf (stderr, "configuration path must be specified");
\r
286 + config = notmuch_config_open (ctx, config_path, NULL);
\r
287 + if (config == NULL)
\r
290 + if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
291 + NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
297 + for (count = 0; count < num_messages; count++) {
\r
299 + int num_tags = random () % (max_tags + 1);
\r
300 + int this_mid_len = random () % message_id_len + 1;
\r
301 + const char **tag_list;
\r
303 + notmuch_status_t status;
\r
306 + mid = random_utf8_string (ctx, this_mid_len);
\r
308 + tag_list = talloc_realloc (ctx, NULL, const char *, num_tags + 2);
\r
310 + tag_list[0] = "random-corpus";
\r
312 + for (j = 0; j < num_tags; j++) {
\r
313 + int this_tag_len = random () % tag_len + 1;
\r
315 + tag_list[j + 1] = random_utf8_string (ctx, this_tag_len);
\r
318 + tag_list[j + 1] = NULL;
\r
320 + status = notmuch_database_add_stub_message (notmuch, mid, tag_list);
\r
321 + } while (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID);
\r
323 + if (status != NOTMUCH_STATUS_SUCCESS) {
\r
324 + fprintf (stderr, "error %d adding message", status);
\r
329 + notmuch_database_destroy (notmuch);
\r
331 + talloc_free (ctx);
\r