Re: [PATCH 1/1] emacs/notmuch.el: remove instruction to (require 'notmuch) in ~/...
[notmuch-archives.git] / d2 / a3c6a3f16cc905e5a484254b101a372213832d
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
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 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
39 X-Spam_bar: -\r
40 Cc: David Bremner <bremner@debian.org>\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\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
54 \r
55 From: David Bremner <bremner@debian.org>\r
56 \r
57 Initial use case is testing dump and restore, so we only have\r
58 message-ids and tags.\r
59 \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
62 \r
63 Tags are UTF-8, even though notmuch is in principle more generous than\r
64 that.\r
65 \r
66 updated for id:m2wr04ocro.fsf@guru.guru-group.fi\r
67 \r
68 - talk about Unicode value rather some specific encoding\r
69 - call talloc_realloc less times\r
70 ---\r
71  test/.gitignore      |    1 +\r
72  test/Makefile.local  |   10 +++\r
73  test/basic           |    1 +\r
74  test/random-corpus.c |  209 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
75  4 files changed, 221 insertions(+)\r
76  create mode 100644 test/random-corpus.c\r
77 \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
83  symbol-test\r
84  arg-test\r
85  hex-xcode\r
86 +random-corpus\r
87  tmp.*\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
95  \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
100 +\r
101 +$(dir)/random-corpus: $(random_corpus_deps)\r
102 +       $(call quiet,CC) $(CFLAGS_FINAL) $^ -o $@ $(CONFIGURE_LDFLAGS)\r
103 +\r
104  $(dir)/smtp-dummy: $(smtp_dummy_modules)\r
105         $(call quiet,CC) $^ -o $@\r
106  \r
107 @@ -29,6 +37,7 @@ $(dir)/parse-time: $(dir)/parse-time.o parse-time-string/parse-time-string.o\r
108  \r
109  TEST_BINARIES=$(dir)/arg-test \\r
110               $(dir)/hex-xcode \\r
111 +             $(dir)/random-corpus \\r
112               $(dir)/parse-time \\r
113               $(dir)/smtp-dummy \\r
114               $(dir)/symbol-test\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
124 --- a/test/basic\r
125 +++ b/test/basic\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
137 --- /dev/null\r
138 +++ b/test/random-corpus.c\r
139 @@ -0,0 +1,209 @@\r
140 +/*\r
141 + * Generate a random corpus of stub messages.\r
142 + *\r
143 + * Initial use case is testing dump and restore, so we only have\r
144 + * message-ids and tags.\r
145 + *\r
146 + * Generated message-id's and tags are intentionally nasty.\r
147 + *\r
148 + * Copyright (c) 2012 David Bremner\r
149 + *\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
154 + *\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
159 + *\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
162 + *\r
163 + * Author: David Bremner <david@tethera.net>\r
164 + */\r
165 +\r
166 +#include <stdlib.h>\r
167 +#include <assert.h>\r
168 +#include <talloc.h>\r
169 +#include <string.h>\r
170 +#include <glib.h>\r
171 +#include <math.h>\r
172 +\r
173 +#include "notmuch-client.h"\r
174 +#include "command-line-arguments.h"\r
175 +#include "database-test.h"\r
176 +\r
177 +/* Current largest Unicode value defined. Note that most of these will\r
178 + * be printed as boxes in most fonts.\r
179 + */\r
180 +\r
181 +#define GLYPH_MAX 0x10FFFE\r
182 +\r
183 +\r
184 +typedef struct {\r
185 +    int weight;\r
186 +    int start;\r
187 +    int stop;\r
188 +} char_class_t;\r
189 +\r
190 +/*\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
194 + *\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
197 + */\r
198 +\r
199 +static const\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
205 +\r
206 +static gunichar\r
207 +random_unichar ()\r
208 +{\r
209 +    int i;\r
210 +    int class = random () % GLYPH_MAX;\r
211 +    int size;\r
212 +\r
213 +    for (i = 0; char_class[i].weight < class; i++) /* nothing */;\r
214 +\r
215 +    size = char_class[i].stop - char_class[i].start + 1;\r
216 +\r
217 +    return char_class[i].start + (random () % size);\r
218 +}\r
219 +\r
220 +static char *\r
221 +random_utf8_string (void *ctx, size_t char_count)\r
222 +{\r
223 +    size_t offset = 0;\r
224 +    size_t i;\r
225 +    gchar *buf = NULL;\r
226 +    size_t buf_size = 0;\r
227 +\r
228 +    for (i = 0; i < char_count; i++) {\r
229 +       gunichar randomchar;\r
230 +       size_t written;\r
231 +\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
236 +       }\r
237 +\r
238 +       randomchar = random_unichar ();\r
239 +\r
240 +       written = g_unichar_to_utf8 (randomchar, buf + offset);\r
241 +\r
242 +       if (written <= 0) {\r
243 +           fprintf (stderr, "error converting to utf8\n");\r
244 +           exit (1);\r
245 +       }\r
246 +\r
247 +       offset += written;\r
248 +\r
249 +    }\r
250 +    buf[offset] = 0;\r
251 +    return buf;\r
252 +}\r
253 +\r
254 +\r
255 +int\r
256 +main (int argc, char **argv)\r
257 +{\r
258 +\r
259 +    void *ctx = talloc_new (NULL);\r
260 +\r
261 +    char *config_path  = NULL;\r
262 +    notmuch_config_t *config;\r
263 +    notmuch_database_t *notmuch;\r
264 +\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
272 +\r
273 +    int seed = 734569;\r
274 +\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
283 +    };\r
284 +\r
285 +    int opt_index = parse_arguments (argc, argv, options, 1);\r
286 +\r
287 +    if (opt_index < 0)\r
288 +       exit (1);\r
289 +\r
290 +    if (message_id_len < 1) {\r
291 +       fprintf (stderr, "message id's must be least length 1\n");\r
292 +       exit (1);\r
293 +    }\r
294 +\r
295 +    if (config_path == NULL) {\r
296 +       fprintf (stderr, "configuration path must be specified");\r
297 +       exit (1);\r
298 +    }\r
299 +\r
300 +    config = notmuch_config_open (ctx, config_path, NULL);\r
301 +    if (config == NULL)\r
302 +       return 1;\r
303 +\r
304 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
305 +                              NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
306 +       return 1;\r
307 +\r
308 +    srandom (seed);\r
309 +\r
310 +    int count;\r
311 +    for (count = 0; count < num_messages; count++) {\r
312 +       int j;\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
318 +       char *mid;\r
319 +       notmuch_status_t status;\r
320 +\r
321 +       do {\r
322 +           mid = random_utf8_string (ctx, this_mid_len);\r
323 +\r
324 +           tag_list = talloc_realloc (ctx, NULL, const char *, num_tags + 1);\r
325 +\r
326 +           for (j = 0; j < num_tags; j++) {\r
327 +               int this_tag_len = random () % tag_len + 1;\r
328 +\r
329 +               tag_list[j] = random_utf8_string (ctx, this_tag_len);\r
330 +           }\r
331 +\r
332 +           tag_list[j] = NULL;\r
333 +\r
334 +           status = notmuch_database_add_stub_message (notmuch, mid, tag_list);\r
335 +       } while (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID);\r
336 +\r
337 +       if (status != NOTMUCH_STATUS_SUCCESS) {\r
338 +           fprintf (stderr, "error %d adding message", status);\r
339 +           exit (status);\r
340 +       }\r
341 +    }\r
342 +\r
343 +    notmuch_database_destroy (notmuch);\r
344 +\r
345 +    talloc_free (ctx);\r
346 +\r
347 +    return 0;\r
348 +}\r
349 -- \r
350 1.7.10.4\r
351 \r