1 Return-Path: <jani@nikula.org>
\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 64FA0431FAF
\r
6 for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 15:18:48 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\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 AA+Ibs8Khwqb for <notmuch@notmuchmail.org>;
\r
16 Fri, 30 Nov 2012 15:18:43 -0800 (PST)
\r
17 Received: from mail-la0-f53.google.com (mail-la0-f53.google.com
\r
18 [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 2441F431FAE
\r
21 for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 15:18:42 -0800 (PST)
\r
22 Received: by mail-la0-f53.google.com with SMTP id w12so844899lag.26
\r
23 for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 15:18:41 -0800 (PST)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=google.com; s=20120113;
\r
26 h=from:to:cc:subject:in-reply-to:references:user-agent:date
\r
27 :message-id:mime-version:content-type:x-gm-message-state;
\r
28 bh=vOg/oRAlXQv5gUTgVuRwW62CCurn0BQjyOl3DFPZsQ8=;
\r
29 b=F6gkjMxgZt0IgETVSkRc8tpCU2QMbsyXMBGsta/NUvtRo+vu1XLj0GnYywSb3MzSaM
\r
30 ZDObYJNAh/0XxnpuUrFnDsu93BfjNI4gKcxoZlPNoUZF/FESnkiDqj3P8lI0pb54BE04
\r
31 qXK0tP6V4jI1nGyeo0KBojLkuFShXRew5/p+3Kluf5rv7SVjX5ZeY0vB2ibT5bjRTa8Z
\r
32 ynBuXFO9US4eTVl3xsnZRAFMr/07Bs5bpdBYZ7OAux1k0G9sAoqSm/VO/NOTwBYREBni
\r
33 xR8DQMt6LGusbAoiHP4nyJPU4eyy8Fpm2P2R+pdxAdxyQyOevnH8rL7sGbprM744TrE4
\r
35 Received: by 10.112.38.226 with SMTP id j2mr1469259lbk.128.1354317521400;
\r
36 Fri, 30 Nov 2012 15:18:41 -0800 (PST)
\r
37 Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi.
\r
39 by mx.google.com with ESMTPS id z9sm2576085lby.8.2012.11.30.15.18.39
\r
40 (version=SSLv3 cipher=OTHER); Fri, 30 Nov 2012 15:18:40 -0800 (PST)
\r
41 From: Jani Nikula <jani@nikula.org>
\r
42 To: david@tethera.net, notmuch@notmuchmail.org
\r
43 Subject: Re: [Patch v2 05/17] test: add generator for random "stub" messages
\r
44 In-Reply-To: <1353792017-31459-6-git-send-email-david@tethera.net>
\r
45 References: <1353792017-31459-1-git-send-email-david@tethera.net>
\r
46 <1353792017-31459-6-git-send-email-david@tethera.net>
\r
47 User-Agent: Notmuch/0.14+124~g3b17402 (http://notmuchmail.org) Emacs/23.4.1
\r
49 Date: Sat, 01 Dec 2012 01:18:37 +0200
\r
50 Message-ID: <87obieadde.fsf@nikula.org>
\r
52 Content-Type: text/plain; charset=us-ascii
\r
54 ALoCoQng7+yRm1TIse5GMilVCiCecZcs+pavU2I+I3CBB1ERl/m3DPvD5QvB0VWa//axoG2zKZ8I
\r
55 Cc: David Bremner <bremner@debian.org>
\r
56 X-BeenThere: notmuch@notmuchmail.org
\r
57 X-Mailman-Version: 2.1.13
\r
59 List-Id: "Use and development of the notmuch mail system."
\r
60 <notmuch.notmuchmail.org>
\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
64 List-Post: <mailto:notmuch@notmuchmail.org>
\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
67 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
68 X-List-Received-Date: Fri, 30 Nov 2012 23:18:48 -0000
\r
70 On Sat, 24 Nov 2012, david@tethera.net wrote:
\r
71 > From: David Bremner <bremner@debian.org>
\r
73 > Initial use case is testing dump and restore, so we only have
\r
74 > message-ids and tags.
\r
76 > The message ID's are nothing like RFC compliant, but it doesn't seem
\r
77 > any harder to roundtrip random UTF-8 strings than RFC-compliant ones.
\r
79 > Tags are UTF-8, even though notmuch is in principle more generous than
\r
82 > updated for id:m2wr04ocro.fsf@guru.guru-group.fi
\r
84 > - talk about Unicode value rather some specific encoding
\r
85 > - call talloc_realloc less times
\r
87 > test/.gitignore | 1 +
\r
88 > test/Makefile.local | 10 +++
\r
90 > test/random-corpus.c | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++
\r
91 > 4 files changed, 216 insertions(+)
\r
92 > create mode 100644 test/random-corpus.c
\r
94 > diff --git a/test/.gitignore b/test/.gitignore
\r
95 > index be7ab5e..1eff7ce 100644
\r
96 > --- a/test/.gitignore
\r
97 > +++ b/test/.gitignore
\r
98 > @@ -4,4 +4,5 @@ smtp-dummy
\r
104 > diff --git a/test/Makefile.local b/test/Makefile.local
\r
105 > index 8479f91..6a9f15e 100644
\r
106 > --- a/test/Makefile.local
\r
107 > +++ b/test/Makefile.local
\r
108 > @@ -16,6 +16,14 @@ $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a
\r
109 > $(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a
\r
110 > $(call quiet,CC) -I. $^ -o $@ -ltalloc
\r
112 > +random_corpus_deps = $(dir)/random-corpus.o $(dir)/database-test.o \
\r
113 > + notmuch-config.o command-line-arguments.o \
\r
114 > + lib/libnotmuch.a util/libutil.a \
\r
115 > + parse-time-string/libparse-time-string.a
\r
117 > +$(dir)/random-corpus: $(random_corpus_deps)
\r
118 > + $(call quiet,CC) $(CFLAGS_FINAL) $^ -o $@ $(CONFIGURE_LDFLAGS)
\r
120 > $(dir)/smtp-dummy: $(smtp_dummy_modules)
\r
121 > $(call quiet,CC) $^ -o $@
\r
123 > @@ -29,6 +37,7 @@ $(dir)/parse-time: $(dir)/parse-time.o parse-time-string/parse-time-string.o
\r
125 > TEST_BINARIES=$(dir)/arg-test \
\r
126 > $(dir)/hex-xcode \
\r
127 > + $(dir)/random-corpus \
\r
128 > $(dir)/parse-time \
\r
129 > $(dir)/smtp-dummy \
\r
130 > $(dir)/symbol-test
\r
131 > @@ -46,5 +55,6 @@ CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \
\r
132 > $(dir)/arg-test $(dir)/arg-test.o \
\r
133 > $(dir)/hex-xcode $(dir)/hex-xcode.o \
\r
134 > $(dir)/database-test.o \
\r
135 > + $(dir)/random-corpus $(dir)/random-corpus.o \
\r
136 > $(dir)/parse-time $(dir)/parse-time.o \
\r
137 > $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*
\r
138 > diff --git a/test/basic b/test/basic
\r
139 > index 2a571ac..f93469f 100755
\r
142 > @@ -59,6 +59,7 @@ available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -perm +111 \
\r
143 > ! -name hex-xcode \
\r
144 > ! -name notmuch-test \
\r
145 > ! -name parse-time \
\r
146 > + ! -name random-corpus \
\r
147 > ! -name smtp-dummy \
\r
148 > ! -name symbol-test \
\r
149 > ! -name test-verbose \
\r
150 > diff --git a/test/random-corpus.c b/test/random-corpus.c
\r
151 > new file mode 100644
\r
152 > index 0000000..085bda0
\r
154 > +++ b/test/random-corpus.c
\r
155 > @@ -0,0 +1,204 @@
\r
157 > + * Generate a random corpus of stub messages.
\r
159 > + * Initial use case is testing dump and restore, so we only have
\r
160 > + * message-ids and tags.
\r
162 > + * Generated message-id's and tags are intentionally nasty.
\r
164 > + * Copyright (c) 2012 David Bremner
\r
166 > + * This program is free software: you can redistribute it and/or modify
\r
167 > + * it under the terms of the GNU General Public License as published by
\r
168 > + * the Free Software Foundation, either version 3 of the License, or
\r
169 > + * (at your option) any later version.
\r
171 > + * This program is distributed in the hope that it will be useful,
\r
172 > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
173 > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
174 > + * GNU General Public License for more details.
\r
176 > + * You should have received a copy of the GNU General Public License
\r
177 > + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
179 > + * Author: David Bremner <david@tethera.net>
\r
182 > +#include <stdlib.h>
\r
183 > +#include <assert.h>
\r
184 > +#include <talloc.h>
\r
185 > +#include <string.h>
\r
186 > +#include <glib.h>
\r
187 > +#include <math.h>
\r
189 > +#include "notmuch-client.h"
\r
190 > +#include "command-line-arguments.h"
\r
191 > +#include "database-test.h"
\r
193 > +/* Current largest Unicode value defined. Note that most of these will
\r
194 > + * be printed as boxes in most fonts.
\r
197 > +#define GLYPH_MAX 0x10FFFE
\r
200 > +random_unichar ()
\r
202 > + int start = 1, stop = GLYPH_MAX;
\r
203 > + int class = random() % 2;
\r
206 > + * Choose about half ascii as test characters, as ascii
\r
207 > + * punctation and whitespace is the main cause of problems for
\r
208 > + * the (old) restore parser
\r
211 I wonder if there should be even more emphasis on ascii and unicode code
\r
212 points up to U+07FF (which maps to two UTF-8 bytes).
\r
214 > + switch (class) {
\r
221 > + /* the rest of unicode */
\r
223 > + stop = GLYPH_MAX;
\r
226 > + if (start == stop)
\r
229 > + return start + (random() % (stop - start + 1));
\r
233 > +random_utf8_string (void *ctx, size_t char_count)
\r
235 > + size_t offset = 0;
\r
239 Irritating blank line. ;)
\r
241 > + gchar *buf = NULL;
\r
242 > + size_t buf_size = 0;
\r
244 You could do an initial talloc of the buf based on char_count,
\r
248 > + for (i = 0; i < char_count; i++) {
\r
249 > + gunichar randomchar;
\r
250 > + size_t written;
\r
252 > + /* 6 for one glyph, one for null, one for luck */
\r
253 > + while (buf_size - offset < 8) {
\r
255 I'd probably write that (offset + 8 >= buf_size).
\r
257 > + buf_size = 2 * buf_size + 8;
\r
258 > + buf = talloc_realloc (ctx, buf, gchar, buf_size);
\r
261 > + randomchar = random_unichar();
\r
263 > + written = g_unichar_to_utf8 (randomchar, buf + offset);
\r
265 > + if (written <= 0) {
\r
266 > + fprintf (stderr, "error converting to utf8\n");
\r
270 > + offset += written;
\r
273 > + buf[offset] = 0;
\r
279 > +main (int argc, char **argv)
\r
282 > + void *ctx = talloc_new (NULL);
\r
284 > + char *config_path = NULL;
\r
285 > + notmuch_config_t *config;
\r
286 > + notmuch_database_t *notmuch;
\r
288 > + int num_messages = 500;
\r
289 > + int max_tags = 10;
\r
290 > + // leave room for UTF-8 encoding.
\r
291 > + int tag_len = NOTMUCH_TAG_MAX / 6;
\r
292 > + // NOTMUCH_MESSAGE_ID_MAX is not exported, so we make a
\r
293 > + // conservative guess.
\r
294 > + int message_id_len = (NOTMUCH_TAG_MAX - 20) / 6;
\r
296 > + int seed = 734569;
\r
298 > + notmuch_opt_desc_t options[] = {
\r
299 > + { NOTMUCH_OPT_STRING, &config_path, "config-path", 'c', 0 },
\r
300 > + { NOTMUCH_OPT_INT, &num_messages, "num-messages", 'n', 0 },
\r
301 > + { NOTMUCH_OPT_INT, &max_tags, "max-tags", 'm', 0 },
\r
302 > + { NOTMUCH_OPT_INT, &message_id_len, "message-id-len", 'M', 0 },
\r
303 > + { NOTMUCH_OPT_INT, &tag_len, "tag-len", 't', 0 },
\r
304 > + { NOTMUCH_OPT_INT, &seed, "seed", 's', 0 },
\r
305 > + { 0, 0, 0, 0, 0 }
\r
308 > + int opt_index = parse_arguments (argc, argv, options, 1);
\r
310 > + if (opt_index < 0)
\r
313 > + if (message_id_len < 1) {
\r
314 > + fprintf (stderr, "message id's must be least length 1\n");
\r
318 > + if (config_path == NULL) {
\r
319 > + fprintf (stderr, "configuration path must be specified");
\r
323 > + config = notmuch_config_open (ctx, config_path, NULL);
\r
324 > + if (config == NULL)
\r
327 > + if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
328 > + NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
331 > + srandom (seed);
\r
334 > + for (count = 0; count < num_messages; count++) {
\r
336 > + /* explicitly allow zero tags */
\r
337 > + int num_tags = random () % (max_tags + 1);
\r
338 > + /* message ids should be non-empty */
\r
339 > + int this_mid_len = (random () % message_id_len) + 1;
\r
340 > + const char **tag_list;
\r
342 > + notmuch_status_t status;
\r
345 > + mid = random_utf8_string (ctx, this_mid_len);
\r
347 > + tag_list = talloc_realloc (ctx, NULL, const char *, num_tags + 2);
\r
349 > + tag_list[0] = "random-corpus";
\r
351 We'll probably want messages completely without tags in the tests
\r
352 too. How about a parameter to define the random-corpus tag. Which can be
\r
353 left out too. And if it's present, another parameter to tell whether it
\r
354 should be added even if num_tags == 0.
\r
356 Do the tags always come out sorted from the library? I'm wondering if
\r
357 it's a good idea to always put random-corpus there first. If it matters,
\r
358 you could use random () % num_tags to decide the position in the tag
\r
359 list to put the random-corpus tag in.
\r
366 > + for (j = 0; j < num_tags; j++) {
\r
367 > + int this_tag_len = random () % tag_len + 1;
\r
369 > + tag_list[j + 1] = random_utf8_string (ctx, this_tag_len);
\r
372 > + tag_list[j + 1] = NULL;
\r
374 > + status = notmuch_database_add_stub_message (notmuch, mid, tag_list);
\r
375 > + } while (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID);
\r
377 > + if (status != NOTMUCH_STATUS_SUCCESS) {
\r
378 > + fprintf (stderr, "error %d adding message", status);
\r
383 > + notmuch_database_destroy (notmuch);
\r
385 > + talloc_free (ctx);
\r
392 > _______________________________________________
\r
393 > notmuch mailing list
\r
394 > notmuch@notmuchmail.org
\r
395 > http://notmuchmail.org/mailman/listinfo/notmuch
\r