diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-04-26 22:41:37 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-04-26 22:41:37 +0000 |
commit | f9ffcc7b14841e2c02c35942c5a39dcfbacc67ba (patch) | |
tree | fc740a469c8260418854451494c1c5e51a10926a /src/lockmanager | |
parent | 86396ee639168cd8ce34f6068545b2605682f081 (diff) | |
download | gnunet-f9ffcc7b14841e2c02c35942c5a39dcfbacc67ba.tar.gz gnunet-f9ffcc7b14841e2c02c35942c5a39dcfbacc67ba.zip |
-test cases setup for lockmanager
Diffstat (limited to 'src/lockmanager')
-rw-r--r-- | src/lockmanager/Makefile.am | 18 | ||||
-rw-r--r-- | src/lockmanager/gnunet-service-lockmanager.c | 4 | ||||
-rw-r--r-- | src/lockmanager/lockmanager.conf.in | 2 | ||||
-rw-r--r-- | src/lockmanager/lockmanager_api.c | 22 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api.c | 141 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api.conf | 73 |
6 files changed, 250 insertions, 10 deletions
diff --git a/src/lockmanager/Makefile.am b/src/lockmanager/Makefile.am index d6e3a5e4e..f86ac72a5 100644 --- a/src/lockmanager/Makefile.am +++ b/src/lockmanager/Makefile.am | |||
@@ -35,4 +35,20 @@ libgnunetlockmanager_la_LIBADD = \ | |||
35 | $(XLIB) | 35 | $(XLIB) |
36 | libgnunetlockmanager_la_LDFLAGS = \ | 36 | libgnunetlockmanager_la_LDFLAGS = \ |
37 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ | 37 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ |
38 | -version-info 0:0:0 \ No newline at end of file | 38 | -version-info 0:0:0 |
39 | |||
40 | check_PROGRAMS = \ | ||
41 | test-lockmanager-api | ||
42 | |||
43 | EXTRA_DIST = \ | ||
44 | test_lockmanager_api.conf | ||
45 | |||
46 | if ENABLE_TEST_RUN | ||
47 | TESTS = $(check_PROGRAMS) | ||
48 | endif | ||
49 | |||
50 | test_lockmanager_api_SOURCES = \ | ||
51 | test_lockmanager_api.c | ||
52 | test_lockmanager_api_LDADD = \ | ||
53 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
54 | libgnunetlockmanager.la | ||
diff --git a/src/lockmanager/gnunet-service-lockmanager.c b/src/lockmanager/gnunet-service-lockmanager.c index 1c228cc3a..5735f65b1 100644 --- a/src/lockmanager/gnunet-service-lockmanager.c +++ b/src/lockmanager/gnunet-service-lockmanager.c | |||
@@ -105,7 +105,7 @@ int main (int argc, char *const *argv) | |||
105 | { | 105 | { |
106 | int ret; | 106 | int ret; |
107 | 107 | ||
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main()\n"); | 108 | LOG (GNUNET_ERROR_TYPE_DEBUG, "main()\n"); |
109 | ret = | 109 | ret = |
110 | (GNUNET_OK == | 110 | (GNUNET_OK == |
111 | GNUNET_SERVICE_run (argc, | 111 | GNUNET_SERVICE_run (argc, |
@@ -114,6 +114,6 @@ int main (int argc, char *const *argv) | |||
114 | GNUNET_SERVICE_OPTION_NONE, | 114 | GNUNET_SERVICE_OPTION_NONE, |
115 | &lockmanager_run, | 115 | &lockmanager_run, |
116 | NULL)) ? 0 : 1; | 116 | NULL)) ? 0 : 1; |
117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main() END\n"); | 117 | LOG (GNUNET_ERROR_TYPE_DEBUG, "main() END\n"); |
118 | return ret; | 118 | return ret; |
119 | } | 119 | } |
diff --git a/src/lockmanager/lockmanager.conf.in b/src/lockmanager/lockmanager.conf.in index 6a91b3e25..75b9244dc 100644 --- a/src/lockmanager/lockmanager.conf.in +++ b/src/lockmanager/lockmanager.conf.in | |||
@@ -4,7 +4,7 @@ AUTOSTART = YES | |||
4 | HOSTNAME = localhost | 4 | HOSTNAME = localhost |
5 | HOME = $SERVICEHOME | 5 | HOME = $SERVICEHOME |
6 | CONFIG = $DEFAULTCONFIG | 6 | CONFIG = $DEFAULTCONFIG |
7 | BINARY = gnunet-service-lockmanger | 7 | BINARY = gnunet-service-lockmanager |
8 | ACCEPT_FROM = 127.0.0.1; | 8 | ACCEPT_FROM = 127.0.0.1; |
9 | ACCEPT_FROM6 = ::1; | 9 | ACCEPT_FROM6 = ::1; |
10 | UNIXPATH = /tmp/gnunet-service-lockmanager.sock | 10 | UNIXPATH = /tmp/gnunet-service-lockmanager.sock |
diff --git a/src/lockmanager/lockmanager_api.c b/src/lockmanager/lockmanager_api.c index 311f43b0f..bfd06275c 100644 --- a/src/lockmanager/lockmanager_api.c +++ b/src/lockmanager/lockmanager_api.c | |||
@@ -130,7 +130,7 @@ handle_server_crash (void *cls, | |||
130 | const struct GNUNET_MessageHeader *msg) | 130 | const struct GNUNET_MessageHeader *msg) |
131 | { | 131 | { |
132 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 132 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
133 | "Lockmanger service went down\n"); | 133 | "Lockmanager service not available or went down\n"); |
134 | 134 | ||
135 | } | 135 | } |
136 | 136 | ||
@@ -179,11 +179,13 @@ GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
179 | { | 179 | { |
180 | struct GNUNET_LOCKMANAGER_Handle *h; | 180 | struct GNUNET_LOCKMANAGER_Handle *h; |
181 | 181 | ||
182 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); | ||
182 | h = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_Handle)); | 183 | h = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_Handle)); |
183 | h->conn = GNUNET_CLIENT_connect ("lockmanager", cfg); | 184 | h->conn = GNUNET_CLIENT_connect ("lockmanager", cfg); |
184 | if (NULL == h->conn) | 185 | if (NULL == h->conn) |
185 | { | 186 | { |
186 | GNUNET_free (h); | 187 | GNUNET_free (h); |
188 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | ||
187 | return NULL; | 189 | return NULL; |
188 | } | 190 | } |
189 | 191 | ||
@@ -192,10 +194,13 @@ GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
192 | NULL, | 194 | NULL, |
193 | GNUNET_TIME_UNIT_FOREVER_REL); | 195 | GNUNET_TIME_UNIT_FOREVER_REL); |
194 | 196 | ||
195 | GNUNET_CLIENT_receive (h->conn, | 197 | /* FIXME: Assertions fail in client.c if trying to receive multiple messages */ |
196 | &handle_success, | 198 | /* GNUNET_CLIENT_receive (h->conn, */ |
197 | h, | 199 | /* &handle_success, */ |
198 | GNUNET_TIME_UNIT_FOREVER_REL); | 200 | /* h, */ |
201 | /* GNUNET_TIME_UNIT_FOREVER_REL); */ | ||
202 | |||
203 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | ||
199 | return h; | 204 | return h; |
200 | } | 205 | } |
201 | 206 | ||
@@ -208,8 +213,10 @@ GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
208 | void | 213 | void |
209 | GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle) | 214 | GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle) |
210 | { | 215 | { |
216 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); | ||
211 | GNUNET_CLIENT_disconnect (handle->conn); | 217 | GNUNET_CLIENT_disconnect (handle->conn); |
212 | GNUNET_free (handle); | 218 | GNUNET_free (handle); |
219 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | ||
213 | } | 220 | } |
214 | 221 | ||
215 | 222 | ||
@@ -249,7 +256,7 @@ GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle, | |||
249 | struct GNUNET_LOCKMANAGER_Message *msg; | 256 | struct GNUNET_LOCKMANAGER_Message *msg; |
250 | uint16_t msg_size; | 257 | uint16_t msg_size; |
251 | 258 | ||
252 | 259 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); | |
253 | r = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_LockingRequest)); | 260 | r = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_LockingRequest)); |
254 | r->domain_name_length = strlen (domain_name) + 1; | 261 | r->domain_name_length = strlen (domain_name) + 1; |
255 | r->handle = handle; | 262 | r->handle = handle; |
@@ -271,6 +278,7 @@ GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle, | |||
271 | GNUNET_NO, | 278 | GNUNET_NO, |
272 | *transmit_notify, | 279 | *transmit_notify, |
273 | msg); | 280 | msg); |
281 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | ||
274 | return r; | 282 | return r; |
275 | } | 283 | } |
276 | 284 | ||
@@ -288,6 +296,7 @@ void | |||
288 | GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest | 296 | GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest |
289 | *request) | 297 | *request) |
290 | { | 298 | { |
299 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); | ||
291 | /* FIXME: Stop ACQUIRE retransmissions */ | 300 | /* FIXME: Stop ACQUIRE retransmissions */ |
292 | if (GNUNET_LOCKMANAGER_SUCCESS == request->status) | 301 | if (GNUNET_LOCKMANAGER_SUCCESS == request->status) |
293 | { | 302 | { |
@@ -309,5 +318,6 @@ GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest | |||
309 | &transmit_notify, | 318 | &transmit_notify, |
310 | msg); | 319 | msg); |
311 | } | 320 | } |
321 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | ||
312 | GNUNET_free (request); | 322 | GNUNET_free (request); |
313 | } | 323 | } |
diff --git a/src/lockmanager/test_lockmanager_api.c b/src/lockmanager/test_lockmanager_api.c new file mode 100644 index 000000000..144f7b43c --- /dev/null +++ b/src/lockmanager/test_lockmanager_api.c | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 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 2, 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 | /** | ||
22 | * @file lockmanager/test_lockmanager_api.c | ||
23 | * @brief Test cases for lockmanager_api.c | ||
24 | * @author Sree Harsha Totakura | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_lockmanager_service.h" | ||
30 | |||
31 | #define VERBOSE 1 | ||
32 | |||
33 | #define VERBOSE_ARM 1 | ||
34 | |||
35 | #define LOG(kind,...) \ | ||
36 | GNUNET_log_from (kind, "test-lockmanager-api",__VA_ARGS__) | ||
37 | |||
38 | #define TIME_REL_SECONDS(min) \ | ||
39 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min) | ||
40 | |||
41 | /** | ||
42 | * The testing result | ||
43 | */ | ||
44 | static int result; | ||
45 | |||
46 | /** | ||
47 | * The process id of the GNUNET ARM process | ||
48 | */ | ||
49 | static struct GNUNET_OS_Process *arm_pid = NULL; | ||
50 | |||
51 | /** | ||
52 | * Configuration Handle | ||
53 | */ | ||
54 | struct GNUNET_CONFIGURATION_Handle *config; | ||
55 | |||
56 | /** | ||
57 | * Testing function | ||
58 | * | ||
59 | * @param cls NULL | ||
60 | * @param tc the task context | ||
61 | */ | ||
62 | static void | ||
63 | test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
64 | { | ||
65 | struct GNUNET_LOCKMANAGER_Handle *handle; | ||
66 | |||
67 | handle = GNUNET_LOCKMANAGER_connect (config); | ||
68 | GNUNET_assert (NULL != handle); | ||
69 | |||
70 | GNUNET_LOCKMANAGER_disconnect (handle); | ||
71 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) | ||
72 | { | ||
73 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
74 | "Kill gnunet-service-arm manually\n"); | ||
75 | } | ||
76 | GNUNET_OS_process_wait (arm_pid); | ||
77 | GNUNET_OS_process_close (arm_pid); | ||
78 | result = GNUNET_OK; | ||
79 | } | ||
80 | |||
81 | |||
82 | /** | ||
83 | * Main point of test execution | ||
84 | */ | ||
85 | static void | ||
86 | run (void *cls, char *const *args, const char *cfgfile, | ||
87 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
88 | { | ||
89 | config = GNUNET_CONFIGURATION_dup (cfg); | ||
90 | arm_pid = | ||
91 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
92 | "gnunet-service-arm", | ||
93 | #if VERBOSE_ARM | ||
94 | "-L", "DEBUG", | ||
95 | #endif | ||
96 | "-c", "test_lockmanager_api.conf", NULL); | ||
97 | |||
98 | GNUNET_assert (NULL != arm_pid); | ||
99 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), | ||
100 | &test, | ||
101 | NULL); | ||
102 | } | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Main function | ||
107 | */ | ||
108 | int main (int argc, char **argv) | ||
109 | { | ||
110 | int ret; | ||
111 | |||
112 | char *const argv2[] = { "test-lockmanager-api", | ||
113 | "-c", "test_lockmanager_api.conf", | ||
114 | #if VERBOSE | ||
115 | "-L", "DEBUG", | ||
116 | #endif | ||
117 | NULL | ||
118 | }; | ||
119 | |||
120 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
121 | GNUNET_GETOPT_OPTION_END | ||
122 | }; | ||
123 | |||
124 | ret = | ||
125 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | ||
126 | "test-lockmanager-api", "nohelp", options, &run, NULL); | ||
127 | |||
128 | if (GNUNET_OK != ret) | ||
129 | { | ||
130 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n", | ||
131 | ret); | ||
132 | return 1; | ||
133 | } | ||
134 | if (GNUNET_SYSERR == result) | ||
135 | { | ||
136 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test failed\n"); | ||
137 | return 1; | ||
138 | } | ||
139 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test ok\n"); | ||
140 | return 0; | ||
141 | } | ||
diff --git a/src/lockmanager/test_lockmanager_api.conf b/src/lockmanager/test_lockmanager_api.conf new file mode 100644 index 000000000..b6a291730 --- /dev/null +++ b/src/lockmanager/test_lockmanager_api.conf | |||
@@ -0,0 +1,73 @@ | |||
1 | [lockmanager] | ||
2 | DEBUG = YES | ||
3 | AUTOSTART = YES | ||
4 | PORT = 12112 | ||
5 | ACCEPT_FROM = 127.0.0.1; | ||
6 | HOSTNAME = localhost | ||
7 | # PREFIX = valgrind --leak-check=full | ||
8 | # PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args | ||
9 | |||
10 | [fs] | ||
11 | AUTOSTART = NO | ||
12 | |||
13 | [resolver] | ||
14 | AUTOSTART = NO | ||
15 | |||
16 | [mesh] | ||
17 | AUTOSTART = NO | ||
18 | |||
19 | [dht] | ||
20 | AUTOSTART = NO | ||
21 | |||
22 | [block] | ||
23 | plugins = dht test | ||
24 | |||
25 | [dhtcache] | ||
26 | QUOTA = 1 MB | ||
27 | DATABASE = sqlite | ||
28 | |||
29 | [transport] | ||
30 | PLUGINS = tcp | ||
31 | DEBUG = NO | ||
32 | ACCEPT_FROM6 = ::1; | ||
33 | ACCEPT_FROM = 127.0.0.1; | ||
34 | NEIGHBOUR_LIMIT = 50 | ||
35 | PORT = 12365 | ||
36 | |||
37 | [ats] | ||
38 | WAN_QUOTA_OUT = 3932160 | ||
39 | WAN_QUOTA_IN = 3932160 | ||
40 | |||
41 | [core] | ||
42 | PORT = 12092 | ||
43 | |||
44 | [arm] | ||
45 | DEFAULTSERVICES = core lockmanager | ||
46 | PORT = 12366 | ||
47 | DEBUG = NO | ||
48 | |||
49 | [transport-tcp] | ||
50 | TIMEOUT = 300 s | ||
51 | PORT = 12368 | ||
52 | |||
53 | [TESTING] | ||
54 | NUM_PEERS = 5 | ||
55 | WEAKRANDOM = YES | ||
56 | DEBUG = YES | ||
57 | HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat | ||
58 | MAX_CONCURRENT_SSH = 10 | ||
59 | USE_PROGRESSBARS = YES | ||
60 | PEERGROUP_TIMEOUT = 2400 s | ||
61 | |||
62 | [gnunetd] | ||
63 | HOSTKEY = $SERVICEHOME/.hostkey | ||
64 | |||
65 | [PATHS] | ||
66 | DEFAULTCONFIG = test_lockmanager_api.conf | ||
67 | SERVICEHOME = /tmp/test-lockmanager/ | ||
68 | |||
69 | [dns] | ||
70 | AUTOSTART = NO | ||
71 | |||
72 | [nse] | ||
73 | AUTOSTART = NO | ||