1 Return-Path: <bremner@tesseract.cs.unb.ca>
\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 3689B431FBF
\r
6 for <notmuch@notmuchmail.org>; Mon, 20 Aug 2012 00:18:37 -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 HaQFbs7fXlGq for <notmuch@notmuchmail.org>;
\r
16 Mon, 20 Aug 2012 00:18:33 -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 55BE2431FBD
\r
21 for <notmuch@notmuchmail.org>; Mon, 20 Aug 2012 00:18:25 -0700 (PDT)
\r
22 Received: from remotemail by tesseract.cs.unb.ca with local (Exim 4.72)
\r
23 (envelope-from <bremner@tesseract.cs.unb.ca>)
\r
24 id 1T3MFk-0002FM-Fk; Mon, 20 Aug 2012 04:18:24 -0300
\r
25 Received: (nullmailer pid 7818 invoked by uid 1000);
\r
26 Sun, 19 Aug 2012 13:19:07 -0000
\r
27 From: david@tethera.net
\r
28 To: notmuch@notmuchmail.org
\r
29 Subject: [Patch v3 5/6] test: add generator for random "stub" messages
\r
30 Date: Sun, 19 Aug 2012 15:18:33 +0200
\r
31 Message-Id: <1345382314-5330-6-git-send-email-david@tethera.net>
\r
32 X-Mailer: git-send-email 1.7.10.4
\r
33 In-Reply-To: <1345382314-5330-1-git-send-email-david@tethera.net>
\r
34 References: <1345382314-5330-1-git-send-email-david@tethera.net>
\r
35 Cc: David Bremner <bremner@debian.org>
\r
36 X-BeenThere: notmuch@notmuchmail.org
\r
37 X-Mailman-Version: 2.1.13
\r
39 List-Id: "Use and development of the notmuch mail system."
\r
40 <notmuch.notmuchmail.org>
\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
42 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
44 List-Post: <mailto:notmuch@notmuchmail.org>
\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
48 X-List-Received-Date: Mon, 20 Aug 2012 07:18:37 -0000
\r
50 From: David Bremner <bremner@debian.org>
\r
52 Initial use case is testing dump and restore, so we only have
\r
53 message-ids and tags.
\r
55 The message ID's are nothing like RFC compliant, but it doesn't seem
\r
56 any harder to roundtrip random UTF-8 strings than RFC-compliant ones.
\r
58 Tags are UTF-8, even though notmuch is in principle more generous than
\r
61 test/.gitignore | 1 +
\r
62 test/Makefile.local | 9 +++
\r
64 test/random-corpus.c | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++
\r
65 4 files changed, 213 insertions(+), 1 deletion(-)
\r
66 create mode 100644 test/random-corpus.c
\r
68 diff --git a/test/.gitignore b/test/.gitignore
\r
69 index be7ab5e..1eff7ce 100644
\r
70 --- a/test/.gitignore
\r
71 +++ b/test/.gitignore
\r
72 @@ -4,4 +4,5 @@ smtp-dummy
\r
78 diff --git a/test/Makefile.local b/test/Makefile.local
\r
79 index bb67ded..ad0fd91 100644
\r
80 --- a/test/Makefile.local
\r
81 +++ b/test/Makefile.local
\r
82 @@ -16,6 +16,13 @@ $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a
\r
83 $(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a
\r
84 $(call quiet,CC) -I. $^ -o $@ -ltalloc
\r
86 +random_corpus_deps = $(dir)/random-corpus.o $(dir)/database-test.o \
\r
87 + notmuch-config.o command-line-arguments.o \
\r
88 + lib/libnotmuch.a util/libutil.a
\r
90 +$(dir)/random-corpus: $(random_corpus_deps)
\r
91 + $(call quiet,CC) $(CFLAGS_FINAL) $^ -o $@ $(CONFIGURE_LDFLAGS)
\r
93 $(dir)/smtp-dummy: $(smtp_dummy_modules)
\r
94 $(call quiet,CC) $^ -o $@
\r
96 @@ -26,6 +33,7 @@ $(dir)/symbol-test: $(dir)/symbol-test.o
\r
98 TEST_BINARIES=$(dir)/arg-test \
\r
100 + $(dir)/random-corpus \
\r
101 $(dir)/smtp-dummy \
\r
104 @@ -42,4 +50,5 @@ CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \
\r
105 $(dir)/arg-test $(dir)/arg-test.o \
\r
106 $(dir)/hex-xcode $(dir)/hex-xcode.o \
\r
107 $(dir)/database-test.o \
\r
108 + $(dir)/random-corpus $(dir)/random-corpus.o \
\r
109 $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*
\r
110 diff --git a/test/basic b/test/basic
\r
111 index af57026..5f8ed7a 100755
\r
114 @@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'
\r
115 eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)
\r
116 tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)
\r
117 available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \
\r
118 - sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|hex-xcode)$/d" | \
\r
119 + sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|hex-xcode|random-corpus)$/d" | \
\r
121 test_expect_equal "$tests_in_suite" "$available"
\r
123 diff --git a/test/random-corpus.c b/test/random-corpus.c
\r
124 new file mode 100644
\r
125 index 0000000..8c5b559
\r
127 +++ b/test/random-corpus.c
\r
130 + * Generate a random corpus of stub messages.
\r
132 + * Initial use case is testing dump and restore, so we only have
\r
133 + * message-ids and tags.
\r
135 + * Generated message-id's and tags are intentionally nasty.
\r
137 + * Copyright (c) 2012 David Bremner
\r
139 + * This program is free software: you can redistribute it and/or modify
\r
140 + * it under the terms of the GNU General Public License as published by
\r
141 + * the Free Software Foundation, either version 3 of the License, or
\r
142 + * (at your option) any later version.
\r
144 + * This program is distributed in the hope that it will be useful,
\r
145 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
146 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
147 + * GNU General Public License for more details.
\r
149 + * You should have received a copy of the GNU General Public License
\r
150 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
152 + * Author: David Bremner <david@tethera.net>
\r
155 +#include <stdlib.h>
\r
156 +#include <assert.h>
\r
157 +#include <talloc.h>
\r
158 +#include <string.h>
\r
162 +#include "notmuch-client.h"
\r
163 +#include "command-line-arguments.h"
\r
164 +#include "database-test.h"
\r
166 +/* Current largest UTF-32 value defined. Note that most of these will
\r
167 + * be printed as boxes in most fonts.
\r
170 +#define GLYPH_MAX 0x10FFFE
\r
175 + int start = 1, stop = GLYPH_MAX;
\r
176 + int class = random() % 2;
\r
179 + * Choose about half ascii as test characters, as ascii
\r
180 + * punctation and whitespace is the main cause of problems for
\r
181 + * the (old) restore parser
\r
190 + /* the rest of unicode */
\r
192 + stop = GLYPH_MAX;
\r
195 + if (start == stop)
\r
198 + return start + (random() % (stop - start + 1));
\r
202 +random_utf8_string (void *ctx, size_t char_count)
\r
205 + gchar *buf = NULL;
\r
206 + size_t buf_size = 0;
\r
208 + size_t offset = 0;
\r
212 + buf = talloc_realloc (ctx, NULL, gchar, char_count);
\r
213 + buf_size = char_count;
\r
215 + for (i = 0; i < char_count; i++) {
\r
216 + gunichar randomchar;
\r
219 + /* 6 for one glyph, one for null */
\r
220 + if (buf_size - offset < 8) {
\r
222 + buf = talloc_realloc (ctx, buf, gchar, buf_size);
\r
225 + randomchar = random_unichar();
\r
227 + written = g_unichar_to_utf8 (randomchar, buf + offset);
\r
229 + if (written <= 0) {
\r
230 + fprintf (stderr, "error converting to utf8\n");
\r
234 + offset += written;
\r
243 +main (int argc, char **argv)
\r
246 + void *ctx = talloc_new (NULL);
\r
248 + char *config_path = NULL;
\r
249 + notmuch_config_t *config;
\r
250 + notmuch_database_t *notmuch;
\r
252 + int num_messages = 500;
\r
253 + int max_tags = 10;
\r
254 + // leave room for UTF-8 encoding.
\r
255 + int tag_len = NOTMUCH_TAG_MAX / 6;
\r
256 + // NOTMUCH_MESSAGE_ID_MAX is not exported, so we make a
\r
257 + // conservative guess.
\r
258 + int message_id_len = (NOTMUCH_TAG_MAX - 20) / 6;
\r
260 + int seed = 734569;
\r
262 + notmuch_opt_desc_t options[] = {
\r
263 + { NOTMUCH_OPT_STRING, &config_path, "config-path", 'c', 0 },
\r
264 + { NOTMUCH_OPT_INT, &num_messages, "num-messages", 'n', 0 },
\r
265 + { NOTMUCH_OPT_INT, &max_tags, "max-tags", 'm', 0 },
\r
266 + { NOTMUCH_OPT_INT, &message_id_len, "message-id-len", 'M', 0 },
\r
267 + { NOTMUCH_OPT_INT, &tag_len, "tag-len", 't', 0 },
\r
268 + { NOTMUCH_OPT_INT, &seed, "seed", 's', 0 },
\r
269 + { 0, 0, 0, 0, 0 }
\r
272 + int opt_index = parse_arguments (argc, argv, options, 1);
\r
274 + if (opt_index < 0)
\r
277 + if (config_path == NULL) {
\r
278 + fprintf (stderr, "configuration path must be specified");
\r
282 + config = notmuch_config_open (ctx, config_path, NULL);
\r
283 + if (config == NULL)
\r
286 + if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
287 + NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
293 + for (count = 0; count < num_messages; count++) {
\r
295 + int num_tags = random () % (max_tags + 1);
\r
296 + int this_mid_len = random () % message_id_len + 1;
\r
297 + const char **tag_list;
\r
299 + notmuch_status_t status;
\r
302 + mid = random_utf8_string (ctx, this_mid_len);
\r
304 + tag_list = talloc_realloc (ctx, NULL, const char *, num_tags + 2);
\r
306 + tag_list[0] = "random-corpus";
\r
308 + for (j = 0; j < num_tags; j++) {
\r
309 + int this_tag_len = random () % tag_len + 1;
\r
311 + tag_list[j + 1] = random_utf8_string (ctx, this_tag_len);
\r
314 + tag_list[j + 1] = NULL;
\r
316 + status = notmuch_database_add_stub_message (notmuch, mid, tag_list);
\r
317 + } while (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID);
\r
319 + if (status != NOTMUCH_STATUS_SUCCESS) {
\r
320 + fprintf (stderr, "error %d adding message", status);
\r
325 + notmuch_database_destroy (notmuch);
\r
327 + talloc_free (ctx);
\r