2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
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
27 #include "gnunet_transport_service.h"
28 #include "transport-testing.h"
31 * How long until we give up on transmitting the message?
33 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
35 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
37 static struct PeerContext *p;
39 struct GNUNET_TRANSPORT_TESTING_handle *tth;
46 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
48 if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
49 GNUNET_SCHEDULER_cancel (timeout_task);
51 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p);
52 GNUNET_TRANSPORT_TESTING_done (tth);
58 timeout_task = GNUNET_SCHEDULER_NO_TASK;
59 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
62 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p);
65 GNUNET_TRANSPORT_TESTING_done (tth);
72 start_cb (struct PeerContext *p, void *cls)
74 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') successfully started\n",
79 GNUNET_SCHEDULER_add_now (&end, NULL);
84 run (void *cls, char *const *args, const char *cfgfile,
85 const struct GNUNET_CONFIGURATION_Handle *cfg)
88 tth = GNUNET_TRANSPORT_TESTING_init ();
89 GNUNET_assert (NULL != tth);
92 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL);
94 p = GNUNET_TRANSPORT_TESTING_start_peer(tth, cfgfile, 1,
95 NULL, /* receive cb */
96 NULL, /* connect cb */
97 NULL, /* disconnect cb */
98 start_cb, /* startup cb */
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n");
103 if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
104 GNUNET_SCHEDULER_cancel (timeout_task);
105 timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
110 main (int argc, char *argv[])
112 GNUNET_log_setup ("test_transport_testing_startstop",
116 char *const argv_1[] = { "test_transport_testing",
118 "test_transport_api_data.conf",
122 struct GNUNET_GETOPT_CommandLineOption options[] = {
123 GNUNET_GETOPT_OPTION_END
126 GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1,
127 "test_transport_testing_startstop", "nohelp", options, &run, &ret);
132 /* end of test_transport_testing_startstop.c */