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 9D0B7431E82
\r
6 for <notmuch@notmuchmail.org>; Sun, 2 Dec 2012 05:34:09 -0800 (PST)
\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 MB-nwAM5oStd for <notmuch@notmuchmail.org>;
\r
16 Sun, 2 Dec 2012 05:34:05 -0800 (PST)
\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 85EB9431FD4
\r
21 for <notmuch@notmuchmail.org>; Sun, 2 Dec 2012 05:33:55 -0800 (PST)
\r
22 Received: from fctnnbsc30w-142167090129.dhcp-dynamic.fibreop.nb.bellaliant.net
\r
23 ([142.167.90.129] 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 1Tf9g0-0005w4-UX; Sun, 02 Dec 2012 09:33:55 -0400
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1Tf9fv-0001rf-Es; Sun, 02 Dec 2012 09:33:39 -0400
\r
31 From: david@tethera.net
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [patch v3 5/6] test: add generator for random "stub" messages
\r
34 Date: Sun, 2 Dec 2012 09:33:23 -0400
\r
35 Message-Id: <1354455204-6908-6-git-send-email-david@tethera.net>
\r
36 X-Mailer: git-send-email 1.7.10.4
\r
37 In-Reply-To: <1354455204-6908-1-git-send-email-david@tethera.net>
\r
38 References: <1354455204-6908-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, 02 Dec 2012 13:34:10 -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 updated for id:m2wr04ocro.fsf@guru.guru-group.fi
\r
68 - talk about Unicode value rather some specific encoding
\r
69 - call talloc_realloc less times
\r
71 test/.gitignore | 1 +
\r
72 test/Makefile.local | 10 +++
\r
74 test/random-corpus.c | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++
\r
75 4 files changed, 221 insertions(+)
\r
76 create mode 100644 test/random-corpus.c
\r
78 diff --git a/test/.gitignore b/test/.gitignore
\r
79 index be7ab5e..1eff7ce 100644
\r
80 --- a/test/.gitignore
\r
81 +++ b/test/.gitignore
\r
82 @@ -4,4 +4,5 @@ smtp-dummy
\r
88 diff --git a/test/Makefile.local b/test/Makefile.local
\r
89 index 8479f91..6a9f15e 100644
\r
90 --- a/test/Makefile.local
\r
91 +++ b/test/Makefile.local
\r
92 @@ -16,6 +16,14 @@ $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a
\r
93 $(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a
\r
94 $(call quiet,CC) -I. $^ -o $@ -ltalloc
\r
96 +random_corpus_deps = $(dir)/random-corpus.o $(dir)/database-test.o \
\r
97 + notmuch-config.o command-line-arguments.o \
\r
98 + lib/libnotmuch.a util/libutil.a \
\r
99 + parse-time-string/libparse-time-string.a
\r
101 +$(dir)/random-corpus: $(random_corpus_deps)
\r
102 + $(call quiet,CC) $(CFLAGS_FINAL) $^ -o $@ $(CONFIGURE_LDFLAGS)
\r
104 $(dir)/smtp-dummy: $(smtp_dummy_modules)
\r
105 $(call quiet,CC) $^ -o $@
\r
107 @@ -29,6 +37,7 @@ $(dir)/parse-time: $(dir)/parse-time.o parse-time-string/parse-time-string.o
\r
109 TEST_BINARIES=$(dir)/arg-test \
\r
111 + $(dir)/random-corpus \
\r
112 $(dir)/parse-time \
\r
113 $(dir)/smtp-dummy \
\r
115 @@ -46,5 +55,6 @@ CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \
\r
116 $(dir)/arg-test $(dir)/arg-test.o \
\r
117 $(dir)/hex-xcode $(dir)/hex-xcode.o \
\r
118 $(dir)/database-test.o \
\r
119 + $(dir)/random-corpus $(dir)/random-corpus.o \
\r
120 $(dir)/parse-time $(dir)/parse-time.o \
\r
121 $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*
\r
122 diff --git a/test/basic b/test/basic
\r
123 index c448ef8..1b2a7d2 100755
\r
126 @@ -59,6 +59,7 @@ available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -perm +111 \
\r
127 ! -name hex-xcode \
\r
128 ! -name notmuch-test \
\r
129 ! -name parse-time \
\r
130 + ! -name random-corpus \
\r
131 ! -name smtp-dummy \
\r
132 ! -name symbol-test \
\r
133 ! -name test-verbose \
\r
134 diff --git a/test/random-corpus.c b/test/random-corpus.c
\r
135 new file mode 100644
\r
136 index 0000000..f354d4b
\r
138 +++ b/test/random-corpus.c
\r
141 + * Generate a random corpus of stub messages.
\r
143 + * Initial use case is testing dump and restore, so we only have
\r
144 + * message-ids and tags.
\r
146 + * Generated message-id's and tags are intentionally nasty.
\r
148 + * Copyright (c) 2012 David Bremner
\r
150 + * This program is free software: you can redistribute it and/or modify
\r
151 + * it under the terms of the GNU General Public License as published by
\r
152 + * the Free Software Foundation, either version 3 of the License, or
\r
153 + * (at your option) any later version.
\r
155 + * This program is distributed in the hope that it will be useful,
\r
156 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
157 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
158 + * GNU General Public License for more details.
\r
160 + * You should have received a copy of the GNU General Public License
\r
161 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
163 + * Author: David Bremner <david@tethera.net>
\r
166 +#include <stdlib.h>
\r
167 +#include <assert.h>
\r
168 +#include <talloc.h>
\r
169 +#include <string.h>
\r
173 +#include "notmuch-client.h"
\r
174 +#include "command-line-arguments.h"
\r
175 +#include "database-test.h"
\r
177 +/* Current largest Unicode value defined. Note that most of these will
\r
178 + * be printed as boxes in most fonts.
\r
181 +#define GLYPH_MAX 0x10FFFE
\r
191 + * Choose about half ascii as test characters, as ascii
\r
192 + * punctation and whitespace is the main cause of problems for
\r
193 + * the (old) restore parser.
\r
195 + * We then favour code points with 2 byte encodings. Note that
\r
196 + * code points 0xD800-0xDFFF are forbidden in UTF-8.
\r
200 +char_class_t char_class[] = { { 0.50 * GLYPH_MAX, 0x0001, 0x007f },
\r
201 + { 0.75 * GLYPH_MAX, 0x0080, 0x07ff },
\r
202 + { 0.88 * GLYPH_MAX, 0x0800, 0xd7ff },
\r
203 + { 0.90 * GLYPH_MAX, 0xE000, 0xffff },
\r
204 + { GLYPH_MAX, 0x10000, GLYPH_MAX } };
\r
210 + int class = random () % GLYPH_MAX;
\r
213 + for (i = 0; char_class[i].weight < class; i++) /* nothing */;
\r
215 + size = char_class[i].stop - char_class[i].start + 1;
\r
217 + return char_class[i].start + (random () % size);
\r
221 +random_utf8_string (void *ctx, size_t char_count)
\r
223 + size_t offset = 0;
\r
225 + gchar *buf = NULL;
\r
226 + size_t buf_size = 0;
\r
228 + for (i = 0; i < char_count; i++) {
\r
229 + gunichar randomchar;
\r
232 + /* 6 for one glyph, one for null, one for luck */
\r
233 + while (buf_size <= offset + 8) {
\r
234 + buf_size = 2 * buf_size + 8;
\r
235 + buf = talloc_realloc (ctx, buf, gchar, buf_size);
\r
238 + randomchar = random_unichar ();
\r
240 + written = g_unichar_to_utf8 (randomchar, buf + offset);
\r
242 + if (written <= 0) {
\r
243 + fprintf (stderr, "error converting to utf8\n");
\r
247 + offset += written;
\r
256 +main (int argc, char **argv)
\r
259 + void *ctx = talloc_new (NULL);
\r
261 + char *config_path = NULL;
\r
262 + notmuch_config_t *config;
\r
263 + notmuch_database_t *notmuch;
\r
265 + int num_messages = 500;
\r
266 + int max_tags = 10;
\r
267 + // leave room for UTF-8 encoding.
\r
268 + int tag_len = NOTMUCH_TAG_MAX / 6;
\r
269 + // NOTMUCH_MESSAGE_ID_MAX is not exported, so we make a
\r
270 + // conservative guess.
\r
271 + int message_id_len = (NOTMUCH_TAG_MAX - 20) / 6;
\r
273 + int seed = 734569;
\r
275 + notmuch_opt_desc_t options[] = {
\r
276 + { NOTMUCH_OPT_STRING, &config_path, "config-path", 'c', 0 },
\r
277 + { NOTMUCH_OPT_INT, &num_messages, "num-messages", 'n', 0 },
\r
278 + { NOTMUCH_OPT_INT, &max_tags, "max-tags", 'm', 0 },
\r
279 + { NOTMUCH_OPT_INT, &message_id_len, "message-id-len", 'M', 0 },
\r
280 + { NOTMUCH_OPT_INT, &tag_len, "tag-len", 't', 0 },
\r
281 + { NOTMUCH_OPT_INT, &seed, "seed", 's', 0 },
\r
282 + { 0, 0, 0, 0, 0 }
\r
285 + int opt_index = parse_arguments (argc, argv, options, 1);
\r
287 + if (opt_index < 0)
\r
290 + if (message_id_len < 1) {
\r
291 + fprintf (stderr, "message id's must be least length 1\n");
\r
295 + if (config_path == NULL) {
\r
296 + fprintf (stderr, "configuration path must be specified");
\r
300 + config = notmuch_config_open (ctx, config_path, NULL);
\r
301 + if (config == NULL)
\r
304 + if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
305 + NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
311 + for (count = 0; count < num_messages; count++) {
\r
313 + /* explicitly allow zero tags */
\r
314 + int num_tags = random () % (max_tags + 1);
\r
315 + /* message ids should be non-empty */
\r
316 + int this_mid_len = (random () % message_id_len) + 1;
\r
317 + const char **tag_list;
\r
319 + notmuch_status_t status;
\r
322 + mid = random_utf8_string (ctx, this_mid_len);
\r
324 + tag_list = talloc_realloc (ctx, NULL, const char *, num_tags + 1);
\r
326 + for (j = 0; j < num_tags; j++) {
\r
327 + int this_tag_len = random () % tag_len + 1;
\r
329 + tag_list[j] = random_utf8_string (ctx, this_tag_len);
\r
332 + tag_list[j] = NULL;
\r
334 + status = notmuch_database_add_stub_message (notmuch, mid, tag_list);
\r
335 + } while (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID);
\r
337 + if (status != NOTMUCH_STATUS_SUCCESS) {
\r
338 + fprintf (stderr, "error %d adding message", status);
\r
343 + notmuch_database_destroy (notmuch);
\r
345 + talloc_free (ctx);
\r