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 35ED5404519
\r
6 for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 17:40:59 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] 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 pDoyOFMgeBt3 for <notmuch@notmuchmail.org>;
\r
16 Sat, 14 Jan 2012 17:40:57 -0800 (PST)
\r
17 Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])
\r
18 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 0962B414395
\r
21 for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 17:40:51 -0800 (PST)
\r
22 Received: from zancas.localnet
\r
23 (fctnnbsc36w-156034076032.pppoe-dynamic.High-Speed.nb.bellaliant.net
\r
24 [156.34.76.32]) (authenticated bits=0)
\r
25 by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id q0F1egpI008575
\r
26 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);
\r
27 Sat, 14 Jan 2012 21:40:44 -0400
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.77)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1RmF5N-000434-Pa; Sat, 14 Jan 2012 21:40:41 -0400
\r
31 From: David Bremner <david@tethera.net>
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH v3 09/10] random-dump.c: new test-binary to generate dump
\r
35 Date: Sat, 14 Jan 2012 21:40:23 -0400
\r
36 Message-Id: <1326591624-15493-10-git-send-email-david@tethera.net>
\r
37 X-Mailer: git-send-email 1.7.7.3
\r
38 In-Reply-To: <1326591624-15493-1-git-send-email-david@tethera.net>
\r
39 References: <874nwxbkhr.fsf@zancas.localnet>
\r
40 <1326591624-15493-1-git-send-email-david@tethera.net>
\r
41 Cc: David Bremner <bremner@debian.org>
\r
42 X-BeenThere: notmuch@notmuchmail.org
\r
43 X-Mailman-Version: 2.1.13
\r
45 List-Id: "Use and development of the notmuch mail system."
\r
46 <notmuch.notmuchmail.org>
\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
50 List-Post: <mailto:notmuch@notmuchmail.org>
\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
53 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
54 X-List-Received-Date: Sun, 15 Jan 2012 01:40:59 -0000
\r
56 From: David Bremner <bremner@debian.org>
\r
58 This binary creates a "torture test" dump file for the new dump
\r
61 test/Makefile.local | 4 ++
\r
63 test/random-dump.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++
\r
64 3 files changed, 149 insertions(+), 1 deletions(-)
\r
65 create mode 100644 test/random-dump.c
\r
67 diff --git a/test/Makefile.local b/test/Makefile.local
\r
68 index ba697f4..b59f837 100644
\r
69 --- a/test/Makefile.local
\r
70 +++ b/test/Makefile.local
\r
71 @@ -16,6 +16,9 @@ $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a
\r
72 $(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a
\r
73 $(call quiet,CC) -I. $^ -o $@ -ltalloc
\r
75 +$(dir)/random-dump: $(dir)/random-dump.o command-line-arguments.o util/libutil.a
\r
76 + $(call quiet,CC) -I. $^ -o $@ -ltalloc -lm
\r
78 $(dir)/smtp-dummy: $(smtp_dummy_modules)
\r
79 $(call quiet,CC) $^ -o $@
\r
81 @@ -25,6 +28,7 @@ $(dir)/symbol-test: $(dir)/symbol-test.o
\r
84 test-binaries: $(dir)/arg-test $(dir)/hex-xcode \
\r
85 + $(dir)/random-dump \
\r
86 $(dir)/smtp-dummy $(dir)/symbol-test
\r
88 test: all test-binaries
\r
89 diff --git a/test/basic b/test/basic
\r
90 index af57026..e3a6cef 100755
\r
93 @@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'
\r
94 eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)
\r
95 tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)
\r
96 available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \
\r
97 - sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|hex-xcode)$/d" | \
\r
98 + sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|hex-xcode|random-dump)$/d" | \
\r
100 test_expect_equal "$tests_in_suite" "$available"
\r
102 diff --git a/test/random-dump.c b/test/random-dump.c
\r
103 new file mode 100644
\r
104 index 0000000..1949425
\r
106 +++ b/test/random-dump.c
\r
109 + Generate a random dump file in 'notmuch' format.
\r
110 + Generated message-id's and tags are intentionally nasty.
\r
112 + We restrict ourselves to 7 bit message-ids, because generating
\r
113 + random valid UTF-8 seems like work. And invalid UTF-8 can't be
\r
114 + round-tripped via Xapian.
\r
118 +#include <stdlib.h>
\r
119 +#include <assert.h>
\r
120 +#include <talloc.h>
\r
121 +#include <string.h>
\r
123 +#include "hex-escape.h"
\r
124 +#include "command-line-arguments.h"
\r
127 +hex_out (void *ctx, char *buf)
\r
129 + static char *encoded_buf = NULL;
\r
130 + static size_t encoded_buf_size = 0;
\r
132 + if (hex_encode (ctx, buf, &encoded_buf, &encoded_buf_size) != HEX_SUCCESS) {
\r
133 + fprintf (stderr, "Hex encoding failed");
\r
137 + fputs (encoded_buf, stdout);
\r
141 +random_chars (char *buf, int from, int stop, int max_char,
\r
142 + const char *blacklist)
\r
146 + for (i = from; i < stop; i++) {
\r
148 + buf[i] = ' ' + (random () % (max_char - ' '));
\r
149 + } while (blacklist && strchr (blacklist, buf[i]));
\r
154 +random_tag (void *ctx, size_t len)
\r
156 + static char *buf = NULL;
\r
157 + static size_t buf_len = 0;
\r
159 + int use = (random () % (len - 1)) + 1;
\r
161 + if (len > buf_len) {
\r
162 + buf = talloc_realloc (ctx, buf, char, len);
\r
166 + random_chars (buf, 0, use, 255, NULL);
\r
170 + hex_out (ctx, buf);
\r
174 +random_message_id (void *ctx, size_t len)
\r
176 + static char *buf = NULL;
\r
177 + static size_t buf_len = 0;
\r
179 + int lhs_len = (random () % (len / 2 - 1)) + 1;
\r
181 + int rhs_len = (random () % len / 2) + 1;
\r
183 + const char *blacklist = "\n\r@<>[]()";
\r
185 + if (len > buf_len) {
\r
186 + buf = talloc_realloc (ctx, buf, char, len);
\r
190 + random_chars (buf, 0, lhs_len, 127, blacklist);
\r
192 + buf[lhs_len] = '@';
\r
194 + random_chars (buf, lhs_len + 1, lhs_len + rhs_len + 1, 127, blacklist);
\r
196 + hex_out (ctx, buf);
\r
200 +main (int argc, char **argv)
\r
203 + void *ctx = talloc_new (NULL);
\r
204 + int num_lines = 500;
\r
205 + int max_tags = 10;
\r
206 + int message_id_len = 100;
\r
207 + int tag_len = 50;
\r
208 + int seed = 734569;
\r
210 + int pad_tag = 0, pad_mid = 0;
\r
212 + notmuch_opt_desc_t options[] = {
\r
213 + { NOTMUCH_OPT_INT, &num_lines, "num-lines", 'n', 0 },
\r
214 + { NOTMUCH_OPT_INT, &max_tags, "max-tags", 'm', 0 },
\r
215 + { NOTMUCH_OPT_INT, &message_id_len, "message-id-len", 'M', 0 },
\r
216 + { NOTMUCH_OPT_INT, &tag_len, "tag-len", 't', 0 },
\r
217 + { NOTMUCH_OPT_INT, &seed, "tag-len", 't', 0 },
\r
218 + { 0, 0, 0, 0, 0 }
\r
221 + int opt_index = parse_arguments (argc, argv, options, 1);
\r
223 + if (opt_index < 0)
\r
226 + pad_mid = ((int) log10 (num_lines) + 1);
\r
227 + pad_tag = ((int) log10 (max_tags)) + 1;
\r
232 + for (line = 0; line < num_lines; line++) {
\r
234 + printf ("%0*d-", pad_mid, line);
\r
236 + random_message_id (ctx, message_id_len);
\r
238 + int num_tags = random () % (max_tags + 1);
\r
241 + for (j = 0; j < num_tags; j++) {
\r
242 + printf (" %0*d-", pad_tag, j);
\r
243 + random_tag (ctx, tag_len);
\r
248 + talloc_free (ctx);
\r