diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-05-22 12:03:07 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-05-22 12:03:07 +0000 |
commit | 157f7872646546aa956e36b3c3629eed00013f45 (patch) | |
tree | 312a4a7d6cb364b231113b7011e64c5dc27b86e6 /src/regex | |
parent | f1593742051929aea7f86175b4af11ef45f3d481 (diff) | |
download | gnunet-157f7872646546aa956e36b3c3629eed00013f45.tar.gz gnunet-157f7872646546aa956e36b3c3629eed00013f45.zip |
-adding integration test
Diffstat (limited to 'src/regex')
-rw-r--r-- | src/regex/Makefile.am | 23 | ||||
-rw-r--r-- | src/regex/regex.conf.in | 2 | ||||
-rw-r--r-- | src/regex/test_regex_integration.c | 185 |
3 files changed, 202 insertions, 8 deletions
diff --git a/src/regex/Makefile.am b/src/regex/Makefile.am index 78324042d..43555cf72 100644 --- a/src/regex/Makefile.am +++ b/src/regex/Makefile.am | |||
@@ -31,7 +31,7 @@ gnunet_service_regex_LDADD = -lm \ | |||
31 | $(top_builddir)/src/dht/libgnunetdht.la \ | 31 | $(top_builddir)/src/dht/libgnunetdht.la \ |
32 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 32 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
33 | $(top_builddir)/src/util/libgnunetutil.la \ | 33 | $(top_builddir)/src/util/libgnunetutil.la \ |
34 | $(GN_LIBINTL) | 34 | $(GN_LIBINTL) |
35 | 35 | ||
36 | noinst_LIBRARIES = \ | 36 | noinst_LIBRARIES = \ |
37 | libgnunetregex_internal.a \ | 37 | libgnunetregex_internal.a \ |
@@ -64,7 +64,7 @@ libgnunetregex_internal_a_DEPENDENCIES = \ | |||
64 | libgnunetregex_la_SOURCES = \ | 64 | libgnunetregex_la_SOURCES = \ |
65 | regex_api.c regex_ipc.h | 65 | regex_api.c regex_ipc.h |
66 | libgnunetregex_la_LIBADD = \ | 66 | libgnunetregex_la_LIBADD = \ |
67 | $(top_builddir)/src/util/libgnunetutil.la | 67 | $(top_builddir)/src/util/libgnunetutil.la |
68 | libgnunetregex_la_LDFLAGS = \ | 68 | libgnunetregex_la_LDFLAGS = \ |
69 | $(GN_LIB_LDFLAGS) \ | 69 | $(GN_LIB_LDFLAGS) \ |
70 | -version-info 3:1:0 | 70 | -version-info 3:1:0 |
@@ -92,13 +92,13 @@ gnunet_regex_simulation_profiler_LDADD = \ | |||
92 | $(top_builddir)/src/util/libgnunetutil.la \ | 92 | $(top_builddir)/src/util/libgnunetutil.la \ |
93 | libgnunetregex_internal.a \ | 93 | libgnunetregex_internal.a \ |
94 | $(top_builddir)/src/dht/libgnunetdht.la \ | 94 | $(top_builddir)/src/dht/libgnunetdht.la \ |
95 | $(top_builddir)/src/mysql/libgnunetmysql.la | 95 | $(top_builddir)/src/mysql/libgnunetmysql.la |
96 | endif | 96 | endif |
97 | 97 | ||
98 | libgnunetregextest_a_SOURCES = \ | 98 | libgnunetregextest_a_SOURCES = \ |
99 | regex_test_lib.c regex_test_lib.h \ | 99 | regex_test_lib.c regex_test_lib.h \ |
100 | regex_test_graph.c \ | 100 | regex_test_graph.c \ |
101 | regex_test_random.c | 101 | regex_test_random.c |
102 | libgnunetregextest_a_LIBADD = \ | 102 | libgnunetregextest_a_LIBADD = \ |
103 | $(top_builddir)/src/util/libgnunetutil.la \ | 103 | $(top_builddir)/src/util/libgnunetutil.la \ |
104 | libgnunetregex_internal.a | 104 | libgnunetregex_internal.a |
@@ -116,7 +116,7 @@ perf_regex_LDADD = -lm \ | |||
116 | $(top_builddir)/src/dht/libgnunetdht.la \ | 116 | $(top_builddir)/src/dht/libgnunetdht.la \ |
117 | libgnunetregexblock.la \ | 117 | libgnunetregexblock.la \ |
118 | libgnunetregextest.a \ | 118 | libgnunetregextest.a \ |
119 | $(top_builddir)/src/util/libgnunetutil.la | 119 | $(top_builddir)/src/util/libgnunetutil.la |
120 | 120 | ||
121 | gnunet_regex_profiler_SOURCES = \ | 121 | gnunet_regex_profiler_SOURCES = \ |
122 | gnunet-regex-profiler.c | 122 | gnunet-regex-profiler.c |
@@ -128,7 +128,7 @@ gnunet_regex_profiler_LDADD = -lm \ | |||
128 | libgnunetregexblock.la \ | 128 | libgnunetregexblock.la \ |
129 | libgnunetregextest.a \ | 129 | libgnunetregextest.a \ |
130 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 130 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
131 | $(top_builddir)/src/util/libgnunetutil.la | 131 | $(top_builddir)/src/util/libgnunetutil.la |
132 | 132 | ||
133 | gnunet_daemon_regexprofiler_SOURCES = \ | 133 | gnunet_daemon_regexprofiler_SOURCES = \ |
134 | gnunet-daemon-regexprofiler.c | 134 | gnunet-daemon-regexprofiler.c |
@@ -138,9 +138,10 @@ gnunet_daemon_regexprofiler_LDADD = -lm \ | |||
138 | libgnunetregexblock.la \ | 138 | libgnunetregexblock.la \ |
139 | libgnunetregextest.a \ | 139 | libgnunetregextest.a \ |
140 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 140 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
141 | $(top_builddir)/src/util/libgnunetutil.la | 141 | $(top_builddir)/src/util/libgnunetutil.la |
142 | 142 | ||
143 | check_PROGRAMS = \ | 143 | check_PROGRAMS = \ |
144 | test_regex_integration \ | ||
144 | test_regex_eval_api \ | 145 | test_regex_eval_api \ |
145 | test_regex_iterate_api \ | 146 | test_regex_iterate_api \ |
146 | test_regex_proofs \ | 147 | test_regex_proofs \ |
@@ -161,6 +162,14 @@ test_regex_eval_api_LDADD = -lm \ | |||
161 | libgnunetregexblock.la \ | 162 | libgnunetregexblock.la \ |
162 | $(top_builddir)/src/util/libgnunetutil.la | 163 | $(top_builddir)/src/util/libgnunetutil.la |
163 | 164 | ||
165 | test_regex_integration_SOURCES = \ | ||
166 | test_regex_integration.c | ||
167 | test_regex_integration_LDADD = -lm \ | ||
168 | libgnunetregex.la \ | ||
169 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
170 | $(top_builddir)/src/tun/libgnunettun.la \ | ||
171 | $(top_builddir)/src/util/libgnunetutil.la | ||
172 | |||
164 | test_regex_api_SOURCES = \ | 173 | test_regex_api_SOURCES = \ |
165 | test_regex_api.c | 174 | test_regex_api.c |
166 | test_regex_api_LDADD = -lm \ | 175 | test_regex_api_LDADD = -lm \ |
diff --git a/src/regex/regex.conf.in b/src/regex/regex.conf.in index 8a75881f9..bc574da58 100644 --- a/src/regex/regex.conf.in +++ b/src/regex/regex.conf.in | |||
@@ -1,6 +1,6 @@ | |||
1 | [regex] | 1 | [regex] |
2 | AUTOSTART = @AUTOSTART@ | 2 | AUTOSTART = @AUTOSTART@ |
3 | @UNIXONLY@ PORT = 2107 | 3 | PORT = 2107 |
4 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-regex.sock | 4 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-regex.sock |
5 | HOSTNAME = localhost | 5 | HOSTNAME = localhost |
6 | BINARY = gnunet-service-regex | 6 | BINARY = gnunet-service-regex |
diff --git a/src/regex/test_regex_integration.c b/src/regex/test_regex_integration.c new file mode 100644 index 000000000..734b1c604 --- /dev/null +++ b/src/regex/test_regex_integration.c | |||
@@ -0,0 +1,185 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2013, 2015 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file regex/test_regex_integration.c | ||
22 | * @brief base test case for regex integration with VPN; | ||
23 | * tests that the regexes generated by the TUN API | ||
24 | * for IP addresses work (for some simple cases) | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_tun_lib.h" | ||
30 | #include "gnunet_testing_lib.h" | ||
31 | #include "gnunet_regex_service.h" | ||
32 | |||
33 | |||
34 | /** | ||
35 | * How long until we really give up on a particular testcase portion? | ||
36 | */ | ||
37 | #define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600) | ||
38 | |||
39 | /** | ||
40 | * How long until we give up on any particular operation (and retry)? | ||
41 | */ | ||
42 | #define BASE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) | ||
43 | |||
44 | |||
45 | static struct GNUNET_REGEX_Announcement *a4; | ||
46 | |||
47 | static struct GNUNET_REGEX_Search *s4; | ||
48 | |||
49 | static struct GNUNET_REGEX_Announcement *a6; | ||
50 | |||
51 | static struct GNUNET_REGEX_Search *s6; | ||
52 | |||
53 | static int ok = 1; | ||
54 | |||
55 | static struct GNUNET_SCHEDULER_Task *die_task; | ||
56 | |||
57 | |||
58 | static void | ||
59 | end (void *cls, | ||
60 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
61 | { | ||
62 | die_task = NULL; | ||
63 | GNUNET_REGEX_announce_cancel (a4); | ||
64 | a4 = NULL; | ||
65 | GNUNET_REGEX_search_cancel (s4); | ||
66 | s4 = NULL; | ||
67 | GNUNET_REGEX_announce_cancel (a6); | ||
68 | a6 = NULL; | ||
69 | GNUNET_REGEX_search_cancel (s6); | ||
70 | s6 = NULL; | ||
71 | ok = 0; | ||
72 | } | ||
73 | |||
74 | |||
75 | static void | ||
76 | end_badly () | ||
77 | { | ||
78 | die_task = NULL; | ||
79 | FPRINTF (stderr, "%s", "Testcase failed (timeout).\n"); | ||
80 | end (NULL, NULL); | ||
81 | ok = 1; | ||
82 | } | ||
83 | |||
84 | |||
85 | /** | ||
86 | * Search callback function, invoked for every result that was found. | ||
87 | * | ||
88 | * @param cls Closure provided in GNUNET_REGEX_search. | ||
89 | * @param id Peer providing a regex that matches the string. | ||
90 | * @param get_path Path of the get request. | ||
91 | * @param get_path_length Length of @a get_path. | ||
92 | * @param put_path Path of the put request. | ||
93 | * @param put_path_length Length of the @a put_path. | ||
94 | */ | ||
95 | static void | ||
96 | found_cb (void *cls, | ||
97 | const struct GNUNET_PeerIdentity *id, | ||
98 | const struct GNUNET_PeerIdentity *get_path, | ||
99 | unsigned int get_path_length, | ||
100 | const struct GNUNET_PeerIdentity *put_path, | ||
101 | unsigned int put_path_length) | ||
102 | { | ||
103 | const char *str = cls; | ||
104 | static int found; | ||
105 | |||
106 | fprintf (stderr, | ||
107 | "IPv%s-exit found\n", | ||
108 | str); | ||
109 | if (0 == strcmp (str, "4")) | ||
110 | found |= 4; | ||
111 | if (0 == strcmp (str, "6")) | ||
112 | found |= 2; | ||
113 | if ((4|2) == found) | ||
114 | { | ||
115 | GNUNET_SCHEDULER_cancel (die_task); | ||
116 | die_task = | ||
117 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | |||
122 | static void | ||
123 | run (void *cls, | ||
124 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
125 | struct GNUNET_TESTING_Peer *peer) | ||
126 | { | ||
127 | char rxstr4[GNUNET_TUN_IPV4_REGEXLEN]; | ||
128 | char rxstr6[GNUNET_TUN_IPV4_REGEXLEN]; | ||
129 | char *p4; | ||
130 | char *p6; | ||
131 | struct in_addr i4; | ||
132 | struct in6_addr i6; | ||
133 | |||
134 | die_task = | ||
135 | GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, | ||
136 | &end_badly, NULL); | ||
137 | GNUNET_assert (1 == | ||
138 | inet_pton (AF_INET, | ||
139 | "127.0.0.1", | ||
140 | &i4)); | ||
141 | GNUNET_assert (1 == | ||
142 | inet_pton (AF_INET6, | ||
143 | "::1:5", | ||
144 | &i6)); | ||
145 | GNUNET_TUN_ipv4toregexsearch (&i4, | ||
146 | 8080, | ||
147 | rxstr4); | ||
148 | GNUNET_TUN_ipv6toregexsearch (&i6, | ||
149 | 8686, | ||
150 | rxstr6); | ||
151 | p4 = GNUNET_TUN_ipv4policy2regex ("0.0.0.0/0:!25;"); | ||
152 | p6 = GNUNET_TUN_ipv6policy2regex ("::/0:!25;"); | ||
153 | a4 = GNUNET_REGEX_announce (cfg, | ||
154 | p4, | ||
155 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
156 | 5), | ||
157 | 1); | ||
158 | a6 = GNUNET_REGEX_announce (cfg, | ||
159 | p6, | ||
160 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
161 | 5), | ||
162 | 1); | ||
163 | GNUNET_free (p4); | ||
164 | GNUNET_free (p6); | ||
165 | |||
166 | s4 = GNUNET_REGEX_search (cfg, | ||
167 | rxstr4, | ||
168 | &found_cb, "4"); | ||
169 | s6 = GNUNET_REGEX_search (cfg, | ||
170 | rxstr6, | ||
171 | &found_cb, "6"); | ||
172 | } | ||
173 | |||
174 | |||
175 | int | ||
176 | main (int argc, char *argv[]) | ||
177 | { | ||
178 | if (0 != GNUNET_TESTING_peer_run ("test-regex-integration", | ||
179 | "test_regex_api_data.conf", | ||
180 | &run, NULL)) | ||
181 | return 1; | ||
182 | return ok; | ||
183 | } | ||
184 | |||
185 | /* end of test_regex_integration.c */ | ||