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 750C0431FD7
\r
6 for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 13:20:44 -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 GHTerZEsoPnH for <notmuch@notmuchmail.org>;
\r
16 Sat, 24 Nov 2012 13:20:41 -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 5A28D431FD5
\r
21 for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 13:20:33 -0800 (PST)
\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 1TcN9L-0006SL-O6; Sat, 24 Nov 2012 17:20:32 -0400
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1TcN9G-0008Ci-8c; Sat, 24 Nov 2012 17:20:26 -0400
\r
31 From: david@tethera.net
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [Patch v2 05/17] test: add generator for random "stub" messages
\r
34 Date: Sat, 24 Nov 2012 17:20:05 -0400
\r
35 Message-Id: <1353792017-31459-6-git-send-email-david@tethera.net>
\r
36 X-Mailer: git-send-email 1.7.10.4
\r
37 In-Reply-To: <1353792017-31459-1-git-send-email-david@tethera.net>
\r
38 References: <1353792017-31459-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: Sat, 24 Nov 2012 21:20:45 -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 | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++
\r
75 4 files changed, 216 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 2a571ac..f93469f 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..085bda0
\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
186 + int start = 1, stop = GLYPH_MAX;
\r
187 + int class = random() % 2;
\r
190 + * Choose about half ascii as test characters, as ascii
\r
191 + * punctation and whitespace is the main cause of problems for
\r
192 + * the (old) restore parser
\r
201 + /* the rest of unicode */
\r
203 + stop = GLYPH_MAX;
\r
206 + if (start == stop)
\r
209 + return start + (random() % (stop - start + 1));
\r
213 +random_utf8_string (void *ctx, size_t char_count)
\r
215 + size_t offset = 0;
\r
218 + gchar *buf = NULL;
\r
219 + size_t buf_size = 0;
\r
221 + for (i = 0; i < char_count; i++) {
\r
222 + gunichar randomchar;
\r
225 + /* 6 for one glyph, one for null, one for luck */
\r
226 + while (buf_size - offset < 8) {
\r
227 + buf_size = 2 * buf_size + 8;
\r
228 + buf = talloc_realloc (ctx, buf, gchar, buf_size);
\r
231 + randomchar = random_unichar();
\r
233 + written = g_unichar_to_utf8 (randomchar, buf + offset);
\r
235 + if (written <= 0) {
\r
236 + fprintf (stderr, "error converting to utf8\n");
\r
240 + offset += written;
\r
249 +main (int argc, char **argv)
\r
252 + void *ctx = talloc_new (NULL);
\r
254 + char *config_path = NULL;
\r
255 + notmuch_config_t *config;
\r
256 + notmuch_database_t *notmuch;
\r
258 + int num_messages = 500;
\r
259 + int max_tags = 10;
\r
260 + // leave room for UTF-8 encoding.
\r
261 + int tag_len = NOTMUCH_TAG_MAX / 6;
\r
262 + // NOTMUCH_MESSAGE_ID_MAX is not exported, so we make a
\r
263 + // conservative guess.
\r
264 + int message_id_len = (NOTMUCH_TAG_MAX - 20) / 6;
\r
266 + int seed = 734569;
\r
268 + notmuch_opt_desc_t options[] = {
\r
269 + { NOTMUCH_OPT_STRING, &config_path, "config-path", 'c', 0 },
\r
270 + { NOTMUCH_OPT_INT, &num_messages, "num-messages", 'n', 0 },
\r
271 + { NOTMUCH_OPT_INT, &max_tags, "max-tags", 'm', 0 },
\r
272 + { NOTMUCH_OPT_INT, &message_id_len, "message-id-len", 'M', 0 },
\r
273 + { NOTMUCH_OPT_INT, &tag_len, "tag-len", 't', 0 },
\r
274 + { NOTMUCH_OPT_INT, &seed, "seed", 's', 0 },
\r
275 + { 0, 0, 0, 0, 0 }
\r
278 + int opt_index = parse_arguments (argc, argv, options, 1);
\r
280 + if (opt_index < 0)
\r
283 + if (message_id_len < 1) {
\r
284 + fprintf (stderr, "message id's must be least length 1\n");
\r
288 + if (config_path == NULL) {
\r
289 + fprintf (stderr, "configuration path must be specified");
\r
293 + config = notmuch_config_open (ctx, config_path, NULL);
\r
294 + if (config == NULL)
\r
297 + if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
298 + NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
304 + for (count = 0; count < num_messages; count++) {
\r
306 + /* explicitly allow zero tags */
\r
307 + int num_tags = random () % (max_tags + 1);
\r
308 + /* message ids should be non-empty */
\r
309 + int this_mid_len = (random () % message_id_len) + 1;
\r
310 + const char **tag_list;
\r
312 + notmuch_status_t status;
\r
315 + mid = random_utf8_string (ctx, this_mid_len);
\r
317 + tag_list = talloc_realloc (ctx, NULL, const char *, num_tags + 2);
\r
319 + tag_list[0] = "random-corpus";
\r
321 + for (j = 0; j < num_tags; j++) {
\r
322 + int this_tag_len = random () % tag_len + 1;
\r
324 + tag_list[j + 1] = random_utf8_string (ctx, this_tag_len);
\r
327 + tag_list[j + 1] = NULL;
\r
329 + status = notmuch_database_add_stub_message (notmuch, mid, tag_list);
\r
330 + } while (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID);
\r
332 + if (status != NOTMUCH_STATUS_SUCCESS) {
\r
333 + fprintf (stderr, "error %d adding message", status);
\r
338 + notmuch_database_destroy (notmuch);
\r
340 + talloc_free (ctx);
\r