aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_testing_startstop.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_transport_testing_startstop.c')
-rw-r--r--src/transport/test_transport_testing_startstop.c69
1 files changed, 35 insertions, 34 deletions
diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c
index 6263f4d18..c516d4277 100644
--- a/src/transport/test_transport_testing_startstop.c
+++ b/src/transport/test_transport_testing_startstop.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010 GNUnet e.V. 3 Copyright (C) 2009, 2010, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -21,67 +21,65 @@
21 * @file transport/test_transport_testing_startstop.c 21 * @file transport/test_transport_testing_startstop.c
22 * @brief test case for transport testing library: 22 * @brief test case for transport testing library:
23 * start the peer, get the HELLO message and stop the peer 23 * start the peer, get the HELLO message and stop the peer
24 *
25 */ 24 */
26#include "platform.h" 25#include "platform.h"
27#include "gnunet_transport_service.h" 26#include "gnunet_transport_service.h"
28#include "transport-testing.h" 27#include "transport-testing.h"
29 28
30/**
31 * How long until we give up on transmitting the message?
32 */
33#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 29#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
34 30
35struct GNUNET_SCHEDULER_Task * timeout_task; 31
32static struct GNUNET_SCHEDULER_Task *timeout_task;
36 33
37static struct GNUNET_TRANSPORT_TESTING_PeerContext *p; 34static struct GNUNET_TRANSPORT_TESTING_PeerContext *p;
38 35
39struct GNUNET_TRANSPORT_TESTING_Handle *tth; 36static struct GNUNET_TRANSPORT_TESTING_Handle *tth;
37
38static int ret;
40 39
41static int ret = 0;
42 40
43static void 41static void
44end () 42end ()
45{ 43{
46 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); 44 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
47 45 "Stopping peers\n");
48 if (timeout_task != NULL) 46 if (NULL != timeout_task)
49 GNUNET_SCHEDULER_cancel (timeout_task); 47 GNUNET_SCHEDULER_cancel (timeout_task);
50 48 if (NULL != p)
51 GNUNET_TRANSPORT_TESTING_stop_peer (p); 49 GNUNET_TRANSPORT_TESTING_stop_peer (p);
52 GNUNET_TRANSPORT_TESTING_done (tth); 50 if (NULL != tth)
51 GNUNET_TRANSPORT_TESTING_done (tth);
53} 52}
54 53
54
55static void 55static void
56end_badly () 56end_badly ()
57{ 57{
58 timeout_task = NULL; 58 timeout_task = NULL;
59 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); 59 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
60 60 "Timeout!\n");
61 if (NULL != p) 61 end ();
62 GNUNET_TRANSPORT_TESTING_stop_peer (p);
63
64 if (NULL != tth)
65 GNUNET_TRANSPORT_TESTING_done (tth);
66
67 ret = GNUNET_SYSERR; 62 ret = GNUNET_SYSERR;
68} 63}
69 64
70 65
71static void 66static void
72start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) 67start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
68 void *cls)
73{ 69{
74 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') successfully started\n", 70 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
71 "Peer %u (`%s') successfully started\n",
75 p->no, 72 p->no,
76 GNUNET_i2s (&p->id)); 73 GNUNET_i2s (&p->id));
77
78 ret = 0; 74 ret = 0;
79 GNUNET_SCHEDULER_add_now (&end, NULL); 75 end ();
80} 76}
81 77
82 78
83static void 79static void
84run (void *cls, char *const *args, const char *cfgfile, 80run (void *cls,
81 char *const *args,
82 const char *cfgfile,
85 const struct GNUNET_CONFIGURATION_Handle *cfg) 83 const struct GNUNET_CONFIGURATION_Handle *cfg)
86{ 84{
87 ret = 1; 85 ret = 1;
@@ -110,25 +108,28 @@ run (void *cls, char *const *args, const char *cfgfile,
110 } 108 }
111} 109}
112 110
111
113int 112int
114main (int argc, char *argv[]) 113main (int argc, char *argv[])
115{ 114{
116 GNUNET_log_setup ("test_transport_testing_startstop",
117 "WARNING",
118 NULL);
119
120 char *const argv_1[] = { "test_transport_testing", 115 char *const argv_1[] = { "test_transport_testing",
121 "-c", 116 "-c",
122 "test_transport_api_data.conf", 117 "test_transport_api_data.conf",
123 NULL 118 NULL
124 }; 119 };
125
126 struct GNUNET_GETOPT_CommandLineOption options[] = { 120 struct GNUNET_GETOPT_CommandLineOption options[] = {
127 GNUNET_GETOPT_OPTION_END 121 GNUNET_GETOPT_OPTION_END
128 }; 122 };
129 123
130 GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1, 124 GNUNET_log_setup ("test_transport_testing_startstop",
131 "test_transport_testing_startstop", "nohelp", options, &run, &ret); 125 "WARNING",
126 NULL);
127 GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1,
128 argv_1,
129 "test_transport_testing_startstop", "nohelp",
130 options,
131 &run,
132 &ret);
132 133
133 return ret; 134 return ret;
134} 135}