2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010 GNUnet e.V.
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.
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.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file transport/test_transport_api.c
22 * @brief base test case for transport implementations
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
30 #include "gnunet_transport_service.h"
31 #include "transport-testing.h"
34 * How long until we give up on transmitting the message?
36 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90)
40 struct GNUNET_SCHEDULER_Task * timeout_task;
42 static struct PeerContext *p1;
44 struct GNUNET_TRANSPORT_TESTING_handle *tth;
46 static int connected = GNUNET_NO;
55 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
57 if (timeout_task != NULL)
59 GNUNET_SCHEDULER_cancel (timeout_task);
62 GNUNET_TRANSPORT_TESTING_done (tth);
63 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting\n");
70 const struct GNUNET_SCHEDULER_TaskContext *tc;
72 tc = GNUNET_SCHEDULER_get_task_context ();
73 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
76 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
80 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
82 GNUNET_TRANSPORT_TESTING_done (tth);
87 notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
89 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n",
95 notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected \n",
102 notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
103 const struct GNUNET_MessageHeader *message)
105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n");
110 run (void *cls, char *const *args, const char *cfgfile,
111 const struct GNUNET_CONFIGURATION_Handle *cfg)
113 tth = GNUNET_TRANSPORT_TESTING_init ();
115 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
118 FPRINTF (stderr, "%i", i);
119 while (i <= ITERATIONS)
121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n");
122 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
123 "test_transport_startonly.conf",
126 ¬ify_disconnect, NULL, p1);
130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer was successfully started\n");
132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
133 "Peer1 was not started successfully\n");
134 GNUNET_assert (p1 != NULL);
135 GNUNET_assert (p1->th != NULL);
137 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
141 FPRINTF (stderr, "..%i", i);
144 FPRINTF (stderr, "%s", "\n");
149 main (int argc, char *argv[])
151 GNUNET_log_setup ("test_transport_testing",
156 char *const argv_1[] = { "test_transport_testing",
158 "test_transport_api_data.conf",
162 struct GNUNET_GETOPT_CommandLineOption options[] = {
163 GNUNET_GETOPT_OPTION_END
166 GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1,
167 "test_transport_testing", "nohelp", options, &run, &ret);
172 /* end of test_transport_api.c */