aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-test-barriers.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-09-09 12:22:31 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-09-09 12:22:31 +0000
commitde547f838e21de9f847c0b357c41cbfa6ecbe967 (patch)
tree35da1aed63ed018249ec58941447bacd758adfff /src/testbed/gnunet-service-test-barriers.c
parenta3efd7521e99175689c589a128240f2c84c55c45 (diff)
downloadgnunet-de547f838e21de9f847c0b357c41cbfa6ecbe967.tar.gz
gnunet-de547f838e21de9f847c0b357c41cbfa6ecbe967.zip
- barriers test case; more fixes
Diffstat (limited to 'src/testbed/gnunet-service-test-barriers.c')
-rw-r--r--src/testbed/gnunet-service-test-barriers.c106
1 files changed, 104 insertions, 2 deletions
diff --git a/src/testbed/gnunet-service-test-barriers.c b/src/testbed/gnunet-service-test-barriers.c
index 84c6bde68..52528d523 100644
--- a/src/testbed/gnunet-service-test-barriers.c
+++ b/src/testbed/gnunet-service-test-barriers.c
@@ -25,8 +25,110 @@
25 * @author Sree Harsha Totakura <sreeharsha@totakura.in> 25 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
26 */ 26 */
27 27
28#include "platform.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_testbed_service.h"
31#include "test_testbed_api_barriers.h"
28 32
29int main () 33/**
34 * logging short hand
35 */
36#define LOG(type,...) \
37 GNUNET_log (type, __VA_ARGS__);
38
39/**
40 * Our barrier wait handle
41 */
42struct GNUNET_TESTBED_BarrierWaitHandle *wh;
43
44
45/**
46 * Dummy task callback to keep us running forever
47 *
48 * @param cls NULL
49 * @param tc scheduler task context
50 */
51static void
52do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
53{
54 if (NULL != wh)
55 GNUNET_TESTBED_barrier_wait_cancel (wh);
56 wh = NULL;
57}
58
59
60/**
61 * Functions of this type are to be given as acallback argumetn to
62 * GNUNET_TESTBED_barrier_wait(). The callback will be called when the barrier
63 * corresponding given in GNUNET_TESTBED_barrier_wait() is crossed or cancelled.
64 *
65 * @param cls NULL
66 * @param name the barrier name
67 * @param status GNUNET_SYSERR in case of error while waiting for the barrier;
68 * GNUNET_OK if the barrier is crossed
69 */
70static void
71barrier_wait_cb (void *cls, const char *name, int status)
72{
73 GNUNET_break (NULL == cls);
74 wh = NULL;
75 GNUNET_break (GNUNET_OK == status);
76}
77
78
79/**
80 * Task to wait for the barrier
81 *
82 * @param cls NULL
83 * @param tc scheduler task context
84 * @return
85 */
86static void
87do_wait (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
88{
89 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
90 return;
91 wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME, &barrier_wait_cb, NULL);
92 GNUNET_break (NULL != wh);
93}
94
95
96/**
97 * Main run function.
98 *
99 * @param cls NULL
100 * @param args arguments passed to GNUNET_PROGRAM_run
101 * @param cfgfile the path to configuration file
102 * @param cfg the configuration file handle
103 */
104static void
105run (void *cls, char *const *args, const char *cfgfile,
106 const struct GNUNET_CONFIGURATION_Handle *config)
107{
108 unsigned int rsec;
109
110 rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 10);
111 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
112 (GNUNET_TIME_UNIT_SECONDS, rsec),
113 &do_wait, NULL);
114 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
115 &do_shutdown, NULL);
116}
117
118
119
120/**
121 * Main
122 */
123int main (int argc, char **argv)
30{ 124{
31 return 0; 125 struct GNUNET_GETOPT_CommandLineOption options[] = {
126 GNUNET_GETOPT_OPTION_END
127 };
128 int ret;
129
130 ret =
131 GNUNET_PROGRAM_run (argc, argv,
132 "test-barriers", "nohelp", options, &run, NULL);
133 return ret;
32} 134}