summaryrefslogtreecommitdiff
path: root/src/testbed/test_testbed_api_topology.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/test_testbed_api_topology.c')
-rw-r--r--src/testbed/test_testbed_api_topology.c150
1 files changed, 76 insertions, 74 deletions
diff --git a/src/testbed/test_testbed_api_topology.c b/src/testbed/test_testbed_api_topology.c
index d1b8da31a..c6e25c656 100644
--- a/src/testbed/test_testbed_api_topology.c
+++ b/src/testbed/test_testbed_api_topology.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2008--2013 GNUnet e.V. 3 Copyright (C) 2008--2013 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 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, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file src/testbed/test_testbed_api_topology.c 22 * @file src/testbed/test_testbed_api_topology.c
@@ -65,15 +65,15 @@ static unsigned int overlay_connects;
65 * @param cls NULL 65 * @param cls NULL
66 */ 66 */
67static void 67static void
68do_shutdown (void *cls) 68do_shutdown(void *cls)
69{ 69{
70 shutdown_task = NULL; 70 shutdown_task = NULL;
71 if (NULL != op) 71 if (NULL != op)
72 { 72 {
73 GNUNET_TESTBED_operation_done (op); 73 GNUNET_TESTBED_operation_done(op);
74 op = NULL; 74 op = NULL;
75 } 75 }
76 GNUNET_SCHEDULER_shutdown (); 76 GNUNET_SCHEDULER_shutdown();
77} 77}
78 78
79/** 79/**
@@ -83,34 +83,36 @@ do_shutdown (void *cls)
83 * @param event the controller event 83 * @param event the controller event
84 */ 84 */
85static void 85static void
86controller_event_cb (void *cls, 86controller_event_cb(void *cls,
87 const struct GNUNET_TESTBED_EventInformation *event) 87 const struct GNUNET_TESTBED_EventInformation *event)
88{ 88{
89 switch (event->type) 89 switch (event->type)
90 {
91 case GNUNET_TESTBED_ET_CONNECT:
92 overlay_connects++;
93 if ((NUM_PEERS) == overlay_connects)
94 { 90 {
95 result = GNUNET_OK; 91 case GNUNET_TESTBED_ET_CONNECT:
96 GNUNET_SCHEDULER_cancel (shutdown_task); 92 overlay_connects++;
97 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 93 if ((NUM_PEERS) == overlay_connects)
94 {
95 result = GNUNET_OK;
96 GNUNET_SCHEDULER_cancel(shutdown_task);
97 shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL);
98 }
99 break;
100
101 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
102 GNUNET_assert(NULL != event->details.operation_finished.emsg);
103 break;
104
105 default:
106 GNUNET_break(0);
107 if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) &&
108 (NULL != event->details.operation_finished.emsg))
109 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
110 "An operation failed with error: %s\n",
111 event->details.operation_finished.emsg);
112 result = GNUNET_SYSERR;
113 GNUNET_SCHEDULER_cancel(shutdown_task);
114 shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL);
98 } 115 }
99 break;
100 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
101 GNUNET_assert (NULL != event->details.operation_finished.emsg);
102 break;
103 default:
104 GNUNET_break (0);
105 if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) &&
106 (NULL != event->details.operation_finished.emsg))
107 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
108 "An operation failed with error: %s\n",
109 event->details.operation_finished.emsg);
110 result = GNUNET_SYSERR;
111 GNUNET_SCHEDULER_cancel (shutdown_task);
112 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
113 }
114} 116}
115 117
116 118
@@ -127,37 +129,37 @@ controller_event_cb (void *cls,
127 * failed 129 * failed
128 */ 130 */
129static void 131static void
130test_master (void *cls, 132test_master(void *cls,
131 struct GNUNET_TESTBED_RunHandle *h, 133 struct GNUNET_TESTBED_RunHandle *h,
132 unsigned int num_peers, 134 unsigned int num_peers,
133 struct GNUNET_TESTBED_Peer **peers_, 135 struct GNUNET_TESTBED_Peer **peers_,
134 unsigned int links_succeeded, 136 unsigned int links_succeeded,
135 unsigned int links_failed) 137 unsigned int links_failed)
136{ 138{
137 unsigned int peer; 139 unsigned int peer;
138 140
139 GNUNET_assert (NULL == cls); 141 GNUNET_assert(NULL == cls);
140 if (NULL == peers_) 142 if (NULL == peers_)
141 { 143 {
142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); 144 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n");
143 return; 145 return;
144 } 146 }
145 GNUNET_assert (NUM_PEERS == num_peers); 147 GNUNET_assert(NUM_PEERS == num_peers);
146 for (peer = 0; peer < num_peers; peer++) 148 for (peer = 0; peer < num_peers; peer++)
147 GNUNET_assert (NULL != peers_[peer]); 149 GNUNET_assert(NULL != peers_[peer]);
148 peers = peers_; 150 peers = peers_;
149 overlay_connects = 0; 151 overlay_connects = 0;
150 op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, NULL, 152 op = GNUNET_TESTBED_overlay_configure_topology(NULL, NUM_PEERS, peers, NULL,
151 NULL, 153 NULL,
152 NULL, 154 NULL,
153 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, 155 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
154 NUM_PEERS, 156 NUM_PEERS,
155 GNUNET_TESTBED_TOPOLOGY_OPTION_END); 157 GNUNET_TESTBED_TOPOLOGY_OPTION_END);
156 GNUNET_assert (NULL != op); 158 GNUNET_assert(NULL != op);
157 shutdown_task = 159 shutdown_task =
158 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 160 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply
159 (GNUNET_TIME_UNIT_SECONDS, 300), 161 (GNUNET_TIME_UNIT_SECONDS, 300),
160 do_shutdown, NULL); 162 do_shutdown, NULL);
161} 163}
162 164
163 165
@@ -165,7 +167,7 @@ test_master (void *cls,
165 * Main function 167 * Main function
166 */ 168 */
167int 169int
168main (int argc, char **argv) 170main(int argc, char **argv)
169{ 171{
170 uint64_t event_mask; 172 uint64_t event_mask;
171 173
@@ -173,10 +175,10 @@ main (int argc, char **argv)
173 event_mask = 0; 175 event_mask = 0;
174 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); 176 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
175 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); 177 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
176 (void) GNUNET_TESTBED_test_run ("test_testbed_api_test", 178 (void)GNUNET_TESTBED_test_run("test_testbed_api_test",
177 "test_testbed_api.conf", NUM_PEERS, 179 "test_testbed_api.conf", NUM_PEERS,
178 event_mask, &controller_event_cb, NULL, 180 event_mask, &controller_event_cb, NULL,
179 &test_master, NULL); 181 &test_master, NULL);
180 if (GNUNET_OK != result) 182 if (GNUNET_OK != result)
181 return 1; 183 return 1;
182 return 0; 184 return 0;