diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-06-20 19:24:26 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-06-20 19:24:26 +0000 |
commit | 48cc55589e0ba907fc2d50c5fbb42692a0bdba3e (patch) | |
tree | 1aeff3421f800c121d5edc6d4d5dd6b4b5ef6eab /src/lockmanager | |
parent | a108a1ec6a4b299f3a6db7d9bb0a507188a2d0bb (diff) | |
download | gnunet-48cc55589e0ba907fc2d50c5fbb42692a0bdba3e.tar.gz gnunet-48cc55589e0ba907fc2d50c5fbb42692a0bdba3e.zip |
lockmanager testcase new testing library
Diffstat (limited to 'src/lockmanager')
-rw-r--r-- | src/lockmanager/Makefile.am | 3 | ||||
-rw-r--r-- | src/lockmanager/gnunet-service-lockmanager.c | 2 | ||||
-rw-r--r-- | src/lockmanager/lockmanager_api.c | 2 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api.c | 4 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api_acquireretry.c | 105 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api_lockrelease.c | 111 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api_servercrash.c | 127 |
7 files changed, 81 insertions, 273 deletions
diff --git a/src/lockmanager/Makefile.am b/src/lockmanager/Makefile.am index bf2ad5d38..b1743e308 100644 --- a/src/lockmanager/Makefile.am +++ b/src/lockmanager/Makefile.am | |||
@@ -62,16 +62,19 @@ test_lockmanager_api_lockrelease_SOURCES = \ | |||
62 | test_lockmanager_api_lockrelease.c | 62 | test_lockmanager_api_lockrelease.c |
63 | test_lockmanager_api_lockrelease_LDADD = \ | 63 | test_lockmanager_api_lockrelease_LDADD = \ |
64 | $(top_builddir)/src/util/libgnunetutil.la \ | 64 | $(top_builddir)/src/util/libgnunetutil.la \ |
65 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
65 | libgnunetlockmanager.la | 66 | libgnunetlockmanager.la |
66 | 67 | ||
67 | test_lockmanager_api_servercrash_SOURCES = \ | 68 | test_lockmanager_api_servercrash_SOURCES = \ |
68 | test_lockmanager_api_servercrash.c | 69 | test_lockmanager_api_servercrash.c |
69 | test_lockmanager_api_servercrash_LDADD = \ | 70 | test_lockmanager_api_servercrash_LDADD = \ |
70 | $(top_builddir)/src/util/libgnunetutil.la \ | 71 | $(top_builddir)/src/util/libgnunetutil.la \ |
72 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
71 | libgnunetlockmanager.la | 73 | libgnunetlockmanager.la |
72 | 74 | ||
73 | test_lockmanager_api_acquireretry_SOURCES = \ | 75 | test_lockmanager_api_acquireretry_SOURCES = \ |
74 | test_lockmanager_api_acquireretry.c | 76 | test_lockmanager_api_acquireretry.c |
75 | test_lockmanager_api_acquireretry_LDADD = \ | 77 | test_lockmanager_api_acquireretry_LDADD = \ |
76 | $(top_builddir)/src/util/libgnunetutil.la \ | 78 | $(top_builddir)/src/util/libgnunetutil.la \ |
79 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
77 | libgnunetlockmanager.la \ No newline at end of file | 80 | libgnunetlockmanager.la \ No newline at end of file |
diff --git a/src/lockmanager/gnunet-service-lockmanager.c b/src/lockmanager/gnunet-service-lockmanager.c index b5126ba20..c0a32e79c 100644 --- a/src/lockmanager/gnunet-service-lockmanager.c +++ b/src/lockmanager/gnunet-service-lockmanager.c | |||
@@ -897,3 +897,5 @@ int main (int argc, char *const *argv) | |||
897 | &lockmanager_run, | 897 | &lockmanager_run, |
898 | NULL)) ? 0 : 1; | 898 | NULL)) ? 0 : 1; |
899 | } | 899 | } |
900 | |||
901 | /* end of gnunet-service-lockmanager.c */ | ||
diff --git a/src/lockmanager/lockmanager_api.c b/src/lockmanager/lockmanager_api.c index 77773ed36..7a47da65b 100644 --- a/src/lockmanager/lockmanager_api.c +++ b/src/lockmanager/lockmanager_api.c | |||
@@ -734,3 +734,5 @@ GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest | |||
734 | GNUNET_free (request); | 734 | GNUNET_free (request); |
735 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | 735 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); |
736 | } | 736 | } |
737 | |||
738 | /* end of lockmanager_api.c */ | ||
diff --git a/src/lockmanager/test_lockmanager_api.c b/src/lockmanager/test_lockmanager_api.c index 91772e39c..7d8e75814 100644 --- a/src/lockmanager/test_lockmanager_api.c +++ b/src/lockmanager/test_lockmanager_api.c | |||
@@ -202,8 +202,10 @@ int main (int argc, char **argv) | |||
202 | { | 202 | { |
203 | 203 | ||
204 | if (0 != GNUNET_TESTING_peer_run ("test_lockmanager_api", | 204 | if (0 != GNUNET_TESTING_peer_run ("test_lockmanager_api", |
205 | "test_lockmanager_api.conf", | 205 | "test_lockmanager_api.conf", |
206 | &run, NULL)) | 206 | &run, NULL)) |
207 | return 1; | 207 | return 1; |
208 | return (TEST_FAIL == result) ? 1 : 0; | 208 | return (TEST_FAIL == result) ? 1 : 0; |
209 | } | 209 | } |
210 | |||
211 | /* end of test_lockmanager_api.c */ | ||
diff --git a/src/lockmanager/test_lockmanager_api_acquireretry.c b/src/lockmanager/test_lockmanager_api_acquireretry.c index a75476442..2ceb6eef4 100644 --- a/src/lockmanager/test_lockmanager_api_acquireretry.c +++ b/src/lockmanager/test_lockmanager_api_acquireretry.c | |||
@@ -28,14 +28,18 @@ | |||
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_lockmanager_service.h" | 30 | #include "gnunet_lockmanager_service.h" |
31 | #include "gnunet_testing_lib-new.h" | ||
31 | 32 | ||
32 | /** | 33 | /** |
33 | * Generic logging shortcut | 34 | * Generic logging shorthand |
34 | */ | 35 | */ |
35 | #define LOG(kind,...) \ | 36 | #define LOG(kind,...) \ |
36 | GNUNET_log (kind, __VA_ARGS__) | 37 | GNUNET_log (kind, __VA_ARGS__) |
37 | 38 | ||
38 | #define TIME_REL_SECS(sec) \ | 39 | /** |
40 | * Relative seconds shorthand | ||
41 | */ | ||
42 | #define TIME_REL_SECS(sec) \ | ||
39 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) | 43 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) |
40 | 44 | ||
41 | /** | 45 | /** |
@@ -70,11 +74,6 @@ enum Test | |||
70 | }; | 74 | }; |
71 | 75 | ||
72 | /** | 76 | /** |
73 | * The process id of the GNUNET ARM process | ||
74 | */ | ||
75 | static struct GNUNET_OS_Process *arm_pid = NULL; | ||
76 | |||
77 | /** | ||
78 | * Configuration Handle | 77 | * Configuration Handle |
79 | */ | 78 | */ |
80 | static const struct GNUNET_CONFIGURATION_Handle *config; | 79 | static const struct GNUNET_CONFIGURATION_Handle *config; |
@@ -99,6 +98,11 @@ static GNUNET_SCHEDULER_TaskIdentifier abort_task_id; | |||
99 | */ | 98 | */ |
100 | enum Test result; | 99 | enum Test result; |
101 | 100 | ||
101 | /** | ||
102 | * Our peer | ||
103 | */ | ||
104 | static struct GNUNET_TESTING_Peer *self; | ||
105 | |||
102 | 106 | ||
103 | /** | 107 | /** |
104 | * Shutdown nicely | 108 | * Shutdown nicely |
@@ -116,16 +120,6 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
116 | } | 120 | } |
117 | if (NULL != handle) | 121 | if (NULL != handle) |
118 | GNUNET_LOCKMANAGER_disconnect (handle); | 122 | GNUNET_LOCKMANAGER_disconnect (handle); |
119 | if (NULL != arm_pid) | ||
120 | { | ||
121 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) | ||
122 | { | ||
123 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
124 | "Kill gnunet-service-arm manually\n"); | ||
125 | } | ||
126 | GNUNET_OS_process_wait (arm_pid); | ||
127 | GNUNET_OS_process_destroy (arm_pid); | ||
128 | } | ||
129 | } | 123 | } |
130 | 124 | ||
131 | /** | 125 | /** |
@@ -172,25 +166,14 @@ status_cb (void *cls, | |||
172 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); | 166 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); |
173 | result = TEST_CLIENT_LOCK_SUCCESS; | 167 | result = TEST_CLIENT_LOCK_SUCCESS; |
174 | /* We should kill the lockmanager process */ | 168 | /* We should kill the lockmanager process */ |
175 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) | 169 | GNUNET_TESTING_peer_stop (self); |
176 | { | ||
177 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
178 | "Kill gnunet-service-arm manually\n"); | ||
179 | } | ||
180 | GNUNET_OS_process_wait (arm_pid); | ||
181 | GNUNET_OS_process_destroy (arm_pid); | ||
182 | arm_pid =NULL; | ||
183 | break; | 170 | break; |
184 | case TEST_CLIENT_LOCK_SUCCESS: | 171 | case TEST_CLIENT_LOCK_SUCCESS: |
185 | GNUNET_assert (handle == cls); | 172 | GNUNET_assert (handle == cls); |
186 | GNUNET_assert (GNUNET_LOCKMANAGER_RELEASE == status); | 173 | GNUNET_assert (GNUNET_LOCKMANAGER_RELEASE == status); |
187 | result = TEST_CLIENT_LOCK_RELEASE; | 174 | result = TEST_CLIENT_LOCK_RELEASE; |
188 | /* Now we should start again the lockmanager process */ | 175 | /* Now we should start again the lockmanager process */ |
189 | arm_pid = | 176 | GNUNET_TESTING_peer_start (self); |
190 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
191 | "gnunet-service-arm", | ||
192 | "-c", "test_lockmanager_api.conf", NULL); | ||
193 | GNUNET_assert (NULL != arm_pid); | ||
194 | break; | 177 | break; |
195 | case TEST_CLIENT_LOCK_RELEASE: | 178 | case TEST_CLIENT_LOCK_RELEASE: |
196 | GNUNET_assert (handle == cls); | 179 | GNUNET_assert (handle == cls); |
@@ -207,14 +190,15 @@ status_cb (void *cls, | |||
207 | 190 | ||
208 | 191 | ||
209 | /** | 192 | /** |
210 | * Testing function | 193 | * Main point of test execution |
211 | * | ||
212 | * @param cls NULL | ||
213 | * @param tc the task context | ||
214 | */ | 194 | */ |
215 | static void | 195 | static void |
216 | test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 196 | run (void *cls, |
217 | { | 197 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
198 | struct GNUNET_TESTING_Peer *peer) | ||
199 | { | ||
200 | config = cfg; | ||
201 | self = peer; | ||
218 | result = TEST_INIT; | 202 | result = TEST_INIT; |
219 | handle = GNUNET_LOCKMANAGER_connect (config); | 203 | handle = GNUNET_LOCKMANAGER_connect (config); |
220 | GNUNET_assert (NULL != handle); | 204 | GNUNET_assert (NULL != handle); |
@@ -226,24 +210,7 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
226 | GNUNET_assert (NULL != request); | 210 | GNUNET_assert (NULL != request); |
227 | abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (30), | 211 | abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (30), |
228 | &do_abort, | 212 | &do_abort, |
229 | NULL); | 213 | NULL); |
230 | } | ||
231 | |||
232 | |||
233 | /** | ||
234 | * Main point of test execution | ||
235 | */ | ||
236 | static void | ||
237 | run (void *cls, char *const *args, const char *cfgfile, | ||
238 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
239 | { | ||
240 | config = cfg; | ||
241 | arm_pid = | ||
242 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
243 | "gnunet-service-arm", | ||
244 | "-c", "test_lockmanager_api.conf", NULL); | ||
245 | GNUNET_assert (NULL != arm_pid); | ||
246 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(3), &test, NULL); | ||
247 | } | 214 | } |
248 | 215 | ||
249 | 216 | ||
@@ -252,31 +219,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
252 | */ | 219 | */ |
253 | int main (int argc, char **argv) | 220 | int main (int argc, char **argv) |
254 | { | 221 | { |
255 | int ret; | 222 | if (0 != GNUNET_TESTING_peer_run ("test_lockmanager_api_servercrash", |
256 | 223 | "test_lockmanager_api.conf", | |
257 | char *const argv2[] = { "test_lockmanager_api_servercrash", | 224 | &run, NULL)) |
258 | "-c", "test_lockmanager_api.conf", | ||
259 | NULL | ||
260 | }; | ||
261 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
262 | GNUNET_GETOPT_OPTION_END | ||
263 | }; | ||
264 | |||
265 | ret = | ||
266 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | ||
267 | "test_lockmanager_api_servercrash", | ||
268 | "nohelp", options, &run, NULL); | ||
269 | if (GNUNET_OK != ret) | ||
270 | { | ||
271 | LOG (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n", | ||
272 | ret); | ||
273 | return 1; | 225 | return 1; |
274 | } | 226 | return (TEST_CLIENT_LOCK_AGAIN_SUCCESS != result) ? 1 : 0; |
275 | if (TEST_CLIENT_LOCK_AGAIN_SUCCESS != result) | ||
276 | { | ||
277 | LOG (GNUNET_ERROR_TYPE_WARNING, "test failed\n"); | ||
278 | return 1; | ||
279 | } | ||
280 | LOG (GNUNET_ERROR_TYPE_INFO, "test OK\n"); | ||
281 | return 0; | ||
282 | } | 227 | } |
diff --git a/src/lockmanager/test_lockmanager_api_lockrelease.c b/src/lockmanager/test_lockmanager_api_lockrelease.c index 64e328ba0..dafba954e 100644 --- a/src/lockmanager/test_lockmanager_api_lockrelease.c +++ b/src/lockmanager/test_lockmanager_api_lockrelease.c | |||
@@ -26,15 +26,18 @@ | |||
26 | 26 | ||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_testing_lib-new.h" | ||
29 | #include "gnunet_lockmanager_service.h" | 30 | #include "gnunet_lockmanager_service.h" |
30 | 31 | ||
31 | #define VERBOSE GNUNET_YES | 32 | /** |
32 | 33 | * Generic Logging shorthand | |
33 | #define VERBOSE_ARM 1 | 34 | */ |
34 | |||
35 | #define LOG(kind,...) \ | 35 | #define LOG(kind,...) \ |
36 | GNUNET_log (kind, __VA_ARGS__) | 36 | GNUNET_log (kind, __VA_ARGS__) |
37 | 37 | ||
38 | /** | ||
39 | * Relative seconds shorthand | ||
40 | */ | ||
38 | #define TIME_REL_SECONDS(min) \ | 41 | #define TIME_REL_SECONDS(min) \ |
39 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min) | 42 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min) |
40 | 43 | ||
@@ -71,14 +74,9 @@ enum Test | |||
71 | static enum Test result; | 74 | static enum Test result; |
72 | 75 | ||
73 | /** | 76 | /** |
74 | * The process id of the GNUNET ARM process | ||
75 | */ | ||
76 | static struct GNUNET_OS_Process *arm_pid = NULL; | ||
77 | |||
78 | /** | ||
79 | * Configuration Handle | 77 | * Configuration Handle |
80 | */ | 78 | */ |
81 | static struct GNUNET_CONFIGURATION_Handle *config; | 79 | static const struct GNUNET_CONFIGURATION_Handle *config; |
82 | 80 | ||
83 | /** | 81 | /** |
84 | * The handle to the lockmanager service | 82 | * The handle to the lockmanager service |
@@ -119,20 +117,9 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
119 | { | 117 | { |
120 | GNUNET_SCHEDULER_cancel (abort_task_id); | 118 | GNUNET_SCHEDULER_cancel (abort_task_id); |
121 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; | 119 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; |
122 | } | 120 | } |
123 | |||
124 | GNUNET_LOCKMANAGER_disconnect (handle); | 121 | GNUNET_LOCKMANAGER_disconnect (handle); |
125 | GNUNET_LOCKMANAGER_disconnect (handle2); | 122 | GNUNET_LOCKMANAGER_disconnect (handle2); |
126 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) | ||
127 | { | ||
128 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
129 | "Kill gnunet-service-arm manually\n"); | ||
130 | } | ||
131 | GNUNET_OS_process_wait (arm_pid); | ||
132 | GNUNET_OS_process_destroy (arm_pid); | ||
133 | |||
134 | if (NULL != config) | ||
135 | GNUNET_CONFIGURATION_destroy (config); | ||
136 | } | 123 | } |
137 | 124 | ||
138 | 125 | ||
@@ -204,14 +191,15 @@ status_cb (void *cls, | |||
204 | 191 | ||
205 | 192 | ||
206 | /** | 193 | /** |
207 | * Testing function | 194 | * Main point of test execution |
208 | * | ||
209 | * @param cls NULL | ||
210 | * @param tc the task context | ||
211 | */ | 195 | */ |
212 | static void | 196 | static void |
213 | test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 197 | run (void *cls, |
214 | { | 198 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
199 | struct GNUNET_TESTING_Peer *peer) | ||
200 | { | ||
201 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n"); | ||
202 | config = cfg; | ||
215 | result = TEST_INIT; | 203 | result = TEST_INIT; |
216 | handle = GNUNET_LOCKMANAGER_connect (config); | 204 | handle = GNUNET_LOCKMANAGER_connect (config); |
217 | GNUNET_assert (NULL != handle); | 205 | GNUNET_assert (NULL != handle); |
@@ -230,72 +218,13 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
230 | 218 | ||
231 | 219 | ||
232 | /** | 220 | /** |
233 | * Main point of test execution | ||
234 | */ | ||
235 | static void | ||
236 | run (void *cls, char *const *args, const char *cfgfile, | ||
237 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
238 | { | ||
239 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n"); | ||
240 | config = GNUNET_CONFIGURATION_dup (cfg); | ||
241 | arm_pid = | ||
242 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
243 | "gnunet-service-arm", | ||
244 | #if VERBOSE_ARM | ||
245 | "-L", "DEBUG", | ||
246 | #endif | ||
247 | "-c", "test_lockmanager_api.conf", NULL); | ||
248 | |||
249 | GNUNET_assert (NULL != arm_pid); | ||
250 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (3), | ||
251 | &test, | ||
252 | NULL); | ||
253 | } | ||
254 | |||
255 | |||
256 | /** | ||
257 | * Main function | 221 | * Main function |
258 | */ | 222 | */ |
259 | int main (int argc, char **argv) | 223 | int main (int argc, char **argv) |
260 | { | 224 | { |
261 | int ret; | 225 | if (0 != GNUNET_TESTING_peer_run ("test_lockmanager_api_lockrelease", |
262 | 226 | "test_lockmanager_api.conf", | |
263 | char *const argv2[] = { "test_lockmanager_api_lockrelease", | 227 | &run, NULL)) |
264 | "-c", "test_lockmanager_api.conf", | ||
265 | #if VERBOSE | ||
266 | "-L", "DEBUG", | ||
267 | #endif | ||
268 | NULL | ||
269 | }; | ||
270 | |||
271 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
272 | GNUNET_GETOPT_OPTION_END | ||
273 | }; | ||
274 | |||
275 | GNUNET_log_setup ("test_lockmanager_api_lockrelease", | ||
276 | #if VERBOSE | ||
277 | "DEBUG", | ||
278 | #else | ||
279 | "WARNING", | ||
280 | #endif | ||
281 | NULL); | ||
282 | |||
283 | ret = | ||
284 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | ||
285 | "test_lockmanager_api_lockrelease", | ||
286 | "nohelp", options, &run, NULL); | ||
287 | |||
288 | if (GNUNET_OK != ret) | ||
289 | { | ||
290 | LOG (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n", | ||
291 | ret); | ||
292 | return 1; | 228 | return 1; |
293 | } | 229 | return (TEST_CLIENT2_LOCK_SUCCESS != result) ? 1 : 0; |
294 | if (TEST_CLIENT2_LOCK_SUCCESS != result) | ||
295 | { | ||
296 | LOG (GNUNET_ERROR_TYPE_WARNING, "test failed\n"); | ||
297 | return 1; | ||
298 | } | ||
299 | LOG (GNUNET_ERROR_TYPE_INFO, "test OK\n"); | ||
300 | return 0; | ||
301 | } | 230 | } |
diff --git a/src/lockmanager/test_lockmanager_api_servercrash.c b/src/lockmanager/test_lockmanager_api_servercrash.c index 974a31f7e..b471dc3b3 100644 --- a/src/lockmanager/test_lockmanager_api_servercrash.c +++ b/src/lockmanager/test_lockmanager_api_servercrash.c | |||
@@ -27,14 +27,17 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_lockmanager_service.h" | 29 | #include "gnunet_lockmanager_service.h" |
30 | #include "gnunet_testing_lib-new.h" | ||
30 | 31 | ||
31 | #define VERBOSE GNUNET_YES | 32 | /** |
32 | 33 | * Generic logging shorthand | |
33 | #define VERBOSE_ARM 1 | 34 | */ |
34 | |||
35 | #define LOG(kind,...) \ | 35 | #define LOG(kind,...) \ |
36 | GNUNET_log (kind, __VA_ARGS__) | 36 | GNUNET_log (kind, __VA_ARGS__) |
37 | 37 | ||
38 | /** | ||
39 | * Relative seconds shorthand | ||
40 | */ | ||
38 | #define TIME_REL_SECONDS(min) \ | 41 | #define TIME_REL_SECONDS(min) \ |
39 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min) | 42 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min) |
40 | 43 | ||
@@ -77,14 +80,9 @@ enum Test | |||
77 | static enum Test result; | 80 | static enum Test result; |
78 | 81 | ||
79 | /** | 82 | /** |
80 | * The process id of the GNUNET ARM process | ||
81 | */ | ||
82 | static struct GNUNET_OS_Process *arm_pid = NULL; | ||
83 | |||
84 | /** | ||
85 | * Configuration Handle | 83 | * Configuration Handle |
86 | */ | 84 | */ |
87 | static struct GNUNET_CONFIGURATION_Handle *config; | 85 | static const struct GNUNET_CONFIGURATION_Handle *config; |
88 | 86 | ||
89 | /** | 87 | /** |
90 | * The handle to the lockmanager service | 88 | * The handle to the lockmanager service |
@@ -111,6 +109,11 @@ static struct GNUNET_LOCKMANAGER_LockingRequest *request2; | |||
111 | */ | 109 | */ |
112 | static GNUNET_SCHEDULER_TaskIdentifier abort_task_id; | 110 | static GNUNET_SCHEDULER_TaskIdentifier abort_task_id; |
113 | 111 | ||
112 | /** | ||
113 | * Our peer | ||
114 | */ | ||
115 | static struct GNUNET_TESTING_Peer *self; | ||
116 | |||
114 | 117 | ||
115 | /** | 118 | /** |
116 | * Shutdown nicely | 119 | * Shutdown nicely |
@@ -130,18 +133,6 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
130 | GNUNET_LOCKMANAGER_disconnect (handle); | 133 | GNUNET_LOCKMANAGER_disconnect (handle); |
131 | if (NULL != handle2) | 134 | if (NULL != handle2) |
132 | GNUNET_LOCKMANAGER_disconnect (handle2); | 135 | GNUNET_LOCKMANAGER_disconnect (handle2); |
133 | if (NULL != arm_pid) | ||
134 | { | ||
135 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) | ||
136 | { | ||
137 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
138 | "Kill gnunet-service-arm manually\n"); | ||
139 | } | ||
140 | GNUNET_OS_process_wait (arm_pid); | ||
141 | GNUNET_OS_process_destroy (arm_pid); | ||
142 | } | ||
143 | if (NULL != config) | ||
144 | GNUNET_CONFIGURATION_destroy (config); | ||
145 | } | 136 | } |
146 | 137 | ||
147 | 138 | ||
@@ -201,15 +192,8 @@ status_cb (void *cls, | |||
201 | GNUNET_assert (handle2 == cls); | 192 | GNUNET_assert (handle2 == cls); |
202 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); | 193 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); |
203 | result = TEST_CLIENT2_LOCK_SUCCESS; | 194 | result = TEST_CLIENT2_LOCK_SUCCESS; |
204 | /* We should kill the lockmanager process */ | 195 | /* We should stop our peer to simulate crash in lockmanager service */ |
205 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) | 196 | GNUNET_TESTING_peer_stop (self); |
206 | { | ||
207 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
208 | "Kill gnunet-service-arm manually\n"); | ||
209 | } | ||
210 | GNUNET_OS_process_wait (arm_pid); | ||
211 | GNUNET_OS_process_destroy (arm_pid); | ||
212 | arm_pid =NULL; | ||
213 | break; | 197 | break; |
214 | case TEST_CLIENT2_LOCK_SUCCESS: | 198 | case TEST_CLIENT2_LOCK_SUCCESS: |
215 | GNUNET_assert (handle2 == cls); | 199 | GNUNET_assert (handle2 == cls); |
@@ -226,19 +210,19 @@ status_cb (void *cls, | |||
226 | default: | 210 | default: |
227 | GNUNET_assert (0); /* We should never reach here */ | 211 | GNUNET_assert (0); /* We should never reach here */ |
228 | } | 212 | } |
229 | |||
230 | } | 213 | } |
231 | 214 | ||
232 | 215 | ||
233 | /** | 216 | /** |
234 | * Testing function | 217 | * Main point of test execution |
235 | * | ||
236 | * @param cls NULL | ||
237 | * @param tc the task context | ||
238 | */ | 218 | */ |
239 | static void | 219 | static void |
240 | test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 220 | run (void *cls, |
241 | { | 221 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
222 | struct GNUNET_TESTING_Peer *peer) | ||
223 | { | ||
224 | config = cfg; | ||
225 | self = peer; | ||
242 | result = TEST_INIT; | 226 | result = TEST_INIT; |
243 | handle = GNUNET_LOCKMANAGER_connect (config); | 227 | handle = GNUNET_LOCKMANAGER_connect (config); |
244 | GNUNET_assert (NULL != handle); | 228 | GNUNET_assert (NULL != handle); |
@@ -257,72 +241,13 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
257 | 241 | ||
258 | 242 | ||
259 | /** | 243 | /** |
260 | * Main point of test execution | ||
261 | */ | ||
262 | static void | ||
263 | run (void *cls, char *const *args, const char *cfgfile, | ||
264 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
265 | { | ||
266 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n"); | ||
267 | config = GNUNET_CONFIGURATION_dup (cfg); | ||
268 | arm_pid = | ||
269 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
270 | "gnunet-service-arm", | ||
271 | #if VERBOSE_ARM | ||
272 | "-L", "DEBUG", | ||
273 | #endif | ||
274 | "-c", "test_lockmanager_api.conf", NULL); | ||
275 | |||
276 | GNUNET_assert (NULL != arm_pid); | ||
277 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (3), | ||
278 | &test, | ||
279 | NULL); | ||
280 | } | ||
281 | |||
282 | |||
283 | /** | ||
284 | * Main function | 244 | * Main function |
285 | */ | 245 | */ |
286 | int main (int argc, char **argv) | 246 | int main (int argc, char **argv) |
287 | { | 247 | { |
288 | int ret; | 248 | if (0 != GNUNET_TESTING_peer_run ("test_lockmanager_api_servercrash", |
289 | 249 | "test_lockmanager_api.conf", | |
290 | char *const argv2[] = { "test_lockmanager_api_servercrash", | 250 | &run, NULL)) |
291 | "-c", "test_lockmanager_api.conf", | ||
292 | #if VERBOSE | ||
293 | "-L", "DEBUG", | ||
294 | #endif | ||
295 | NULL | ||
296 | }; | ||
297 | |||
298 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
299 | GNUNET_GETOPT_OPTION_END | ||
300 | }; | ||
301 | |||
302 | GNUNET_log_setup ("test_lockmanager_api_servercrash", | ||
303 | #if VERBOSE | ||
304 | "DEBUG", | ||
305 | #else | ||
306 | "WARNING", | ||
307 | #endif | ||
308 | NULL); | ||
309 | |||
310 | ret = | ||
311 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | ||
312 | "test_lockmanager_api_servercrash", | ||
313 | "nohelp", options, &run, NULL); | ||
314 | |||
315 | if (GNUNET_OK != ret) | ||
316 | { | ||
317 | LOG (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n", | ||
318 | ret); | ||
319 | return 1; | 251 | return 1; |
320 | } | 252 | return (TEST_CLIENT2_SERVER_CRASH_SUCCESS != result) ? 1 : 0; |
321 | if (TEST_CLIENT2_SERVER_CRASH_SUCCESS != result) | ||
322 | { | ||
323 | LOG (GNUNET_ERROR_TYPE_WARNING, "test failed\n"); | ||
324 | return 1; | ||
325 | } | ||
326 | LOG (GNUNET_ERROR_TYPE_INFO, "test OK\n"); | ||
327 | return 0; | ||
328 | } | 253 | } |