aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/test_testbed_api_test.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-11-09 16:14:20 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-11-09 16:14:20 +0000
commit7dcb3d8558f23a197b357874917c66cfe9d9cca4 (patch)
treeef7032550d6df86bd9396d57ec990cfd1ef9c8a7 /src/testbed/test_testbed_api_test.c
parentf9a99e68470c769411a1e3851838b4b18a6ce5f8 (diff)
downloadgnunet-7dcb3d8558f23a197b357874917c66cfe9d9cca4.tar.gz
gnunet-7dcb3d8558f23a197b357874917c66cfe9d9cca4.zip
-fixes
Diffstat (limited to 'src/testbed/test_testbed_api_test.c')
-rw-r--r--src/testbed/test_testbed_api_test.c97
1 files changed, 80 insertions, 17 deletions
diff --git a/src/testbed/test_testbed_api_test.c b/src/testbed/test_testbed_api_test.c
index e93c5872a..1738c0a98 100644
--- a/src/testbed/test_testbed_api_test.c
+++ b/src/testbed/test_testbed_api_test.c
@@ -28,6 +28,13 @@
28#include "gnunet_common.h" 28#include "gnunet_common.h"
29#include "gnunet_testbed_service.h" 29#include "gnunet_testbed_service.h"
30 30
31
32/**
33 * Generic logging shortcut
34 */
35#define LOG(kind,...) \
36 GNUNET_log (kind, __VA_ARGS__)
37
31/** 38/**
32 * Number of peers we want to start 39 * Number of peers we want to start
33 */ 40 */
@@ -44,6 +51,16 @@ static struct GNUNET_TESTBED_Peer **peers;
44static struct GNUNET_TESTBED_Operation *op; 51static struct GNUNET_TESTBED_Operation *op;
45 52
46/** 53/**
54 * Abort task identifier
55 */
56static GNUNET_SCHEDULER_TaskIdentifier abort_task;
57
58/**
59 * shutdown task identifier
60 */
61static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
62
63/**
47 * Testing result 64 * Testing result
48 */ 65 */
49static int result; 66static int result;
@@ -57,10 +74,47 @@ static int result;
57 */ 74 */
58static void 75static void
59do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 76do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
60{ 77{
78 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
79 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
80 GNUNET_SCHEDULER_cancel (abort_task);
81 if (NULL != op)
82 GNUNET_TESTBED_operation_done (op);
61 GNUNET_SCHEDULER_shutdown (); 83 GNUNET_SCHEDULER_shutdown ();
62} 84}
63 85
86/**
87 * shortcut to exit during failure
88 */
89#define FAIL_TEST(cond) do { \
90 if (!(cond)) { \
91 GNUNET_break(0); \
92 if (GNUNET_SCHEDULER_NO_TASK != abort_task) \
93 GNUNET_SCHEDULER_cancel (abort_task); \
94 abort_task = GNUNET_SCHEDULER_NO_TASK; \
95 if (GNUNET_SCHEDULER_NO_TASK == shutdown_task) \
96 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); \
97 return; \
98 } \
99 } while (0)
100
101
102/**
103 * abort task to run on test timed out
104 *
105 * @param cls NULL
106 * @param tc the task context
107 */
108static void
109do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
110{
111 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
112 abort_task = GNUNET_SCHEDULER_NO_TASK;
113 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
114 GNUNET_SCHEDULER_cancel (shutdown_task);
115 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL);
116}
117
64 118
65/** 119/**
66 * Callback to be called when the requested peer information is available 120 * Callback to be called when the requested peer information is available
@@ -76,14 +130,15 @@ peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_,
76 const struct GNUNET_TESTBED_PeerInformation *pinfo, 130 const struct GNUNET_TESTBED_PeerInformation *pinfo,
77 const char *emsg) 131 const char *emsg)
78{ 132{
79 GNUNET_assert (op == op_); 133 FAIL_TEST (op == op_);
80 GNUNET_assert (NULL == cb_cls); 134 FAIL_TEST (NULL == cb_cls);
81 GNUNET_assert (NULL == emsg); 135 FAIL_TEST (NULL == emsg);
82 GNUNET_assert (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit); 136 FAIL_TEST (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit);
83 GNUNET_assert (NULL != pinfo->result.id); 137 FAIL_TEST (NULL != pinfo->result.id);
84 GNUNET_TESTBED_operation_done (op); 138 GNUNET_TESTBED_operation_done (op);
139 op = NULL;
85 result = GNUNET_OK; 140 result = GNUNET_OK;
86 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 141 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
87} 142}
88 143
89 144
@@ -98,9 +153,13 @@ peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_,
98static void 153static void
99op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) 154op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg)
100{ 155{
101 GNUNET_assert (NULL == cls); 156 FAIL_TEST (NULL == cls);
102 GNUNET_assert (op == op_); 157 FAIL_TEST (op == op_);
103 GNUNET_assert (NULL == emsg); 158 if (NULL != emsg)
159 {
160 LOG (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
161 FAIL_TEST (0);
162 }
104 GNUNET_TESTBED_operation_done (op); 163 GNUNET_TESTBED_operation_done (op);
105 op = GNUNET_TESTBED_peer_get_information (peers[0], 164 op = GNUNET_TESTBED_peer_get_information (peers[0],
106 GNUNET_TESTBED_PIT_IDENTITY, 165 GNUNET_TESTBED_PIT_IDENTITY,
@@ -121,11 +180,11 @@ controller_event_cb (void *cls,
121 switch (event->type) 180 switch (event->type)
122 { 181 {
123 case GNUNET_TESTBED_ET_CONNECT: 182 case GNUNET_TESTBED_ET_CONNECT:
124 GNUNET_assert (event->details.peer_connect.peer1 == peers[0]); 183 FAIL_TEST (event->details.peer_connect.peer1 == peers[0]);
125 GNUNET_assert (event->details.peer_connect.peer2 == peers[1]); 184 FAIL_TEST (event->details.peer_connect.peer2 == peers[1]);
126 break; 185 break;
127 default: 186 default:
128 GNUNET_assert (0); 187 FAIL_TEST (0);
129 } 188 }
130} 189}
131 190
@@ -143,13 +202,17 @@ test_master (void *cls, unsigned int num_peers,
143{ 202{
144 unsigned int peer; 203 unsigned int peer;
145 204
146 GNUNET_assert (NULL == cls); 205 FAIL_TEST (NULL == cls);
147 GNUNET_assert (NUM_PEERS == num_peers); 206 FAIL_TEST (NUM_PEERS == num_peers);
148 GNUNET_assert (NULL != peers_); 207 FAIL_TEST (NULL != peers_);
149 for (peer = 0; peer < num_peers; peer++) 208 for (peer = 0; peer < num_peers; peer++)
150 GNUNET_assert (NULL != peers_[peer]); 209 FAIL_TEST (NULL != peers_[peer]);
151 peers = peers_; 210 peers = peers_;
152 op = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peers[0], peers[1]); 211 op = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peers[0], peers[1]);
212 abort_task =
213 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
214 (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
215 NULL);
153} 216}
154 217
155 218