aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/test_testbed_underlay.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2014-01-08 15:02:20 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2014-01-08 15:02:20 +0000
commitce8e0739623ee25d2a29a75f393027a42bbe4d4f (patch)
treee7e81cdd5acda711d738706b9a1ff141b819b2cd /src/testbed/test_testbed_underlay.c
parent8b69aded04512e71f742c2ee60be174af18a8759 (diff)
downloadgnunet-ce8e0739623ee25d2a29a75f393027a42bbe4d4f.tar.gz
gnunet-ce8e0739623ee25d2a29a75f393027a42bbe4d4f.zip
- testbed underlay testcase
Diffstat (limited to 'src/testbed/test_testbed_underlay.c')
-rw-r--r--src/testbed/test_testbed_underlay.c141
1 files changed, 141 insertions, 0 deletions
diff --git a/src/testbed/test_testbed_underlay.c b/src/testbed/test_testbed_underlay.c
new file mode 100644
index 000000000..6b66a5f7a
--- /dev/null
+++ b/src/testbed/test_testbed_underlay.c
@@ -0,0 +1,141 @@
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_underlay.c
23 * @brief testcase binary for testing testbed underlay restrictions
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/**
33 * Number of peers we start in this test case
34 */
35#define NUM_PEERS 3
36
37/**
38 * Result of this test case
39 */
40static int result;
41
42static struct GNUNET_TESTBED_Operation *op;
43
44
45/**
46 * Callback to be called when an operation is completed
47 *
48 * @param cls the callback closure from functions generating an operation
49 * @param op the operation that has been finished
50 * @param emsg error message in case the operation has failed; will be NULL if
51 * operation has executed successfully.
52 */
53static void
54overlay_connect_status (void *cls,
55 struct GNUNET_TESTBED_Operation *op,
56 const char *emsg)
57{
58 GNUNET_TESTBED_operation_done (op);
59 op = NULL;
60 if (NULL == emsg)
61 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peers 0 and 2 should not get connected\n");
62 else
63 result = GNUNET_OK;
64 GNUNET_SCHEDULER_shutdown ();
65}
66
67
68
69/**
70 * Signature of a main function for a testcase.
71 *
72 * @param cls closure
73 * @param h the run handle
74 * @param num_peers number of peers in 'peers'
75 * @param peers_ handle to peers run in the testbed
76 * @param links_succeeded the number of overlay link connection attempts that
77 * succeeded
78 * @param links_failed the number of overlay link connection attempts that
79 * failed
80 */
81static void
82test_master (void *cls,
83 struct GNUNET_TESTBED_RunHandle *h,
84 unsigned int num_peers,
85 struct GNUNET_TESTBED_Peer **peers_,
86 unsigned int links_succeeded,
87 unsigned int links_failed)
88{
89 GNUNET_assert (NULL == cls);
90 if (NULL == peers_)
91 {
92 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n");
93 return;
94 }
95 GNUNET_assert (NUM_PEERS == num_peers);
96 getchar();
97 op = GNUNET_TESTBED_overlay_connect (NULL,
98 &overlay_connect_status,
99 NULL,
100 peers_[0],
101 peers_[2]);
102}
103
104
105/**
106 * Main function
107 */
108int
109main (int argc, char **argv)
110{
111 struct GNUNET_CONFIGURATION_Handle *cfg;
112 char pwd[PATH_MAX];
113 char *dbfile;
114 uint64_t event_mask;
115
116 result = GNUNET_SYSERR;
117 event_mask = 0;
118 cfg = GNUNET_CONFIGURATION_create ();
119 GNUNET_assert (GNUNET_YES ==
120 GNUNET_CONFIGURATION_parse (cfg,
121 "test_testbed_underlay.conf.in"));
122 if (NULL == getcwd (pwd, PATH_MAX))
123 return 1;
124 GNUNET_assert (0 < GNUNET_asprintf (&dbfile, "%s/%s", pwd,
125 "test-underlay.sqlite"));
126 GNUNET_CONFIGURATION_set_value_string (cfg, "TESTBED-UNDERLAY","DBFILE", dbfile);
127 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write
128 (cfg, "test_testbed_underlay.conf"));
129 GNUNET_CONFIGURATION_destroy (cfg);
130 cfg = NULL;
131 GNUNET_free (dbfile);
132 dbfile = NULL;
133 (void) GNUNET_TESTBED_test_run ("test_testbed_underlay",
134 "test_testbed_underlay.conf", NUM_PEERS,
135 event_mask, NULL, NULL,
136 &test_master, NULL);
137 (void) unlink ("test_testbed_underlay.conf");
138 if (GNUNET_OK != result)
139 return 1;
140 return 0;
141}