aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-05-26 14:04:59 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-05-26 14:04:59 +0000
commit3dfcafa46627f230f83bb323cac321346a0f75eb (patch)
treee3abfc666a453cfed82dfb5d24fbe8965c3bc6e0 /src/testing
parentcf99c0faa8634abfdcb54a7c7e8d2e5e72210e36 (diff)
downloadgnunet-3dfcafa46627f230f83bb323cac321346a0f75eb.tar.gz
gnunet-3dfcafa46627f230f83bb323cac321346a0f75eb.zip
port reservation and test cases
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/Makefile.am12
-rw-r--r--src/testing/test_testing_new_portreservation.c78
-rw-r--r--src/testing/testing_new.c4
3 files changed, 90 insertions, 4 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 25cf2cbe2..dc357fbf7 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -89,7 +89,8 @@ check_PROGRAMS = \
89 test_testing_topology_erdos_renyi \ 89 test_testing_topology_erdos_renyi \
90 test_testing_topology_internat \ 90 test_testing_topology_internat \
91 test_testing_topology_none \ 91 test_testing_topology_none \
92 test_testing_topology_scale_free 92 test_testing_topology_scale_free \
93 test_testing_new_portreservation
93 94
94if ENABLE_TEST_RUN 95if ENABLE_TEST_RUN
95TESTS = \ 96TESTS = \
@@ -97,7 +98,8 @@ TESTS = \
97 test_testing_connect \ 98 test_testing_connect \
98 test_testing_reconnect \ 99 test_testing_reconnect \
99 test_testing_group \ 100 test_testing_group \
100 test_testing_peergroup 101 test_testing_peergroup \
102 test_testing_new_portreservation
101endif 103endif
102 104
103gnunet_testing_SOURCES = \ 105gnunet_testing_SOURCES = \
@@ -263,6 +265,12 @@ test_testing_topology_none_LDADD = \
263 $(top_builddir)/src/core/libgnunetcore.la \ 265 $(top_builddir)/src/core/libgnunetcore.la \
264 $(top_builddir)/src/util/libgnunetutil.la 266 $(top_builddir)/src/util/libgnunetutil.la
265 267
268test_testing_new_portreservation_SOURCES = \
269 test_testing_new_portreservation.c
270test_testing_new_portreservation_LDADD = \
271 $(top_builddir)/src/testing/libgnunettesting_new.la \
272 $(top_builddir)/src/util/libgnunetutil.la
273
266 274
267EXTRA_DIST = \ 275EXTRA_DIST = \
268 test_testing_defaults.conf \ 276 test_testing_defaults.conf \
diff --git a/src/testing/test_testing_new_portreservation.c b/src/testing/test_testing_new_portreservation.c
new file mode 100644
index 000000000..a5821edb0
--- /dev/null
+++ b/src/testing/test_testing_new_portreservation.c
@@ -0,0 +1,78 @@
1/*
2 This file is part of GNUnet
3 (C) 2008, 2009, 2012 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 testing/test_testing_new_portreservation.c
23 * @brief test case for testing port reservation routines from the new testing
24 * library API
25 * @author Sree Harsha Totakura
26 */
27
28#include "platform.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_testing_lib-new.h"
31
32#define LOG(kind,...) \
33 GNUNET_log (kind, __VA_ARGS__)
34
35/**
36 * Main point of test execution
37 */
38static void
39run (void *cls, char *const *args, const char *cfgfile,
40 const struct GNUNET_CONFIGURATION_Handle *cfg)
41{
42 uint16_t new_port1, new_port2;
43 struct GNUNET_TESTING_System *system;
44
45 system = GNUNET_TESTING_system_create ("/tmp/gnunet-testing-new",
46 "localhost");
47 GNUNET_assert (NULL != system);
48 new_port1 = reserve_port (system, GNUNET_YES);
49 LOG (GNUNET_ERROR_TYPE_DEBUG,
50 "Reserved TCP port %u\n", new_port1);
51 GNUNET_assert (0 != new_port1);
52 new_port2 = reserve_port (system, GNUNET_YES);
53 LOG (GNUNET_ERROR_TYPE_DEBUG,
54 "Reserved TCP port %u\n", new_port2);
55 GNUNET_assert (0 != new_port2);
56 GNUNET_assert (new_port1 != new_port2);
57 GNUNET_TESTING_system_destroy (system, GNUNET_NO);
58}
59
60int main (int argc, char *argv[])
61{
62 struct GNUNET_GETOPT_CommandLineOption options[] = {
63 GNUNET_GETOPT_OPTION_END
64 };
65 if (GNUNET_OK !=
66 GNUNET_PROGRAM_run (argc,
67 argv,
68 "test_testing_new_portreservation",
69 "test case for testing port reservation routines"
70 " from the new testing library API",
71 options,
72 &run,
73 NULL))
74 {
75 return 1;
76 }
77 return 0;
78}
diff --git a/src/testing/testing_new.c b/src/testing/testing_new.c
index 4622ae874..7a97b3b9c 100644
--- a/src/testing/testing_new.c
+++ b/src/testing/testing_new.c
@@ -210,11 +210,11 @@ reserve_port (struct GNUNET_TESTING_System *system,
210 struct addrinfo *ret; 210 struct addrinfo *ret;
211 uint32_t *port_buckets; 211 uint32_t *port_buckets;
212 char *open_port_str; 212 char *open_port_str;
213 int pos;
214 int bind_status; 213 int bind_status;
215 uint32_t xor_image; 214 uint32_t xor_image;
216 uint16_t index; 215 uint16_t index;
217 uint16_t open_port; 216 uint16_t open_port;
217 uint16_t pos;
218 218
219 hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */ 219 hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
220 hint.ai_socktype = (GNUNET_YES == is_tcp)? SOCK_STREAM : SOCK_DGRAM; 220 hint.ai_socktype = (GNUNET_YES == is_tcp)? SOCK_STREAM : SOCK_DGRAM;
@@ -244,7 +244,7 @@ reserve_port (struct GNUNET_TESTING_System *system,
244 ret = NULL; 244 ret = NULL;
245 GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret)); 245 GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret));
246 GNUNET_free (open_port_str); 246 GNUNET_free (open_port_str);
247 socket = GNUNET_NETWORK_socket_create (AF_UNSPEC, 247 socket = GNUNET_NETWORK_socket_create (ret->ai_family,
248 (GNUNET_YES == is_tcp) ? 248 (GNUNET_YES == is_tcp) ?
249 SOCK_STREAM : SOCK_DGRAM, 249 SOCK_STREAM : SOCK_DGRAM,
250 0); 250 0);