diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-08-24 13:43:34 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-08-24 13:43:34 +0000 |
commit | 6a752e4fcce7616810f6cf47235e72198ebdadeb (patch) | |
tree | db97333e941038224659783f7a9fa42b38867ba2 /src/transport/test_transport_startonly.c | |
parent | df0c0a796560d71065988a961f0046f8a0377456 (diff) | |
download | gnunet-6a752e4fcce7616810f6cf47235e72198ebdadeb.tar.gz gnunet-6a752e4fcce7616810f6cf47235e72198ebdadeb.zip |
the test
Diffstat (limited to 'src/transport/test_transport_startonly.c')
-rw-r--r-- | src/transport/test_transport_startonly.c | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/src/transport/test_transport_startonly.c b/src/transport/test_transport_startonly.c new file mode 100644 index 000000000..029227fa0 --- /dev/null +++ b/src/transport/test_transport_startonly.c | |||
@@ -0,0 +1,182 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009, 2010 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 | * @file transport/test_transport_api.c | ||
22 | * @brief base test case for transport implementations | ||
23 | * | ||
24 | * This test case serves as a base for tcp, udp, and udp-nat | ||
25 | * transport test cases. Based on the executable being run | ||
26 | * the correct test case will be performed. Conservation of | ||
27 | * C code apparently. | ||
28 | */ | ||
29 | #include "platform.h" | ||
30 | #include "gnunet_common.h" | ||
31 | #include "gnunet_hello_lib.h" | ||
32 | #include "gnunet_getopt_lib.h" | ||
33 | #include "gnunet_os_lib.h" | ||
34 | #include "gnunet_program_lib.h" | ||
35 | #include "gnunet_scheduler_lib.h" | ||
36 | #include "gnunet_transport_service.h" | ||
37 | #include "transport.h" | ||
38 | #include "transport-testing.h" | ||
39 | |||
40 | #define VERBOSE GNUNET_NO | ||
41 | |||
42 | #define VERBOSE_ARM GNUNET_NO | ||
43 | |||
44 | #define START_ARM GNUNET_YES | ||
45 | |||
46 | /** | ||
47 | * How long until we give up on transmitting the message? | ||
48 | */ | ||
49 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90) | ||
50 | |||
51 | #define ITERATIONS 10 | ||
52 | |||
53 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; | ||
54 | |||
55 | static struct PeerContext *p1; | ||
56 | |||
57 | static int connected = GNUNET_NO; | ||
58 | |||
59 | static int ret = 0; | ||
60 | |||
61 | static int i; | ||
62 | |||
63 | static void | ||
64 | end () | ||
65 | { | ||
66 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | ||
67 | |||
68 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
69 | { | ||
70 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
71 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
72 | } | ||
73 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting\n"); | ||
74 | } | ||
75 | |||
76 | static void | ||
77 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
78 | { | ||
79 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | ||
80 | |||
81 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
82 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
83 | return; | ||
84 | |||
85 | if (p1 != NULL) | ||
86 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
87 | |||
88 | ret = GNUNET_SYSERR; | ||
89 | } | ||
90 | |||
91 | static void | ||
92 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
93 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
94 | uint32_t ats_count) | ||
95 | { | ||
96 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n", | ||
97 | GNUNET_i2s (peer)); | ||
98 | connected++; | ||
99 | } | ||
100 | |||
101 | static void | ||
102 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
103 | { | ||
104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected \n", | ||
105 | GNUNET_i2s (peer)); | ||
106 | } | ||
107 | |||
108 | static void | ||
109 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
110 | const struct GNUNET_MessageHeader *message, | ||
111 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
112 | uint32_t ats_count) | ||
113 | { | ||
114 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n"); | ||
115 | } | ||
116 | |||
117 | |||
118 | static void | ||
119 | run (void *cls, char *const *args, const char *cfgfile, | ||
120 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
121 | { | ||
122 | timeout_task = | ||
123 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL); | ||
124 | |||
125 | i = 1; | ||
126 | fprintf(stderr,"%i",i); | ||
127 | while (i <= ITERATIONS) | ||
128 | { | ||
129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n"); | ||
130 | p1 = GNUNET_TRANSPORT_TESTING_start_peer ("test_transport_api_tcp_peer1.conf", | ||
131 | ¬ify_receive, ¬ify_connect, | ||
132 | ¬ify_disconnect, p1); | ||
133 | |||
134 | |||
135 | if (p1 != NULL) | ||
136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer was successfully started\n"); | ||
137 | else | ||
138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
139 | "Peer1 was not started successfully\n"); | ||
140 | GNUNET_assert (p1 != NULL); | ||
141 | GNUNET_assert (p1->th != NULL); | ||
142 | |||
143 | GNUNET_TRANSPORT_TESTING_stop_peer(p1); | ||
144 | |||
145 | i++; | ||
146 | fprintf(stderr,"..%i",i); | ||
147 | } | ||
148 | fprintf(stderr,"\n"); | ||
149 | end(); | ||
150 | } | ||
151 | |||
152 | int | ||
153 | main (int argc, char *argv[]) | ||
154 | { | ||
155 | GNUNET_log_setup ("test_transport_testing", | ||
156 | #if VERBOSE | ||
157 | "DEBUG", | ||
158 | #else | ||
159 | "WARNING", | ||
160 | #endif | ||
161 | NULL); | ||
162 | |||
163 | char *const argv_1[] = { "test_transport_testing", | ||
164 | "-c", | ||
165 | "test_transport_api_data.conf", | ||
166 | #if VERBOSE | ||
167 | "-L", "DEBUG", | ||
168 | #endif | ||
169 | NULL | ||
170 | }; | ||
171 | |||
172 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
173 | GNUNET_GETOPT_OPTION_END | ||
174 | }; | ||
175 | |||
176 | GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1, | ||
177 | "test_transport_testing", "nohelp", options, &run, &ret); | ||
178 | |||
179 | return ret; | ||
180 | } | ||
181 | |||
182 | /* end of test_transport_api.c */ | ||