diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-07-02 11:02:31 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-07-02 11:02:31 +0000 |
commit | ebfd3a019674280bb14fb3ac52f1f8ebd057ea35 (patch) | |
tree | e4e71af1face88d7ebbdcd2f7fa098b9f646bd02 /src/transport/test_transport_testing_startstop.c | |
parent | 8e4a7c4f930757ce1bcab560c853caa7608fd930 (diff) | |
download | gnunet-ebfd3a019674280bb14fb3ac52f1f8ebd057ea35.tar.gz gnunet-ebfd3a019674280bb14fb3ac52f1f8ebd057ea35.zip |
- new test
Diffstat (limited to 'src/transport/test_transport_testing_startstop.c')
-rw-r--r-- | src/transport/test_transport_testing_startstop.c | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c new file mode 100644 index 000000000..2d035ca70 --- /dev/null +++ b/src/transport/test_transport_testing_startstop.c | |||
@@ -0,0 +1,193 @@ | |||
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_testing_startstop.c | ||
22 | * @brief test case for transport testing library: | ||
23 | * start the peer, get the HELLO message and stop the peer | ||
24 | * | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_common.h" | ||
28 | #include "gnunet_hello_lib.h" | ||
29 | #include "gnunet_getopt_lib.h" | ||
30 | #include "gnunet_os_lib.h" | ||
31 | #include "gnunet_program_lib.h" | ||
32 | #include "gnunet_scheduler_lib.h" | ||
33 | #include "gnunet_transport_service.h" | ||
34 | #include "transport.h" | ||
35 | #include "transport-testing.h" | ||
36 | |||
37 | #define VERBOSE GNUNET_NO | ||
38 | |||
39 | #define VERBOSE_ARM GNUNET_NO | ||
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, 30) | ||
47 | |||
48 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; | ||
49 | |||
50 | static struct PeerContext *p; | ||
51 | |||
52 | //static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; | ||
53 | |||
54 | struct GNUNET_TRANSPORT_TESTING_handle *tth; | ||
55 | |||
56 | static int ret = 0; | ||
57 | |||
58 | static void | ||
59 | end () | ||
60 | { | ||
61 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | ||
62 | |||
63 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
64 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
65 | |||
66 | if (NULL != p) | ||
67 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); | ||
68 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
69 | } | ||
70 | |||
71 | static void | ||
72 | end_badly () | ||
73 | { | ||
74 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | ||
76 | |||
77 | if (p != NULL) | ||
78 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); | ||
79 | |||
80 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
81 | |||
82 | ret = GNUNET_SYSERR; | ||
83 | } | ||
84 | |||
85 | #if 0 | ||
86 | static void | ||
87 | testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | ||
88 | { | ||
89 | char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
90 | |||
91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
92 | "Peer %u (`%4s') connected to peer %u (`%s')!\n", p1->no, ps, | ||
93 | p2->no, GNUNET_i2s (&p2->id)); | ||
94 | GNUNET_free (ps); | ||
95 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
96 | } | ||
97 | |||
98 | |||
99 | static void | ||
100 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
101 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | ||
102 | { | ||
103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n", | ||
104 | GNUNET_i2s (peer)); | ||
105 | connected++; | ||
106 | } | ||
107 | |||
108 | static void | ||
109 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
110 | { | ||
111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected \n", | ||
112 | GNUNET_i2s (peer)); | ||
113 | } | ||
114 | |||
115 | static void | ||
116 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
117 | const struct GNUNET_MessageHeader *message, | ||
118 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | ||
119 | { | ||
120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n"); | ||
121 | } | ||
122 | |||
123 | |||
124 | |||
125 | void | ||
126 | start_cb (struct PeerContext *p, void *cls) | ||
127 | { | ||
128 | static int started; | ||
129 | |||
130 | started++; | ||
131 | |||
132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, | ||
133 | GNUNET_i2s (&p->id)); | ||
134 | |||
135 | if (started != 2) | ||
136 | return; | ||
137 | |||
138 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
139 | |||
140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
141 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | ||
142 | p->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); | ||
143 | GNUNET_free (sender_c); | ||
144 | |||
145 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p, p2, &testing_connect_cb, | ||
146 | NULL); | ||
147 | } | ||
148 | #endif | ||
149 | |||
150 | static void | ||
151 | run (void *cls, char *const *args, const char *cfgfile, | ||
152 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
153 | { | ||
154 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
155 | GNUNET_assert (NULL != tth); | ||
156 | |||
157 | timeout_task = | ||
158 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL); | ||
159 | |||
160 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
161 | } | ||
162 | |||
163 | int | ||
164 | main (int argc, char *argv[]) | ||
165 | { | ||
166 | GNUNET_log_setup ("test_transport_testing_startstop", | ||
167 | #if VERBOSE | ||
168 | "DEBUG", | ||
169 | #else | ||
170 | "WARNING", | ||
171 | #endif | ||
172 | NULL); | ||
173 | |||
174 | char *const argv_1[] = { "test_transport_testing", | ||
175 | "-c", | ||
176 | "test_transport_api_data.conf", | ||
177 | #if VERBOSE | ||
178 | "-L", "DEBUG", | ||
179 | #endif | ||
180 | NULL | ||
181 | }; | ||
182 | |||
183 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
184 | GNUNET_GETOPT_OPTION_END | ||
185 | }; | ||
186 | |||
187 | GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1, | ||
188 | "test_transport_testing_startstop", "nohelp", options, &run, &ret); | ||
189 | |||
190 | return ret; | ||
191 | } | ||
192 | |||
193 | /* end of test_transport_testing_startstop.c */ | ||