aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-04-02 16:54:35 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-04-02 16:54:35 +0000
commit8eb1702f2a5944ebdccae9d9e37b58e6fec290cc (patch)
treef67caa35a36afaf61ca7e57f0f816e26f2132712 /src
parent68eb732cc6e17c765a00eb6841130b0e3b9de9b3 (diff)
downloadgnunet-8eb1702f2a5944ebdccae9d9e37b58e6fec290cc.tar.gz
gnunet-8eb1702f2a5944ebdccae9d9e37b58e6fec290cc.zip
- test case for starting/stopping peer's services
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_testbed_service.h24
-rw-r--r--src/testbed/Makefile.am10
-rw-r--r--src/testbed/gnunet-service-testbed.c3
-rw-r--r--src/testbed/test_testbed_api_peers_manage_services.c211
4 files changed, 246 insertions, 2 deletions
diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h
index 5aa4bd727..522484821 100644
--- a/src/include/gnunet_testbed_service.h
+++ b/src/include/gnunet_testbed_service.h
@@ -882,6 +882,30 @@ GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
882 882
883 883
884/** 884/**
885 * Start or stop given service at a peer. This should not be called to
886 * start/stop the peer's ARM service. Use GNUNET_TESTBED_peer_start(),
887 * GNUNET_TESTBED_peer_stop() for starting/stopping peer's ARM service. Success
888 * or failure of the generated operation is signalled through the controller
889 * event callback and/or operation completion callback.
890 *
891 * @param op_cls the closure for the operation
892 * @param peer the peer whose service is to be started/stopped
893 * @param service_name the name of the service
894 * @param cb the operation completion callback
895 * @param cb_cls the closure for the operation completion callback
896 * @param start 1 to start the service; 0 to stop the service
897 * @return an operation handle; NULL upon error (peer not running)
898 */
899struct GNUNET_TESTBED_Operation *
900GNUNET_TESTBED_peer_manage_service (void *op_cls,
901 struct GNUNET_TESTBED_Peer *peer,
902 const char *service_name,
903 GNUNET_TESTBED_OperationCompletionCallback cb,
904 void *cb_cls,
905 unsigned int start);
906
907
908/**
885 * Stops and destroys all peers. Is equivalent of calling 909 * Stops and destroys all peers. Is equivalent of calling
886 * GNUNET_TESTBED_peer_stop() and GNUNET_TESTBED_peer_destroy() on all peers, 910 * GNUNET_TESTBED_peer_stop() and GNUNET_TESTBED_peer_destroy() on all peers,
887 * except that the peer stop event and operation finished event corresponding to 911 * except that the peer stop event and operation finished event corresponding to
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index 20056fba1..af61135f6 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -102,6 +102,7 @@ libgnunettestbed_la_LDFLAGS = \
102 102
103check_PROGRAMS = \ 103check_PROGRAMS = \
104 test_testbed_api_hosts \ 104 test_testbed_api_hosts \
105 test_gnunet_helper_testbed \
105 test_testbed_api_controllerlink \ 106 test_testbed_api_controllerlink \
106 test_testbed_api_2peers_1controller \ 107 test_testbed_api_2peers_1controller \
107 test_testbed_api_3peers_3controllers \ 108 test_testbed_api_3peers_3controllers \
@@ -111,7 +112,7 @@ check_PROGRAMS = \
111 test_testbed_api_testbed_run \ 112 test_testbed_api_testbed_run \
112 test_testbed_api_test \ 113 test_testbed_api_test \
113 test_testbed_api_test_timeout \ 114 test_testbed_api_test_timeout \
114 test_gnunet_helper_testbed \ 115 test_testbed_api_peers_manage_services \
115 test_testbed_api_topology \ 116 test_testbed_api_topology \
116 test_testbed_api_topology_clique \ 117 test_testbed_api_topology_clique \
117 test_testbed_api_testbed_run_topologyrandom \ 118 test_testbed_api_testbed_run_topologyrandom \
@@ -139,6 +140,7 @@ if ENABLE_TEST_RUN
139 test_testbed_api_test \ 140 test_testbed_api_test \
140 test_testbed_api_test_timeout \ 141 test_testbed_api_test_timeout \
141 test_testbed_api_statistics \ 142 test_testbed_api_statistics \
143 test_testbed_api_peers_manage_services \
142 test_testbed_api_topology \ 144 test_testbed_api_topology \
143 test_testbed_api_topology_clique \ 145 test_testbed_api_topology_clique \
144 test_testbed_api_testbed_run_topologyrandom \ 146 test_testbed_api_testbed_run_topologyrandom \
@@ -295,6 +297,12 @@ test_testbed_api_statistics_LDADD = \
295 $(top_builddir)/src/util/libgnunetutil.la \ 297 $(top_builddir)/src/util/libgnunetutil.la \
296 libgnunettestbed.la 298 libgnunettestbed.la
297 299
300test_testbed_api_peers_manage_services_SOURCES = \
301 test_testbed_api_peers_manage_services.c
302test_testbed_api_peers_manage_services_LDADD = \
303 $(top_builddir)/src/util/libgnunetutil.la \
304 libgnunettestbed.la
305
298EXTRA_DIST = \ 306EXTRA_DIST = \
299 test_testbed_api.conf \ 307 test_testbed_api.conf \
300 test_testbed_api_test_timeout.conf \ 308 test_testbed_api_test_timeout.conf \
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 247d7391d..84a508b34 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -25,6 +25,7 @@
25 */ 25 */
26 26
27#include "gnunet-service-testbed.h" 27#include "gnunet-service-testbed.h"
28#include "gnunet_arm_service.h"
28 29
29#include <zlib.h> 30#include <zlib.h>
30 31
@@ -2137,7 +2138,7 @@ service_manage_result_cb (void *cls, struct GNUNET_ARM_Handle *arm,
2137 } 2138 }
2138 else 2139 else
2139 send_operation_success_msg (mctx->client, mctx->op_id); 2140 send_operation_success_msg (mctx->client, mctx->op_id);
2140 GNUNET_free (emsg); 2141 GNUNET_free_non_null (emsg);
2141 cleanup_mctx (mctx); 2142 cleanup_mctx (mctx);
2142} 2143}
2143 2144
diff --git a/src/testbed/test_testbed_api_peers_manage_services.c b/src/testbed/test_testbed_api_peers_manage_services.c
new file mode 100644
index 000000000..cccccd207
--- /dev/null
+++ b/src/testbed/test_testbed_api_peers_manage_services.c
@@ -0,0 +1,211 @@
1/*
2 This file is part of GNUnet
3 (C) 2008--2013 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_peers_manage_services.c
23 * @brief testcase for testing GNUNET_TESTBED_peer_manage_service()
24 * implementation
25 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
26 */
27
28#include "platform.h"
29#include "gnunet_common.h"
30#include "gnunet_testbed_service.h"
31
32/**
33 * Number of peers we want to start
34 */
35#define NUM_PEERS 2
36
37/**
38 * The array of peers; we get them from the testbed
39 */
40static struct GNUNET_TESTBED_Peer **peers;
41
42/**
43 * Operation handle
44 */
45static struct GNUNET_TESTBED_Operation *op;
46
47/**
48 * dummy pointer
49 */
50static void *dummy_cls = (void *) 0xDEAD0001;
51
52/**
53 * Abort task identifier
54 */
55static GNUNET_SCHEDULER_TaskIdentifier abort_task;
56
57/**
58 * States in this test
59 */
60enum {
61
62 /**
63 * Test has just been initialized
64 */
65 STATE_INIT,
66
67 /**
68 * Peers have been started
69 */
70 STATE_PEERS_STARTED,
71
72 /**
73 * statistics service went down
74 */
75 STATE_SERVICE_DOWN,
76
77 /**
78 * statistics service went up
79 */
80 STATE_SERVICE_UP,
81
82 /**
83 * Testing completed successfully
84 */
85 STATE_OK
86} state;
87
88/**
89 * Fail testcase
90 */
91#define FAIL_TEST(cond, ret) do { \
92 if (!(cond)) { \
93 GNUNET_break(0); \
94 if (GNUNET_SCHEDULER_NO_TASK != abort_task) \
95 GNUNET_SCHEDULER_cancel (abort_task); \
96 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
97 ret; \
98 } \
99 } while (0)
100
101
102/**
103 * Abort task
104 *
105 * @param cls NULL
106 * @param tc scheduler task context
107 */
108static void
109do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
110{
111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test timed out -- Aborting\n");
112 abort_task = GNUNET_SCHEDULER_NO_TASK;
113 if (NULL != op)
114 {
115 GNUNET_TESTBED_operation_done (op);
116 op = NULL;
117 }
118 GNUNET_SCHEDULER_shutdown();
119}
120
121
122/**
123 * Callback to be called when an operation is completed
124 *
125 * @param cls the callback closure from functions generating an operation
126 * @param op the operation that has been finished
127 * @param emsg error message in case the operation has failed; will be NULL if
128 * operation has executed successfully.
129 */
130static void
131op_comp_cb (void *cls,
132 struct GNUNET_TESTBED_Operation *op,
133 const char *emsg)
134{
135 FAIL_TEST (cls == dummy_cls, return);
136 FAIL_TEST (NULL == emsg, return);
137 GNUNET_TESTBED_operation_done (op);
138 op = NULL;
139 switch (state)
140 {
141 case STATE_PEERS_STARTED:
142 state = STATE_SERVICE_DOWN;
143 op = GNUNET_TESTBED_peer_manage_service (dummy_cls,
144 peers[1],
145 "statistics",
146 op_comp_cb,
147 dummy_cls,
148 1);
149 break;
150 case STATE_SERVICE_DOWN:
151 state = STATE_SERVICE_UP;
152 GNUNET_SCHEDULER_cancel (abort_task);
153 abort_task = GNUNET_SCHEDULER_NO_TASK;
154 state = STATE_OK;
155 GNUNET_SCHEDULER_shutdown ();
156 break;
157 default:
158 FAIL_TEST (0, return);
159 }
160}
161
162
163/**
164 * Signature of a main function for a testcase.
165 *
166 * @param cls closure
167 * @param num_peers number of peers in 'peers'
168 * @param peers_ handle to peers run in the testbed
169 * @param links_succeeded the number of overlay link connection attempts that
170 * succeeded
171 * @param links_failed the number of overlay link connection attempts that
172 * failed
173 */
174static void
175test_master (void *cls, unsigned int num_peers,
176 struct GNUNET_TESTBED_Peer **peers_,
177 unsigned int links_succeeded,
178 unsigned int links_failed)
179{
180 FAIL_TEST (NUM_PEERS == num_peers, return);
181 state = STATE_PEERS_STARTED;
182 peers = peers_;
183 op = GNUNET_TESTBED_peer_manage_service (dummy_cls,
184 peers[1],
185 "statistics",
186 op_comp_cb,
187 dummy_cls,
188 0);
189 FAIL_TEST (NULL != op, return);
190 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
191 (GNUNET_TIME_UNIT_MINUTES, 1),
192 &do_abort, NULL);
193}
194
195
196/**
197 * Main function
198 */
199int
200main (int argc, char **argv)
201{
202 state = STATE_INIT;
203 (void) GNUNET_TESTBED_test_run ("test_testbed_api_statistics",
204 "test_testbed_api_statistics.conf",
205 NUM_PEERS,
206 1LL, NULL, NULL,
207 &test_master, NULL);
208 if (STATE_OK != state)
209 return 1;
210 return 0;
211}