aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/test_testbed_api_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/test_testbed_api_barriers.c
parenta3efd7521e99175689c589a128240f2c84c55c45 (diff)
downloadgnunet-de547f838e21de9f847c0b357c41cbfa6ecbe967.tar.gz
gnunet-de547f838e21de9f847c0b357c41cbfa6ecbe967.zip
- barriers test case; more fixes
Diffstat (limited to 'src/testbed/test_testbed_api_barriers.c')
-rw-r--r--src/testbed/test_testbed_api_barriers.c106
1 files changed, 98 insertions, 8 deletions
diff --git a/src/testbed/test_testbed_api_barriers.c b/src/testbed/test_testbed_api_barriers.c
index b40fbc87a..35fda4b31 100644
--- a/src/testbed/test_testbed_api_barriers.c
+++ b/src/testbed/test_testbed_api_barriers.c
@@ -27,12 +27,31 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_testbed_service.h" 29#include "gnunet_testbed_service.h"
30#include "test_testbed_api_barriers.h"
31
32
33/**
34 * logging short hand
35 */
36#define LOG(type,...) \
37 GNUNET_log (type, __VA_ARGS__);
30 38
31/** 39/**
32 * Number of peers we start in this test case 40 * Number of peers we start in this test case
33 */ 41 */
34#define NUM_PEERS 3 42#define NUM_PEERS 3
35 43
44
45/**
46 * Our barrier
47 */
48struct GNUNET_TESTBED_Barrier *barrier;
49
50/**
51 * Identifier for the shutdown task
52 */
53static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
54
36/** 55/**
37 * Result of this test case 56 * Result of this test case
38 */ 57 */
@@ -40,6 +59,75 @@ static int result;
40 59
41 60
42/** 61/**
62 * Shutdown this test case when it takes too long
63 *
64 * @param cls NULL
65 * @param tc scheduler task context
66 */
67static void
68do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
69{
70 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
71 if (NULL != barrier)
72 {
73 GNUNET_TESTBED_barrier_cancel (barrier);
74 barrier = NULL;
75 }
76
77 GNUNET_SCHEDULER_shutdown ();
78}
79
80
81/**
82 * Functions of this type are to be given as callback argument to
83 * GNUNET_TESTBED_barrier_init(). The callback will be called when status
84 * information is available for the barrier.
85 *
86 * @param cls the closure given to GNUNET_TESTBED_barrier_init()
87 * @param name the name of the barrier
88 * @param barrier the barrier handle
89 * @param status status of the barrier; GNUNET_OK if the barrier is crossed;
90 * GNUNET_SYSERR upon error
91 * @param emsg if the status were to be GNUNET_SYSERR, this parameter has the
92 * error messsage
93 */
94static void
95barrier_cb (void *cls,
96 const char *name,
97 struct GNUNET_TESTBED_Barrier *_barrier,
98 enum GNUNET_TESTBED_BarrierStatus status,
99 const char *emsg)
100{
101 static enum GNUNET_TESTBED_BarrierStatus old_status;
102
103 GNUNET_assert (NULL == cls);
104 GNUNET_assert (_barrier == barrier);
105 switch (status)
106 {
107 case BARRIER_STATUS_INITIALISED:
108 LOG (GNUNET_ERROR_TYPE_INFO, "Barrier initialised\n");
109 old_status = status;
110 return;
111 case BARRIER_STATUS_ERROR:
112 LOG (GNUNET_ERROR_TYPE_ERROR, "Barrier initialisation failed: %s",
113 (NULL == emsg) ? "unknown reason" : emsg);
114 barrier = NULL;
115 GNUNET_SCHEDULER_shutdown ();
116 return;
117 case BARRIER_STATUS_CROSSED:
118 LOG (GNUNET_ERROR_TYPE_INFO, "Barrier crossed\n");
119 if (old_status == BARRIER_STATUS_INITIALISED)
120 result = GNUNET_OK;
121 barrier = NULL;
122 GNUNET_SCHEDULER_shutdown ();
123 return;
124 default:
125 GNUNET_assert (0);
126 }
127}
128
129
130/**
43 * Signature of a main function for a testcase. 131 * Signature of a main function for a testcase.
44 * 132 *
45 * @param cls closure 133 * @param cls closure
@@ -59,6 +147,7 @@ test_master (void *cls,
59 unsigned int links_succeeded, 147 unsigned int links_succeeded,
60 unsigned int links_failed) 148 unsigned int links_failed)
61{ 149{
150 struct GNUNET_TESTBED_Controller *c;
62 151
63 GNUNET_assert (NULL == cls); 152 GNUNET_assert (NULL == cls);
64 if (NULL == peers_) 153 if (NULL == peers_)
@@ -67,13 +156,14 @@ test_master (void *cls,
67 return; 156 return;
68 } 157 }
69 GNUNET_assert (NUM_PEERS == num_peers); 158 GNUNET_assert (NUM_PEERS == num_peers);
70 159 c = GNUNET_TESTBED_run_get_controller_handle (h);
71 result = GNUNET_OK; 160 barrier = GNUNET_TESTBED_barrier_init (c, TEST_BARRIER_NAME, 100,
72 GNUNET_SCHEDULER_shutdown (); 161 &barrier_cb, NULL);
73 /* shutdown_task = */ 162 shutdown_task =
74 /* GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply */ 163 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
75 /* (GNUNET_TIME_UNIT_SECONDS, 300), */ 164 (GNUNET_TIME_UNIT_SECONDS,
76 /* do_shutdown, NULL); */ 165 10 * (NUM_PEERS + 1)),
166 &do_shutdown, NULL);
77} 167}
78 168
79 169
@@ -87,7 +177,7 @@ main (int argc, char **argv)
87 177
88 result = GNUNET_SYSERR; 178 result = GNUNET_SYSERR;
89 event_mask = 0; 179 event_mask = 0;
90 (void) GNUNET_TESTBED_test_run ("test_testbed_api_test", 180 (void) GNUNET_TESTBED_test_run ("test_testbed_api_barriers",
91 "test_testbed_api_barriers.conf", NUM_PEERS, 181 "test_testbed_api_barriers.conf", NUM_PEERS,
92 event_mask, NULL, NULL, 182 event_mask, NULL, NULL,
93 &test_master, NULL); 183 &test_master, NULL);