diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-01 09:53:50 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-01 09:53:50 +0000 |
commit | 9a6e5853d2e563ae4baf5e90fccec267a1e1fe0b (patch) | |
tree | 16c9fa88ad8ce5a20c67d14552555e711050d510 | |
parent | 1410eed84796598e79e5868f9754a02018099885 (diff) | |
download | gnunet-9a6e5853d2e563ae4baf5e90fccec267a1e1fe0b.tar.gz gnunet-9a6e5853d2e563ae4baf5e90fccec267a1e1fe0b.zip |
- basic bl test
-rw-r--r-- | src/transport/Makefile.am | 10 | ||||
-rw-r--r-- | src/transport/test_transport_api_blacklisting.c | 159 |
2 files changed, 169 insertions, 0 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index b7d9956d3..b816209b7 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -248,6 +248,7 @@ libgnunet_plugin_transport_https_la_CPPFLAGS = \ | |||
248 | check_PROGRAMS = \ | 248 | check_PROGRAMS = \ |
249 | test_transport_testing \ | 249 | test_transport_testing \ |
250 | test_transport_startonly \ | 250 | test_transport_startonly \ |
251 | test_transport_api_blacklisting \ | ||
251 | test_transport_api_disconnect_tcp \ | 252 | test_transport_api_disconnect_tcp \ |
252 | test_transport_api_bidirectional_connect \ | 253 | test_transport_api_bidirectional_connect \ |
253 | test_transport_api_tcp \ | 254 | test_transport_api_tcp \ |
@@ -289,6 +290,7 @@ if ENABLE_TEST_RUN | |||
289 | TESTS = \ | 290 | TESTS = \ |
290 | test_transport_testing \ | 291 | test_transport_testing \ |
291 | test_transport_startonly \ | 292 | test_transport_startonly \ |
293 | test_transport_api_blacklisting \ | ||
292 | test_transport_api_disconnect_tcp \ | 294 | test_transport_api_disconnect_tcp \ |
293 | test_transport_api_bidirectional_connect \ | 295 | test_transport_api_bidirectional_connect \ |
294 | test_transport_api_tcp \ | 296 | test_transport_api_tcp \ |
@@ -343,6 +345,14 @@ test_transport_testing_LDADD = \ | |||
343 | # $(top_builddir)/src/util/libgnunetutil.la \ | 345 | # $(top_builddir)/src/util/libgnunetutil.la \ |
344 | # $(top_builddir)/src/transport/libgnunettransporttesting.la | 346 | # $(top_builddir)/src/transport/libgnunettransporttesting.la |
345 | 347 | ||
348 | test_transport_api_blacklisting_SOURCES = \ | ||
349 | test_transport_api_blacklisting.c | ||
350 | test_transport_api_blacklisting_LDADD = \ | ||
351 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
352 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
353 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
354 | $(top_builddir)/src/util/libgnunetutil.la | ||
355 | |||
346 | test_transport_api_disconnect_tcp_SOURCES = \ | 356 | test_transport_api_disconnect_tcp_SOURCES = \ |
347 | test_transport_api_disconnect.c | 357 | test_transport_api_disconnect.c |
348 | test_transport_api_disconnect_tcp_LDADD = \ | 358 | test_transport_api_disconnect_tcp_LDADD = \ |
diff --git a/src/transport/test_transport_api_blacklisting.c b/src/transport/test_transport_api_blacklisting.c new file mode 100644 index 000000000..8e5e14725 --- /dev/null +++ b/src/transport/test_transport_api_blacklisting.c | |||
@@ -0,0 +1,159 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009, 2010, 2011 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 transport/transport_api_blacklisting.c | ||
23 | * @brief test for the blacklisting API | ||
24 | * @author Matthias Wachs | ||
25 | * | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_common.h" | ||
29 | #include "gnunet_hello_lib.h" | ||
30 | #include "gnunet_getopt_lib.h" | ||
31 | #include "gnunet_os_lib.h" | ||
32 | #include "gnunet_program_lib.h" | ||
33 | #include "gnunet_scheduler_lib.h" | ||
34 | #include "gnunet_transport_service.h" | ||
35 | #include "transport.h" | ||
36 | #include "transport-testing.h" | ||
37 | |||
38 | #define VERBOSE GNUNET_EXTRA_LOGGING | ||
39 | #define VERBOSE_ARM GNUNET_EXTRA_LOGGING | ||
40 | |||
41 | #define START_ARM GNUNET_YES | ||
42 | |||
43 | /** | ||
44 | * How long until we give up on transmitting the message? | ||
45 | */ | ||
46 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | ||
47 | |||
48 | /** | ||
49 | * How long until we give up on transmitting the message? | ||
50 | */ | ||
51 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | ||
52 | |||
53 | #define MTYPE 12345 | ||
54 | |||
55 | static int ok; | ||
56 | |||
57 | struct GNUNET_TRANSPORT_Blacklist * blacklist; | ||
58 | |||
59 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
60 | |||
61 | #if VERBOSE | ||
62 | #define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | ||
63 | #else | ||
64 | #define OKPP do { ok++; } while (0) | ||
65 | #endif | ||
66 | |||
67 | |||
68 | static void | ||
69 | end () | ||
70 | { | ||
71 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping\n"); | ||
72 | |||
73 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
74 | GNUNET_SCHEDULER_cancel (die_task); | ||
75 | |||
76 | ok = 0; | ||
77 | } | ||
78 | |||
79 | static void | ||
80 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
81 | { | ||
82 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
83 | |||
84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail!\n"); | ||
85 | |||
86 | ok = GNUNET_SYSERR; | ||
87 | } | ||
88 | |||
89 | |||
90 | int blacklist_cb (void *cls, | ||
91 | const struct | ||
92 | GNUNET_PeerIdentity * pid) | ||
93 | { | ||
94 | return GNUNET_YES; | ||
95 | } | ||
96 | |||
97 | static void | ||
98 | run (void *cls, char *const *args, const char *cfgfile, | ||
99 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
100 | { | ||
101 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
102 | |||
103 | blacklist = GNUNET_TRANSPORT_blacklist (cfg, | ||
104 | &blacklist_cb, | ||
105 | NULL); | ||
106 | |||
107 | GNUNET_assert (blacklist != NULL); | ||
108 | |||
109 | GNUNET_TRANSPORT_blacklist_cancel (blacklist); | ||
110 | |||
111 | end (); | ||
112 | } | ||
113 | |||
114 | |||
115 | static int | ||
116 | check () | ||
117 | { | ||
118 | static char *const argv[] = { "test-transport-api-blacklisting", | ||
119 | "-c", | ||
120 | "test_transport_api_data.conf", | ||
121 | #if VERBOSE | ||
122 | "-L", "DEBUG", | ||
123 | #endif | ||
124 | NULL | ||
125 | }; | ||
126 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
127 | GNUNET_GETOPT_OPTION_END | ||
128 | }; | ||
129 | |||
130 | #if WRITECONFIG | ||
131 | setTransportOptions ("test_transport_api_data.conf"); | ||
132 | #endif | ||
133 | |||
134 | ok = 1; | ||
135 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-transport-api-blacklisting", | ||
136 | "nohelp", options, &run, &ok); | ||
137 | |||
138 | return ok; | ||
139 | } | ||
140 | |||
141 | int | ||
142 | main (int argc, char *argv[]) | ||
143 | { | ||
144 | int ret; | ||
145 | |||
146 | GNUNET_log_setup ("test-transport-api-blacklisting", | ||
147 | #if VERBOSE | ||
148 | "DEBUG", | ||
149 | #else | ||
150 | "WARNING", | ||
151 | #endif | ||
152 | NULL); | ||
153 | |||
154 | ret = check (); | ||
155 | |||
156 | return ret; | ||
157 | } | ||
158 | |||
159 | /* end of transport_api_blacklisting.c */ | ||