summaryrefslogtreecommitdiff
path: root/src/regex/perf-regex.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-02 14:38:54 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-02 14:38:54 +0000
commit15a8471c0edc4134f57c19884c033a63f49a04dd (patch)
tree4465bb0b1198f1869163706e6cfeeaba5ff3fabf /src/regex/perf-regex.c
parent2a453cf6aec60af36f655bd053847ab15ff7ae8f (diff)
downloadgnunet-15a8471c0edc4134f57c19884c033a63f49a04dd.tar.gz
gnunet-15a8471c0edc4134f57c19884c033a63f49a04dd.zip
-implementing regex test
Diffstat (limited to 'src/regex/perf-regex.c')
-rw-r--r--src/regex/perf-regex.c64
1 files changed, 29 insertions, 35 deletions
diff --git a/src/regex/perf-regex.c b/src/regex/perf-regex.c
index bf19a2bff..c2ec7441e 100644
--- a/src/regex/perf-regex.c
+++ b/src/regex/perf-regex.c
@@ -29,18 +29,12 @@
29#include "regex_internal_lib.h" 29#include "regex_internal_lib.h"
30#include "regex_test_lib.h" 30#include "regex_test_lib.h"
31 31
32static const char *exe;
33
34static void
35usage(void)
36{
37 fprintf (stderr, "Usage: %s REGEX_FILE COMPRESSION\n", exe);
38}
39 32
40/** 33/**
41 * Iterator callback function. 34 * Print information about the given node and its edges
35 * to stdout.
42 * 36 *
43 * @param cls closure. 37 * @param cls closure, unused.
44 * @param key hash for current state. 38 * @param key hash for current state.
45 * @param proof proof for current state. 39 * @param proof proof for current state.
46 * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not. 40 * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not.
@@ -48,28 +42,25 @@ usage(void)
48 * @param edges edges leaving current state. 42 * @param edges edges leaving current state.
49 */ 43 */
50static void 44static void
51iter (void *cls, 45print_edge (void *cls,
52 const struct GNUNET_HashCode *key, 46 const struct GNUNET_HashCode *key,
53 const char *proof, 47 const char *proof,
54 int accepting, 48 int accepting,
55 unsigned int num_edges, 49 unsigned int num_edges,
56 const struct REGEX_BLOCK_Edge *edges) 50 const struct REGEX_BLOCK_Edge *edges)
57{ 51{
58 unsigned int i; 52 unsigned int i;
59 53
60 printf ("%s: %s\n", GNUNET_h2s (key), accepting ? "ACCEPTING" : ""); 54 printf ("%s: %s, proof: `%s'\n",
61 printf (" proof: %s\n", proof); 55 GNUNET_h2s (key),
56 accepting ? "ACCEPTING" : "",
57 proof);
62 for (i = 0; i < num_edges; i++) 58 for (i = 0; i < num_edges; i++)
63 { 59 printf (" `%s': %s\n",
64 printf (" %s: %s\n", edges[i].label, GNUNET_h2s (&edges[i].destination)); 60 edges[i].label,
65 } 61 GNUNET_h2s (&edges[i].destination));
66} 62}
67 63
68static void
69print_dfa (struct REGEX_INTERNAL_Automaton* dfa)
70{
71 REGEX_INTERNAL_iterate_all_edges (dfa, iter, NULL);
72}
73 64
74/** 65/**
75 * The main function of the regex performace test. 66 * The main function of the regex performace test.
@@ -92,30 +83,33 @@ main (int argc, char *const *argv)
92 long size; 83 long size;
93 84
94 GNUNET_log_setup ("perf-regex", "DEBUG", NULL); 85 GNUNET_log_setup ("perf-regex", "DEBUG", NULL);
95 exe = argv[0];
96 if (3 != argc) 86 if (3 != argc)
97 { 87 {
98 usage(); 88 fprintf (stderr,
89 "Usage: %s REGEX_FILE COMPRESSION\n",
90 argv[0]);
99 return 1; 91 return 1;
100 } 92 }
101 regexes = REGEX_TEST_read_from_file (argv[1]); 93 regexes = REGEX_TEST_read_from_file (argv[1]);
102
103 if (NULL == regexes) 94 if (NULL == regexes)
104 { 95 {
105 usage(); 96 fprintf (stderr,
97 "Failed to read regexes from `%s'\n",
98 argv[1]);
106 return 2; 99 return 2;
107 } 100 }
108 buffer = REGEX_TEST_combine (regexes); 101 compression = atoi (argv[2]);
109 102
103 buffer = REGEX_TEST_combine (regexes);
110 GNUNET_asprintf (&regex, "GNVPN-0001-PAD(%s)(0|1)*", buffer); 104 GNUNET_asprintf (&regex, "GNVPN-0001-PAD(%s)(0|1)*", buffer);
111 size = strlen (regex); 105 size = strlen (regex);
112 106
113 fprintf (stderr, "Combined regex (%ld bytes):\n%s\n", size, regex); 107 fprintf (stderr,
114 // return 0; 108 "Combined regex (%ld bytes):\n%s\n",
115 109 size,
116 compression = atoi (argv[2]); 110 regex);
117 dfa = REGEX_INTERNAL_construct_dfa (regex, size, compression); 111 dfa = REGEX_INTERNAL_construct_dfa (regex, size, compression);
118 print_dfa (dfa); 112 REGEX_INTERNAL_iterate_all_edges (dfa, &print_edge, NULL);
119 REGEX_INTERNAL_automaton_destroy (dfa); 113 REGEX_INTERNAL_automaton_destroy (dfa);
120 GNUNET_free (buffer); 114 GNUNET_free (buffer);
121 REGEX_TEST_free_from_file (regexes); 115 REGEX_TEST_free_from_file (regexes);