2 This file is part of GNUnet
3 Copyright (C) 2008--2013 GNUnet e.V.
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.
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.
17 * @file testbed/test_testbed_underlay.c
18 * @brief testcase binary for testing testbed underlay restrictions
19 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
23 #include "gnunet_util_lib.h"
24 #include "gnunet_testbed_service.h"
28 * Number of peers we start in this test case
33 * Result of this test case
37 static struct GNUNET_TESTBED_Operation *op;
44 * @param tc scheduler task context
47 do_shutdown (void *cls)
50 GNUNET_TESTBED_operation_done (op);
56 * Callback to be called when an operation is completed
58 * @param cls the callback closure from functions generating an operation
59 * @param op the operation that has been finished
60 * @param emsg error message in case the operation has failed; will be NULL if
61 * operation has executed successfully.
64 overlay_connect_status (void *cls,
65 struct GNUNET_TESTBED_Operation *op_,
68 GNUNET_assert (op_ == op);
69 GNUNET_TESTBED_operation_done (op);
72 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peers 0 and 2 should not get connected\n");
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers 0 and 2 not connected: %s. Success!\n", emsg);
78 GNUNET_SCHEDULER_shutdown ();
84 * Signature of a main function for a testcase.
87 * @param h the run handle
88 * @param num_peers number of peers in 'peers'
89 * @param peers_ handle to peers run in the testbed
90 * @param links_succeeded the number of overlay link connection attempts that
92 * @param links_failed the number of overlay link connection attempts that
96 test_master (void *cls,
97 struct GNUNET_TESTBED_RunHandle *h,
98 unsigned int num_peers,
99 struct GNUNET_TESTBED_Peer **peers_,
100 unsigned int links_succeeded,
101 unsigned int links_failed)
103 GNUNET_assert (NULL == cls);
106 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n");
107 GNUNET_SCHEDULER_shutdown ();
110 GNUNET_assert (NUM_PEERS == num_peers);
111 op = GNUNET_TESTBED_overlay_connect (NULL,
112 &overlay_connect_status,
116 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
124 * Assumed maximum path length (for the log file name).
126 #define PATH_MAX 4096
134 main (int argc, char **argv)
136 struct GNUNET_CONFIGURATION_Handle *cfg;
141 result = GNUNET_SYSERR;
143 cfg = GNUNET_CONFIGURATION_create ();
144 GNUNET_assert (GNUNET_YES ==
145 GNUNET_CONFIGURATION_parse (cfg,
146 "test_testbed_underlay.conf.in"));
147 if (NULL == getcwd (pwd, PATH_MAX))
149 GNUNET_assert (0 < GNUNET_asprintf (&dbfile, "%s/%s", pwd,
150 "test-underlay.sqlite"));
151 GNUNET_CONFIGURATION_set_value_string (cfg, "TESTBED-UNDERLAY","DBFILE", dbfile);
152 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write
153 (cfg, "test_testbed_underlay.conf"));
154 GNUNET_CONFIGURATION_destroy (cfg);
156 GNUNET_free (dbfile);
158 (void) GNUNET_TESTBED_test_run ("test_testbed_underlay",
159 "test_testbed_underlay.conf", NUM_PEERS,
160 event_mask, NULL, NULL,
162 (void) unlink ("test_testbed_underlay.conf");
163 if (GNUNET_OK != result)