diff options
Diffstat (limited to 'src/testbed/test_testbed_api_peer_reconfiguration.c')
-rw-r--r-- | src/testbed/test_testbed_api_peer_reconfiguration.c | 194 |
1 files changed, 0 insertions, 194 deletions
diff --git a/src/testbed/test_testbed_api_peer_reconfiguration.c b/src/testbed/test_testbed_api_peer_reconfiguration.c deleted file mode 100644 index 22dd46b53..000000000 --- a/src/testbed/test_testbed_api_peer_reconfiguration.c +++ /dev/null | |||
@@ -1,194 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2008--2013 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your 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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testbed/test_testbed_api_peer_reconfiguration.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_util_lib.h" | ||
30 | #include "gnunet_testbed_service.h" | ||
31 | |||
32 | /** | ||
33 | * Number of peers we want to start | ||
34 | */ | ||
35 | #define NUM_PEERS 1 | ||
36 | |||
37 | /** | ||
38 | * The array of peers; we get them from the testbed | ||
39 | */ | ||
40 | static struct GNUNET_TESTBED_Peer **peers; | ||
41 | |||
42 | /** | ||
43 | * Operation handle | ||
44 | */ | ||
45 | static struct GNUNET_TESTBED_Operation *op; | ||
46 | |||
47 | /** | ||
48 | * Abort task identifier | ||
49 | */ | ||
50 | static struct GNUNET_SCHEDULER_Task *abort_task; | ||
51 | |||
52 | /** | ||
53 | * States in this test | ||
54 | */ | ||
55 | enum | ||
56 | { | ||
57 | /** | ||
58 | * Test has just been initialized | ||
59 | */ | ||
60 | STATE_INIT, | ||
61 | |||
62 | /** | ||
63 | * Peers have been started | ||
64 | */ | ||
65 | STATE_PEER_STARTED, | ||
66 | |||
67 | /** | ||
68 | * Peer has been reconfigured. Test completed successfully | ||
69 | */ | ||
70 | STATE_PEER_RECONFIGURED | ||
71 | } state; | ||
72 | |||
73 | /** | ||
74 | * Fail testcase | ||
75 | */ | ||
76 | #define FAIL_TEST(cond, ret) do { \ | ||
77 | if (! (cond)) { \ | ||
78 | GNUNET_break (0); \ | ||
79 | if (NULL != abort_task) \ | ||
80 | GNUNET_SCHEDULER_cancel (abort_task); \ | ||
81 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \ | ||
82 | ret; \ | ||
83 | } \ | ||
84 | } while (0) | ||
85 | |||
86 | |||
87 | /** | ||
88 | * Abort task | ||
89 | * | ||
90 | * @param cls NULL | ||
91 | */ | ||
92 | static void | ||
93 | do_abort (void *cls) | ||
94 | { | ||
95 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting\n"); | ||
96 | abort_task = NULL; | ||
97 | if (NULL != op) | ||
98 | { | ||
99 | GNUNET_TESTBED_operation_done (op); | ||
100 | op = NULL; | ||
101 | } | ||
102 | GNUNET_SCHEDULER_shutdown (); | ||
103 | } | ||
104 | |||
105 | |||
106 | /** | ||
107 | * Signature of the event handler function called by the | ||
108 | * respective event controller. | ||
109 | * | ||
110 | * @param cls closure | ||
111 | * @param event information about the event | ||
112 | */ | ||
113 | static void | ||
114 | controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | ||
115 | { | ||
116 | if (STATE_PEER_STARTED != state) | ||
117 | return; | ||
118 | if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type) | ||
119 | { | ||
120 | GNUNET_TESTBED_operation_done (op); | ||
121 | op = NULL; | ||
122 | FAIL_TEST (0, return ); | ||
123 | } | ||
124 | if (NULL != event->details.operation_finished.emsg) | ||
125 | { | ||
126 | fprintf (stderr, "Operation failed: %s\n", | ||
127 | event->details.operation_finished.emsg); | ||
128 | GNUNET_TESTBED_operation_done (op); | ||
129 | op = NULL; | ||
130 | FAIL_TEST (0, return ); | ||
131 | } | ||
132 | GNUNET_TESTBED_operation_done (op); | ||
133 | state = STATE_PEER_RECONFIGURED; | ||
134 | GNUNET_SCHEDULER_cancel (abort_task); | ||
135 | abort_task = NULL; | ||
136 | GNUNET_SCHEDULER_shutdown (); | ||
137 | } | ||
138 | |||
139 | |||
140 | /** | ||
141 | * Signature of a main function for a testcase. | ||
142 | * | ||
143 | * @param cls closure | ||
144 | * @param h the run handle | ||
145 | * @param num_peers number of peers in 'peers' | ||
146 | * @param peers_ handle to peers run in the testbed | ||
147 | * @param links_succeeded the number of overlay link connection attempts that | ||
148 | * succeeded | ||
149 | * @param links_failed the number of overlay link connection attempts that | ||
150 | * failed | ||
151 | */ | ||
152 | static void | ||
153 | test_master (void *cls, | ||
154 | struct GNUNET_TESTBED_RunHandle *h, | ||
155 | unsigned int num_peers, | ||
156 | struct GNUNET_TESTBED_Peer **peers_, | ||
157 | unsigned int links_succeeded, | ||
158 | unsigned int links_failed) | ||
159 | { | ||
160 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
161 | |||
162 | FAIL_TEST (NUM_PEERS == num_peers, return ); | ||
163 | state = STATE_PEER_STARTED; | ||
164 | peers = peers_; | ||
165 | cfg = GNUNET_CONFIGURATION_create (); | ||
166 | FAIL_TEST (GNUNET_OK == GNUNET_CONFIGURATION_load | ||
167 | (cfg, "test_testbed_api_testbed_run_topologyrandom.conf"), | ||
168 | return ); | ||
169 | op = GNUNET_TESTBED_peer_update_configuration (peers[0], cfg); | ||
170 | GNUNET_CONFIGURATION_destroy (cfg); | ||
171 | FAIL_TEST (NULL != op, return ); | ||
172 | abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
173 | (GNUNET_TIME_UNIT_SECONDS, 30), | ||
174 | &do_abort, NULL); | ||
175 | } | ||
176 | |||
177 | |||
178 | /** | ||
179 | * Main function | ||
180 | */ | ||
181 | int | ||
182 | main (int argc, char **argv) | ||
183 | { | ||
184 | state = STATE_INIT; | ||
185 | (void) GNUNET_TESTBED_test_run ("test_testbed_api_peer_reconfiguration", | ||
186 | "test_testbed_api.conf", | ||
187 | NUM_PEERS, | ||
188 | 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED, | ||
189 | &controller_cb, NULL, | ||
190 | &test_master, NULL); | ||
191 | if (STATE_PEER_RECONFIGURED != state) | ||
192 | return 1; | ||
193 | return 0; | ||
194 | } | ||