diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-09-26 18:23:09 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-09-26 18:23:09 +0000 |
commit | dec04c01635f2d4f9187793320e2373821a0fe62 (patch) | |
tree | 91996602b281c01d559090a350821c4442454922 /src/regex | |
parent | 0ce690b643084839053f0d7f79fd23e2487271f6 (diff) | |
download | gnunet-dec04c01635f2d4f9187793320e2373821a0fe62.tar.gz gnunet-dec04c01635f2d4f9187793320e2373821a0fe62.zip |
- undo r28718
Diffstat (limited to 'src/regex')
-rw-r--r-- | src/regex/test_regex_iterate_api.c | 115 |
1 files changed, 36 insertions, 79 deletions
diff --git a/src/regex/test_regex_iterate_api.c b/src/regex/test_regex_iterate_api.c index 99652cb8b..69badb5d8 100644 --- a/src/regex/test_regex_iterate_api.c +++ b/src/regex/test_regex_iterate_api.c | |||
@@ -46,21 +46,16 @@ struct IteratorContext | |||
46 | int error; | 46 | int error; |
47 | int should_save_graph; | 47 | int should_save_graph; |
48 | FILE *graph_filep; | 48 | FILE *graph_filep; |
49 | unsigned int valid_string_count; | 49 | unsigned int string_count; |
50 | char *const *valid_strings; | 50 | char *const *strings; |
51 | unsigned int match_count; | 51 | unsigned int match_count; |
52 | unsigned int invalid_string_count; | ||
53 | char *const *invalid_strings; | ||
54 | unsigned int invalid_match_count; | ||
55 | }; | 52 | }; |
56 | 53 | ||
57 | struct RegexStringPair | 54 | struct RegexStringPair |
58 | { | 55 | { |
59 | char *regex; | 56 | char *regex; |
60 | unsigned int valid_string_count; | 57 | unsigned int string_count; |
61 | char *valid_strings[20]; | 58 | char *strings[20]; |
62 | unsigned int invalid_string_count; | ||
63 | char *invalid_strings[20]; | ||
64 | }; | 59 | }; |
65 | 60 | ||
66 | 61 | ||
@@ -102,19 +97,12 @@ key_iterator (void *cls, const struct GNUNET_HashCode *key, | |||
102 | transition_counter++; | 97 | transition_counter++; |
103 | } | 98 | } |
104 | 99 | ||
105 | for (i = 0; i < ctx->valid_string_count; i++) | 100 | for (i = 0; i < ctx->string_count; i++) |
106 | { | 101 | { |
107 | if (0 == strcmp (proof, ctx->valid_strings[i])) | 102 | if (0 == strcmp (proof, ctx->strings[i])) |
108 | ctx->match_count++; | 103 | ctx->match_count++; |
109 | } | 104 | } |
110 | 105 | ||
111 | for (i = 0; i < ctx->invalid_string_count; i++) | ||
112 | { | ||
113 | if (0 == strcmp (proof, ctx->invalid_strings[i])) { | ||
114 | ctx->invalid_match_count++; | ||
115 | } | ||
116 | } | ||
117 | |||
118 | if (GNUNET_OK != REGEX_BLOCK_check_proof (proof, strlen (proof), key)) | 106 | if (GNUNET_OK != REGEX_BLOCK_check_proof (proof, strlen (proof), key)) |
119 | { | 107 | { |
120 | ctx->error++; | 108 | ctx->error++; |
@@ -139,45 +127,36 @@ main (int argc, char *argv[]) | |||
139 | 127 | ||
140 | error = 0; | 128 | error = 0; |
141 | 129 | ||
142 | const struct RegexStringPair rxstr[14] = { | 130 | const struct RegexStringPair rxstr[13] = { |
143 | {INITIAL_PADDING "ab(c|d)+c*(a(b|c)+d)+(bla)+", 2, | 131 | {INITIAL_PADDING "ab(c|d)+c*(a(b|c)+d)+(bla)+", 2, |
144 | {INITIAL_PADDING "abcdcdca", INITIAL_PADDING "abcabdbl"}, 2, | 132 | {INITIAL_PADDING "abcdcdca", INITIAL_PADDING "abcabdbl"}}, |
145 | {INITIAL_PADDING, INITIAL_PADDING "ab"}}, | ||
146 | {INITIAL_PADDING | 133 | {INITIAL_PADDING |
147 | "abcdefghixxxxxxxxxxxxxjklmnop*qstoisdjfguisdfguihsdfgbdsuivggsd", 1, | 134 | "abcdefghixxxxxxxxxxxxxjklmnop*qstoisdjfguisdfguihsdfgbdsuivggsd", 1, |
148 | {INITIAL_PADDING "abcdefgh"}, 2, {INITIAL_PADDING, INITIAL_PADDING "a"}}, | 135 | {INITIAL_PADDING "abcdefgh"}}, |
149 | {INITIAL_PADDING "VPN-4-1(0|1)*", 2, | 136 | {INITIAL_PADDING "VPN-4-1(0|1)*", 2, |
150 | {INITIAL_PADDING "VPN-4-10", INITIAL_PADDING "VPN-4-11"}, | 137 | {INITIAL_PADDING "VPN-4-10", INITIAL_PADDING "VPN-4-11"}}, |
151 | 1, {INITIAL_PADDING}}, | ||
152 | {INITIAL_PADDING "(a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*)", 2, | 138 | {INITIAL_PADDING "(a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*)", 2, |
153 | {INITIAL_PADDING "aaaaaaaa", INITIAL_PADDING "aaXXyyyc"}}, | 139 | {INITIAL_PADDING "aaaaaaaa", INITIAL_PADDING "aaXXyyyc"}}, |
154 | {INITIAL_PADDING "a*", 2, {INITIAL_PADDING "aaaaaaaa", INITIAL_PADDING}}, | 140 | {INITIAL_PADDING "a*", 1, {INITIAL_PADDING "aaaaaaaa"}}, |
155 | {INITIAL_PADDING "xzxzxzxzxz", 1, {INITIAL_PADDING "xzxzxzxz"}, | 141 | {INITIAL_PADDING "xzxzxzxzxz", 1, {INITIAL_PADDING "xzxzxzxz"}}, |
156 | 1, {INITIAL_PADDING}}, | 142 | {INITIAL_PADDING "xyz*", 1, {INITIAL_PADDING "xyzzzzzz"}}, |
157 | {INITIAL_PADDING "xyz*", 1, {INITIAL_PADDING "xyzzzzzz"}, | ||
158 | 1, {INITIAL_PADDING}}, | ||
159 | {INITIAL_PADDING | 143 | {INITIAL_PADDING |
160 | "abcd:(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1):(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)", | 144 | "abcd:(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1):(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)", |
161 | 2, {INITIAL_PADDING "abcd:000", INITIAL_PADDING "abcd:101"}, | 145 | 2, {INITIAL_PADDING "abcd:000", INITIAL_PADDING "abcd:101"}}, |
162 | 1, {INITIAL_PADDING}}, | ||
163 | {INITIAL_PADDING "(x*|(0|1|2)(a|b|c|d)+)", 2, | 146 | {INITIAL_PADDING "(x*|(0|1|2)(a|b|c|d)+)", 2, |
164 | {INITIAL_PADDING "xxxxxxxx", INITIAL_PADDING "0abcdbad"}}, | 147 | {INITIAL_PADDING "xxxxxxxx", INITIAL_PADDING "0abcdbad"}}, |
165 | {INITIAL_PADDING "(0|1)(0|1)23456789ABC", 1, {INITIAL_PADDING "11234567"}, | 148 | {INITIAL_PADDING "(0|1)(0|1)23456789ABC", 1, {INITIAL_PADDING "11234567"}}, |
166 | 1, {INITIAL_PADDING}}, | ||
167 | {INITIAL_PADDING "0*123456789ABC*", 3, | 149 | {INITIAL_PADDING "0*123456789ABC*", 3, |
168 | {INITIAL_PADDING "00123456", INITIAL_PADDING "00000000", | 150 | {INITIAL_PADDING "00123456", INITIAL_PADDING "00000000", |
169 | INITIAL_PADDING "12345678"}}, | 151 | INITIAL_PADDING "12345678"}}, |
170 | {INITIAL_PADDING "0123456789A*BC", 1, {INITIAL_PADDING "01234567"}}, | 152 | {INITIAL_PADDING "0123456789A*BC", 1, {INITIAL_PADDING "01234567"}}, |
171 | {"GNUNETVPN000100000IPEX6-fc5a:4e1:c2ba::1", 1, {"GNUNETVPN000100000IPEX6-"}, | 153 | {"GNUNETVPN000100000IPEX6-fc5a:4e1:c2ba::1", 1, {"GNUNETVPN000100000IPEX6-"}} |
172 | 1, {INITIAL_PADDING}}, | ||
173 | {"my long prefix - hello world(0|1)*", 0, {"my long prefix - hello world"}, | ||
174 | 1, {"my long prefix"}} | ||
175 | }; | 154 | }; |
176 | 155 | ||
177 | const char *graph_start_str = "digraph G {\nrankdir=LR\n"; | 156 | const char *graph_start_str = "digraph G {\nrankdir=LR\n"; |
178 | const char *graph_end_str = "\n}\n"; | 157 | const char *graph_end_str = "\n}\n"; |
179 | 158 | ||
180 | for (i = 0; i < 14; i++) | 159 | for (i = 0; i < 13; i++) |
181 | { | 160 | { |
182 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating DFA for regex %s\n", | 161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating DFA for regex %s\n", |
183 | rxstr[i].regex); | 162 | rxstr[i].regex); |
@@ -209,36 +188,36 @@ main (int argc, char *argv[]) | |||
209 | } | 188 | } |
210 | 189 | ||
211 | /* Iterate over DFA edges */ | 190 | /* Iterate over DFA edges */ |
212 | ctx.valid_string_count = rxstr[i].valid_string_count; | 191 | transition_counter = 0; |
213 | ctx.valid_strings = rxstr[i].valid_strings; | 192 | ctx.string_count = rxstr[i].string_count; |
193 | ctx.strings = rxstr[i].strings; | ||
214 | ctx.match_count = 0; | 194 | ctx.match_count = 0; |
215 | ctx.invalid_string_count = rxstr[i].invalid_string_count; | ||
216 | ctx.invalid_strings = rxstr[i].invalid_strings; | ||
217 | ctx.invalid_match_count = 0; | ||
218 | dfa = | 195 | dfa = |
219 | REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 1); | 196 | REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0); |
220 | REGEX_INTERNAL_iterate_all_edges (dfa, key_iterator, &ctx); | 197 | REGEX_INTERNAL_iterate_all_edges (dfa, key_iterator, &ctx); |
198 | num_transitions = | ||
199 | REGEX_INTERNAL_get_transition_count (dfa) - dfa->start->transition_count; | ||
221 | 200 | ||
222 | if (0 != ctx.invalid_match_count) | 201 | if (transition_counter < num_transitions) |
223 | { | 202 | { |
224 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 203 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
225 | "Found invalid initial states for regex %s\n", | 204 | "Automaton has %d transitions, iterated over %d transitions\n", |
226 | rxstr[i].regex); | 205 | num_transitions, transition_counter); |
227 | error += ctx.invalid_match_count; | 206 | error += 1; |
228 | } | 207 | } |
229 | 208 | ||
230 | if (ctx.match_count < ctx.valid_string_count) | 209 | if (ctx.match_count < ctx.string_count) |
231 | { | 210 | { |
232 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 211 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
233 | "Missing initial states for regex %s\n", rxstr[i].regex); | 212 | "Missing initial states for regex %s\n", rxstr[i].regex); |
234 | error += (ctx.valid_string_count - ctx.match_count); | 213 | error += (ctx.string_count - ctx.match_count); |
235 | } | 214 | } |
236 | else if (ctx.match_count > ctx.valid_string_count) | 215 | else if (ctx.match_count > ctx.string_count) |
237 | { | 216 | { |
238 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 217 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
239 | "Duplicate initial transitions for regex %s\n", | 218 | "Duplicate initial transitions for regex %s\n", |
240 | rxstr[i].regex); | 219 | rxstr[i].regex); |
241 | error += (ctx.valid_string_count - ctx.match_count); | 220 | error += (ctx.string_count - ctx.match_count); |
242 | } | 221 | } |
243 | 222 | ||
244 | REGEX_INTERNAL_automaton_destroy (dfa); | 223 | REGEX_INTERNAL_automaton_destroy (dfa); |
@@ -254,44 +233,22 @@ main (int argc, char *argv[]) | |||
254 | } | 233 | } |
255 | 234 | ||
256 | 235 | ||
257 | for (i = 0; i < 14; i++) | 236 | for (i = 0; i < 13; i++) |
258 | { | 237 | { |
259 | transition_counter = 0; | 238 | ctx.string_count = rxstr[i].string_count; |
260 | ctx.valid_string_count = rxstr[i].valid_string_count; | 239 | ctx.strings = rxstr[i].strings; |
261 | ctx.valid_strings = rxstr[i].valid_strings; | ||
262 | ctx.match_count = 0; | 240 | ctx.match_count = 0; |
263 | ctx.invalid_string_count = rxstr[i].invalid_string_count; | ||
264 | ctx.invalid_strings = rxstr[i].invalid_strings; | ||
265 | ctx.invalid_match_count = 0; | ||
266 | 241 | ||
267 | dfa = | 242 | dfa = |
268 | REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0); | 243 | REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0); |
269 | REGEX_INTERNAL_dfa_add_multi_strides (NULL, dfa, 2); | 244 | REGEX_INTERNAL_dfa_add_multi_strides (NULL, dfa, 2); |
270 | REGEX_INTERNAL_iterate_all_edges (dfa, key_iterator, &ctx); | 245 | REGEX_INTERNAL_iterate_all_edges (dfa, key_iterator, &ctx); |
271 | num_transitions = | ||
272 | REGEX_INTERNAL_get_transition_count (dfa) - dfa->start->transition_count; | ||
273 | |||
274 | if (transition_counter < num_transitions) | ||
275 | { | ||
276 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
277 | "Automaton has %d transitions, iterated over %d transitions\n", | ||
278 | num_transitions, transition_counter); | ||
279 | error += 1; | ||
280 | } | ||
281 | 246 | ||
282 | if (ctx.match_count < ctx.valid_string_count) | 247 | if (ctx.match_count < ctx.string_count) |
283 | { | 248 | { |
284 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 249 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
285 | "Missing initial states for regex %s\n", rxstr[i].regex); | 250 | "Missing initial states for regex %s\n", rxstr[i].regex); |
286 | error += (ctx.valid_string_count - ctx.match_count); | 251 | error += (ctx.string_count - ctx.match_count); |
287 | } | ||
288 | |||
289 | if (0 != ctx.invalid_match_count) | ||
290 | { | ||
291 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
292 | "Found invalid initial states for regex %s\n", | ||
293 | rxstr[i].regex); | ||
294 | error += ctx.invalid_match_count; | ||
295 | } | 252 | } |
296 | 253 | ||
297 | REGEX_INTERNAL_automaton_destroy (dfa); | 254 | REGEX_INTERNAL_automaton_destroy (dfa); |