diff options
Diffstat (limited to 'src/testbed/test_testbed_api_topology.c')
-rw-r--r-- | src/testbed/test_testbed_api_topology.c | 189 |
1 files changed, 0 insertions, 189 deletions
diff --git a/src/testbed/test_testbed_api_topology.c b/src/testbed/test_testbed_api_topology.c deleted file mode 100644 index dada7286f..000000000 --- a/src/testbed/test_testbed_api_topology.c +++ /dev/null | |||
@@ -1,189 +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 src/testbed/test_testbed_api_topology.c | ||
23 | * @brief testing cases for testing high level testbed api helper functions | ||
24 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_testbed_service.h" | ||
30 | |||
31 | /** | ||
32 | * Number of peers we want to start | ||
33 | */ | ||
34 | #define NUM_PEERS 10 | ||
35 | |||
36 | /** | ||
37 | * Array of peers | ||
38 | */ | ||
39 | static struct GNUNET_TESTBED_Peer **peers; | ||
40 | |||
41 | /** | ||
42 | * Operation handle | ||
43 | */ | ||
44 | static struct GNUNET_TESTBED_Operation *op; | ||
45 | |||
46 | /** | ||
47 | * Shutdown task | ||
48 | */ | ||
49 | static struct GNUNET_SCHEDULER_Task *shutdown_task; | ||
50 | |||
51 | /** | ||
52 | * Testing result | ||
53 | */ | ||
54 | static int result; | ||
55 | |||
56 | /** | ||
57 | * Counter for counting overlay connections | ||
58 | */ | ||
59 | static unsigned int overlay_connects; | ||
60 | |||
61 | |||
62 | /** | ||
63 | * Shutdown nicely | ||
64 | * | ||
65 | * @param cls NULL | ||
66 | */ | ||
67 | static void | ||
68 | do_shutdown (void *cls) | ||
69 | { | ||
70 | shutdown_task = NULL; | ||
71 | if (NULL != op) | ||
72 | { | ||
73 | GNUNET_TESTBED_operation_done (op); | ||
74 | op = NULL; | ||
75 | } | ||
76 | GNUNET_SCHEDULER_shutdown (); | ||
77 | } | ||
78 | |||
79 | |||
80 | /** | ||
81 | * Controller event callback | ||
82 | * | ||
83 | * @param cls NULL | ||
84 | * @param event the controller event | ||
85 | */ | ||
86 | static void | ||
87 | controller_event_cb (void *cls, | ||
88 | const struct GNUNET_TESTBED_EventInformation *event) | ||
89 | { | ||
90 | switch (event->type) | ||
91 | { | ||
92 | case GNUNET_TESTBED_ET_CONNECT: | ||
93 | overlay_connects++; | ||
94 | if ((NUM_PEERS) == overlay_connects) | ||
95 | { | ||
96 | result = GNUNET_OK; | ||
97 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
98 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
99 | } | ||
100 | break; | ||
101 | |||
102 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
103 | GNUNET_assert (NULL != event->details.operation_finished.emsg); | ||
104 | break; | ||
105 | |||
106 | default: | ||
107 | GNUNET_break (0); | ||
108 | if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) && | ||
109 | (NULL != event->details.operation_finished.emsg)) | ||
110 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
111 | "An operation failed with error: %s\n", | ||
112 | event->details.operation_finished.emsg); | ||
113 | result = GNUNET_SYSERR; | ||
114 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
115 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
116 | } | ||
117 | } | ||
118 | |||
119 | |||
120 | /** | ||
121 | * Signature of a main function for a testcase. | ||
122 | * | ||
123 | * @param cls closure | ||
124 | * @param h the run handle | ||
125 | * @param num_peers number of peers in 'peers' | ||
126 | * @param peers_ handle to peers run in the testbed | ||
127 | * @param links_succeeded the number of overlay link connection attempts that | ||
128 | * succeeded | ||
129 | * @param links_failed the number of overlay link connection attempts that | ||
130 | * failed | ||
131 | */ | ||
132 | static void | ||
133 | test_master (void *cls, | ||
134 | struct GNUNET_TESTBED_RunHandle *h, | ||
135 | unsigned int num_peers, | ||
136 | struct GNUNET_TESTBED_Peer **peers_, | ||
137 | unsigned int links_succeeded, | ||
138 | unsigned int links_failed) | ||
139 | { | ||
140 | unsigned int peer; | ||
141 | |||
142 | GNUNET_assert (NULL == cls); | ||
143 | if (NULL == peers_) | ||
144 | { | ||
145 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); | ||
146 | return; | ||
147 | } | ||
148 | GNUNET_assert (NUM_PEERS == num_peers); | ||
149 | for (peer = 0; peer < num_peers; peer++) | ||
150 | GNUNET_assert (NULL != peers_[peer]); | ||
151 | peers = peers_; | ||
152 | overlay_connects = 0; | ||
153 | op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, NULL, | ||
154 | NULL, | ||
155 | NULL, | ||
156 | GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, | ||
157 | NUM_PEERS, | ||
158 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | ||
159 | GNUNET_assert (NULL != op); | ||
160 | shutdown_task = | ||
161 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
162 | (GNUNET_TIME_UNIT_SECONDS, 300), | ||
163 | do_shutdown, NULL); | ||
164 | } | ||
165 | |||
166 | |||
167 | /** | ||
168 | * Main function | ||
169 | */ | ||
170 | int | ||
171 | main (int argc, char **argv) | ||
172 | { | ||
173 | uint64_t event_mask; | ||
174 | |||
175 | result = GNUNET_SYSERR; | ||
176 | event_mask = 0; | ||
177 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | ||
178 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | ||
179 | (void) GNUNET_TESTBED_test_run ("test_testbed_api_test", | ||
180 | "test_testbed_api.conf", NUM_PEERS, | ||
181 | event_mask, &controller_event_cb, NULL, | ||
182 | &test_master, NULL); | ||
183 | if (GNUNET_OK != result) | ||
184 | return 1; | ||
185 | return 0; | ||
186 | } | ||
187 | |||
188 | |||
189 | /* end of test_testbed_api_topology.c */ | ||