aboutsummaryrefslogtreecommitdiff
path: root/src/lockmanager/test_lockmanager_api_lockrelease.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-06-20 19:24:26 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-06-20 19:24:26 +0000
commit48cc55589e0ba907fc2d50c5fbb42692a0bdba3e (patch)
tree1aeff3421f800c121d5edc6d4d5dd6b4b5ef6eab /src/lockmanager/test_lockmanager_api_lockrelease.c
parenta108a1ec6a4b299f3a6db7d9bb0a507188a2d0bb (diff)
downloadgnunet-48cc55589e0ba907fc2d50c5fbb42692a0bdba3e.tar.gz
gnunet-48cc55589e0ba907fc2d50c5fbb42692a0bdba3e.zip
lockmanager testcase new testing library
Diffstat (limited to 'src/lockmanager/test_lockmanager_api_lockrelease.c')
-rw-r--r--src/lockmanager/test_lockmanager_api_lockrelease.c111
1 files changed, 20 insertions, 91 deletions
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
71static enum Test result; 74static enum Test result;
72 75
73/** 76/**
74 * The process id of the GNUNET ARM process
75 */
76static struct GNUNET_OS_Process *arm_pid = NULL;
77
78/**
79 * Configuration Handle 77 * Configuration Handle
80 */ 78 */
81static struct GNUNET_CONFIGURATION_Handle *config; 79static 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 */
212static void 196static void
213test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 197run (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 */
235static void
236run (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 */
259int main (int argc, char **argv) 223int 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}