aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-07-06 15:13:24 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-07-06 15:13:24 +0000
commit08669dc96bde16224d1dfc5eb5f790b93c93fb88 (patch)
tree91a322e8623f7f6849ffbb5b2d98e36a10800d26 /src/testbed
parent3ea2e31b3a7a6c835de5665c2df2e2684c8efeaa (diff)
downloadgnunet-08669dc96bde16224d1dfc5eb5f790b93c93fb88.tar.gz
gnunet-08669dc96bde16224d1dfc5eb5f790b93c93fb88.zip
testbed api test case and fixes
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/Makefile.am10
-rw-r--r--src/testbed/gnunet-service-testbed.c62
-rw-r--r--src/testbed/test_testbed_api.c177
-rw-r--r--src/testbed/test_testbed_api.conf8
-rw-r--r--src/testbed/testbed_api.c49
5 files changed, 279 insertions, 27 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index e8ca96081..8a3912f5b 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -51,7 +51,8 @@ libgnunettestbed_la_LDFLAGS = \
51 -version-info 0:0:0 51 -version-info 0:0:0
52 52
53check_PROGRAMS = \ 53check_PROGRAMS = \
54 test_testbed_api_hosts 54 test_testbed_api_hosts \
55 test_testbed_api
55 56
56if ENABLE_TEST_RUN 57if ENABLE_TEST_RUN
57 TESTS = $(check_PROGRAMS) 58 TESTS = $(check_PROGRAMS)
@@ -61,4 +62,11 @@ test_testbed_api_hosts_SOURCES = \
61 test_testbed_api_hosts.c 62 test_testbed_api_hosts.c
62test_testbed_api_hosts_LDADD = \ 63test_testbed_api_hosts_LDADD = \
63 $(top_builddir)/src/util/libgnunetutil.la \ 64 $(top_builddir)/src/util/libgnunetutil.la \
65 libgnunettestbed.la
66
67test_testbed_api_SOURCES = \
68 test_testbed_api.c
69test_testbed_api_LDADD = \
70 $(top_builddir)/src/util/libgnunetutil.la \
71 $(top_builddir)/src/testing/libgnunettesting.la \
64 libgnunettestbed.la \ No newline at end of file 72 libgnunettestbed.la \ No newline at end of file
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 7cc822aca..a89ae405c 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -422,14 +422,18 @@ static int
422host_list_add (struct GNUNET_TESTBED_Host *host) 422host_list_add (struct GNUNET_TESTBED_Host *host)
423{ 423{
424 uint32_t host_id; 424 uint32_t host_id;
425 425 uint32_t new_size;
426
426 host_id = GNUNET_TESTBED_host_get_id_ (host); 427 host_id = GNUNET_TESTBED_host_get_id_ (host);
427 if (host_list_size <= host_id) 428 if (host_list_size <= host_id)
428 { 429 {
430 new_size = host_list_size + LIST_GROW_STEP;
429 host_list = GNUNET_realloc (host_list, 431 host_list = GNUNET_realloc (host_list,
430 sizeof (struct GNUNET_TESTBED_Host *) 432 sizeof (struct GNUNET_TESTBED_Host *)
431 * (host_id + 10)); 433 * new_size);
432 host_list_size += (host_id + 10); 434 memset (&host_list[host_list_size], 0,
435 sizeof (struct Slave *) * LIST_GROW_STEP);
436 host_list_size = new_size;
433 } 437 }
434 if (NULL != host_list[host_id]) 438 if (NULL != host_list[host_id])
435 { 439 {
@@ -449,11 +453,16 @@ host_list_add (struct GNUNET_TESTBED_Host *host)
449static void 453static void
450route_list_add (struct Route *route) 454route_list_add (struct Route *route)
451{ 455{
452 if (route->dest > route_list_size) 456 uint32_t new_size;
457
458 if (route->dest >= route_list_size)
453 { 459 {
454 route_list_size += LIST_GROW_STEP; 460 new_size = route_list_size + LIST_GROW_STEP;
455 route_list = GNUNET_realloc (route_list, sizeof (struct Route *) 461 route_list = GNUNET_realloc (route_list, sizeof (struct Route *)
456 * route_list_size); 462 * new_size);
463 memset (&route_list[route_list_size], 0,
464 sizeof (struct Slave *) * LIST_GROW_STEP);
465 route_list_size = new_size;
457 } 466 }
458 GNUNET_assert (NULL == route_list[route->dest]); 467 GNUNET_assert (NULL == route_list[route->dest]);
459 route_list[route->dest] = route; 468 route_list[route->dest] = route;
@@ -461,6 +470,30 @@ route_list_add (struct Route *route)
461 470
462 471
463/** 472/**
473 * Adds a slave to the slave array
474 *
475 * @param route the route to add
476 */
477static void
478slave_list_add (struct Slave *slave)
479{
480 uint32_t new_size;
481
482 if (slave->host_id >= slave_list_size)
483 {
484 new_size = slave_list_size + LIST_GROW_STEP;
485 slave_list = GNUNET_realloc (slave_list, sizeof (struct Slave *)
486 * new_size);
487 memset (&slave_list[slave_list_size], 0,
488 sizeof (struct Slave *) * LIST_GROW_STEP);
489 slave_list_size = new_size;
490 }
491 GNUNET_assert (NULL == slave_list[slave->host_id]);
492 slave_list[slave->host_id] = slave;
493}
494
495
496/**
464 * Routes message to a host given its host_id 497 * Routes message to a host given its host_id
465 * 498 *
466 * @param host_id the id of the destination host 499 * @param host_id the id of the destination host
@@ -657,7 +690,7 @@ handle_add_host (void *cls,
657 } 690 }
658 hostname_length = ntohs (message->size) 691 hostname_length = ntohs (message->size)
659 - (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length); 692 - (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length);
660 if (strlen (hostname) != hostname_length) 693 if (strlen (hostname) != hostname_length - 1)
661 { 694 {
662 GNUNET_break (0); 695 GNUNET_break (0);
663 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 696 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -667,7 +700,8 @@ handle_add_host (void *cls,
667 LOG_DEBUG ("Received ADDHOST message\n"); 700 LOG_DEBUG ("Received ADDHOST message\n");
668 LOG_DEBUG ("-------host id: %u\n", host_id); 701 LOG_DEBUG ("-------host id: %u\n", host_id);
669 if (NULL != hostname) LOG_DEBUG ("-------hostname: %s\n", hostname); 702 if (NULL != hostname) LOG_DEBUG ("-------hostname: %s\n", hostname);
670 if (NULL != username) LOG_DEBUG ("-------username: %s\n", username); 703 if (0 != username_length) LOG_DEBUG ("-------username: %s\n", username);
704 else LOG_DEBUG ("-------username: NULL\n");
671 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port)); 705 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
672 host = GNUNET_TESTBED_host_create_with_id (host_id, hostname, username, 706 host = GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
673 ntohs (msg->ssh_port)); 707 ntohs (msg->ssh_port));
@@ -887,15 +921,16 @@ handle_link_controllers (void *cls,
887 return; 921 return;
888 } 922 }
889 GNUNET_free (config); 923 GNUNET_free (config);
890 if (delegated_host_id >= slave_list_size) 924 if ((delegated_host_id < slave_list_size) &&
925 (NULL != slave_list[delegated_host_id]))
891 { 926 {
892 slave_list_size += LIST_GROW_STEP; 927 GNUNET_break (0); /* Configuration parsing error */
893 slave_list = GNUNET_realloc (slave_list, 928 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
894 sizeof (struct Slave *) * slave_list_size); 929 return;
895 } 930 }
896 slave = GNUNET_malloc (sizeof (struct Slave)); 931 slave = GNUNET_malloc (sizeof (struct Slave));
897 slave->host_id = delegated_host_id; 932 slave->host_id = delegated_host_id;
898 slave_list[delegated_host_id] = slave; 933 slave_list_add (slave);
899 if (1 == msg->is_subordinate) 934 if (1 == msg->is_subordinate)
900 { 935 {
901 slave->controller_proc = 936 slave->controller_proc =
@@ -1113,6 +1148,7 @@ testbed_run (void *cls,
1113 fh, 1148 fh,
1114 &shutdown_task, 1149 &shutdown_task,
1115 NULL); 1150 NULL);
1151 LOG_DEBUG ("Testbed startup complete\n");
1116} 1152}
1117 1153
1118 1154
diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c
new file mode 100644
index 000000000..612b30347
--- /dev/null
+++ b/src/testbed/test_testbed_api.c
@@ -0,0 +1,177 @@
1/*
2 This file is part of GNUnet
3 (C) 2008--2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file testbed/test_testbed_api.c
23 * @brief testcases for the testbed api
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_testing_lib-new.h"
30#include "gnunet_testbed_service.h"
31
32
33/**
34 * Generic logging shortcut
35 */
36#define LOG(kind,...) \
37 GNUNET_log (kind, __VA_ARGS__)
38
39
40/**
41 * Our localhost
42 */
43static struct GNUNET_TESTBED_Host *host;
44
45/**
46 * The controller handle
47 */
48static struct GNUNET_TESTBED_Controller *c;
49
50/**
51 * A neighbouring host
52 */
53static struct GNUNET_TESTBED_Host *neighbour;
54
55/**
56 * Handle for neighbour registration
57 */
58static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
59
60/**
61 * Abort task identifier
62 */
63static GNUNET_SCHEDULER_TaskIdentifier abort_task_id;
64
65/**
66 * The testing result
67 */
68static int result;
69
70
71/**
72 * Shutdown nicely
73 *
74 * @param cls NULL
75 * @param tc the task context
76 */
77static void
78do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
79{
80 if (GNUNET_SCHEDULER_NO_TASK != abort_task_id)
81 GNUNET_SCHEDULER_cancel (abort_task_id);
82 if (NULL != reg_handle)
83 GNUNET_TESTBED_cancel_registration (reg_handle);
84 GNUNET_TESTBED_controller_disconnect (c);
85 GNUNET_TESTBED_host_destroy (neighbour);
86 GNUNET_TESTBED_host_destroy (host);
87}
88
89
90/**
91 * abort task to run on test timed out
92 *
93 * @param cls NULL
94 * @param tc the task context
95 */
96static void
97do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
98{
99 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
100 abort_task_id = GNUNET_SCHEDULER_NO_TASK;
101 do_shutdown (cls, tc);
102}
103
104
105/**
106 * Signature of the event handler function called by the
107 * respective event controller.
108 *
109 * @param cls closure
110 * @param event information about the event
111 */
112static void
113controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
114{
115 GNUNET_break (0);
116}
117
118
119/**
120 * Callback which will be called to after a host registration succeeded or failed
121 *
122 * @param cls the host which has been registered
123 * @param emsg the error message; NULL if host registration is successful
124 */
125static void
126registration_comp (void *cls, const char *emsg)
127{
128 GNUNET_assert (cls == neighbour);
129 reg_handle = NULL;
130 result = GNUNET_YES;
131 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
132}
133
134
135/**
136 * Main point of test execution
137 */
138static void
139run (void *cls,
140 const struct GNUNET_CONFIGURATION_Handle *cfg,
141 struct GNUNET_TESTING_Peer *peer)
142{
143 uint64_t event_mask;
144
145 host = GNUNET_TESTBED_host_create (NULL, NULL, 0);
146 GNUNET_assert (NULL != host);
147 event_mask ^= event_mask; /* NULL out */
148 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
149 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
150 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
151 c = GNUNET_TESTBED_controller_connect (cfg, host, event_mask,
152 &controller_cb, NULL);
153 GNUNET_assert (NULL != c);
154 neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, 0);
155 GNUNET_assert (NULL != neighbour);
156 reg_handle =
157 GNUNET_TESTBED_register_host (c, neighbour, &registration_comp, neighbour);
158 GNUNET_assert (NULL != reg_handle);
159
160 abort_task_id = GNUNET_SCHEDULER_add_delayed
161 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30), &do_abort, NULL);
162}
163
164
165/**
166 * Main function
167 */
168int main (int argc, char **argv)
169{
170 result = GNUNET_SYSERR;
171 if (0 != GNUNET_TESTING_service_run ("test_testbed_api",
172 "testbed",
173 "test_testbed_api.conf",
174 &run, NULL))
175 return 1;
176 else return (GNUNET_OK == result) ? 0 : 1;
177}
diff --git a/src/testbed/test_testbed_api.conf b/src/testbed/test_testbed_api.conf
index c41ee9539..bf6c414b8 100644
--- a/src/testbed/test_testbed_api.conf
+++ b/src/testbed/test_testbed_api.conf
@@ -1,5 +1,9 @@
1[lockmanager] 1[testbed]
2AUTOSTART = NO 2AUTOSTART = NO
3PORT = 12113
4ACCEPT_FROM = 127.0.0.1;
5HOSTNAME = localhost
6#PREFIX = xterm -geometry 100x85 -T peer1 -e libtool --mode=execute gdb --args
3 7
4[fs] 8[fs]
5AUTOSTART = NO 9AUTOSTART = NO
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index cd8e2249c..c0967dca3 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -48,6 +48,18 @@
48#define LOG_DEBUG(...) \ 48#define LOG_DEBUG(...) \
49 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); 49 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);
50 50
51/**
52 * Relative time seconds shorthand
53 */
54#define TIME_REL_SECS(sec) \
55 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
56
57
58/**
59 * Default server message sending retry timeout
60 */
61#define TIMEOUT_REL TIME_REL_SECS(1)
62
51 63
52/** 64/**
53 * The message queue for sending messages to the controller service 65 * The message queue for sending messages to the controller service
@@ -289,6 +301,7 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
289 struct GNUNET_TESTBED_Controller *c = cls; 301 struct GNUNET_TESTBED_Controller *c = cls;
290 int status; 302 int status;
291 303
304 c->in_receive = GNUNET_NO;
292 /* FIXME: Add checks for message integrity */ 305 /* FIXME: Add checks for message integrity */
293 if (NULL == msg) 306 if (NULL == msg)
294 { 307 {
@@ -306,12 +319,14 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
306 default: 319 default:
307 GNUNET_break (0); 320 GNUNET_break (0);
308 } 321 }
309 if (GNUNET_OK == status) 322 if ((GNUNET_OK == status) && (GNUNET_NO == c->in_receive))
323 {
324 c->in_receive = GNUNET_YES;
310 GNUNET_CLIENT_receive (c->client, &message_handler, c, 325 GNUNET_CLIENT_receive (c->client, &message_handler, c,
311 GNUNET_TIME_UNIT_FOREVER_REL); 326 GNUNET_TIME_UNIT_FOREVER_REL);
327 }
312} 328}
313 329
314
315/** 330/**
316 * Function called to notify a client about the connection begin ready to queue 331 * Function called to notify a client about the connection begin ready to queue
317 * more data. "buf" will be NULL and "size" zero if the connection was closed 332 * more data. "buf" will be NULL and "size" zero if the connection was closed
@@ -331,9 +346,22 @@ transmit_ready_notify (void *cls, size_t size, void *buf)
331 c->th = NULL; 346 c->th = NULL;
332 mq_entry = c->mq_head; 347 mq_entry = c->mq_head;
333 GNUNET_assert (NULL != mq_entry); 348 GNUNET_assert (NULL != mq_entry);
349 if ((0 == size) && (NULL == buf)) /* Timeout */
350 {
351 LOG_DEBUG ("Message sending timed out -- retrying\n");
352 c->th =
353 GNUNET_CLIENT_notify_transmit_ready (c->client,
354 ntohs (mq_entry->msg->size),
355 TIMEOUT_REL,
356 GNUNET_YES, &transmit_ready_notify,
357 c);
358 return 0;
359 }
334 GNUNET_assert (ntohs (mq_entry->msg->size) <= size); 360 GNUNET_assert (ntohs (mq_entry->msg->size) <= size);
335 size = ntohs (mq_entry->msg->size); 361 size = ntohs (mq_entry->msg->size);
336 memcpy (buf, mq_entry->msg, size); 362 memcpy (buf, mq_entry->msg, size);
363 LOG_DEBUG ("Message of type: %u and size: %u sent\n",
364 ntohs (mq_entry->msg->type), size);
337 GNUNET_free (mq_entry->msg); 365 GNUNET_free (mq_entry->msg);
338 GNUNET_CONTAINER_DLL_remove (c->mq_head, c->mq_tail, mq_entry); 366 GNUNET_CONTAINER_DLL_remove (c->mq_head, c->mq_tail, mq_entry);
339 GNUNET_free (mq_entry); 367 GNUNET_free (mq_entry);
@@ -342,11 +370,10 @@ transmit_ready_notify (void *cls, size_t size, void *buf)
342 c->th = 370 c->th =
343 GNUNET_CLIENT_notify_transmit_ready (c->client, 371 GNUNET_CLIENT_notify_transmit_ready (c->client,
344 ntohs (mq_entry->msg->size), 372 ntohs (mq_entry->msg->size),
345 GNUNET_TIME_UNIT_FOREVER_REL, 373 TIMEOUT_REL,
346 GNUNET_NO, &transmit_ready_notify, 374 GNUNET_YES, &transmit_ready_notify,
347 c); 375 c);
348 if ( (GNUNET_NO == c->in_receive) && 376 if (GNUNET_NO == c->in_receive)
349 (size > 0) )
350 { 377 {
351 c->in_receive = GNUNET_YES; 378 c->in_receive = GNUNET_YES;
352 GNUNET_CLIENT_receive (c->client, &message_handler, c, 379 GNUNET_CLIENT_receive (c->client, &message_handler, c,
@@ -384,8 +411,8 @@ queue_message (struct GNUNET_TESTBED_Controller *controller,
384 if (NULL == controller->th) 411 if (NULL == controller->th)
385 controller->th = 412 controller->th =
386 GNUNET_CLIENT_notify_transmit_ready (controller->client, size, 413 GNUNET_CLIENT_notify_transmit_ready (controller->client, size,
387 GNUNET_TIME_UNIT_FOREVER_REL, 414 TIMEOUT_REL,
388 GNUNET_NO, &transmit_ready_notify, 415 GNUNET_YES, &transmit_ready_notify,
389 controller); 416 controller);
390} 417}
391 418
@@ -634,7 +661,7 @@ GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
634 msg->user_name_length = htons (user_name_length); 661 msg->user_name_length = htons (user_name_length);
635 if (NULL != username) 662 if (NULL != username)
636 memcpy (&msg[1], username, user_name_length); 663 memcpy (&msg[1], username, user_name_length);
637 strcpy (((void *) msg) + user_name_length, hostname); 664 strcpy (((void *) &msg[1]) + user_name_length, hostname);
638 queue_message (controller, (struct GNUNET_MessageHeader *) msg); 665 queue_message (controller, (struct GNUNET_MessageHeader *) msg);
639 return rh; 666 return rh;
640} 667}