diff options
Diffstat (limited to 'src/transport/test_transport_testing_startstop.c')
-rw-r--r-- | src/transport/test_transport_testing_startstop.c | 138 |
1 files changed, 0 insertions, 138 deletions
diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c deleted file mode 100644 index 4783c1813..000000000 --- a/src/transport/test_transport_testing_startstop.c +++ /dev/null | |||
@@ -1,138 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009, 2010, 2016 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your 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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
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 | #include "platform.h" | ||
26 | #include "gnunet_transport_service.h" | ||
27 | #include "transport-testing.h" | ||
28 | |||
29 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
30 | |||
31 | |||
32 | static struct GNUNET_SCHEDULER_Task *timeout_task; | ||
33 | |||
34 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p; | ||
35 | |||
36 | static struct GNUNET_TRANSPORT_TESTING_Handle *tth; | ||
37 | |||
38 | static int ret; | ||
39 | |||
40 | |||
41 | static void | ||
42 | end () | ||
43 | { | ||
44 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
45 | "Stopping peers\n"); | ||
46 | if (NULL != timeout_task) | ||
47 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
48 | if (NULL != p) | ||
49 | GNUNET_TRANSPORT_TESTING_stop_peer (p); | ||
50 | if (NULL != tth) | ||
51 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
52 | } | ||
53 | |||
54 | |||
55 | static void | ||
56 | end_badly () | ||
57 | { | ||
58 | timeout_task = NULL; | ||
59 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
60 | "Timeout!\n"); | ||
61 | end (); | ||
62 | ret = GNUNET_SYSERR; | ||
63 | } | ||
64 | |||
65 | |||
66 | static void | ||
67 | start_cb (void *cls) | ||
68 | { | ||
69 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
70 | "Peer %u (`%s') successfully started\n", | ||
71 | p->no, | ||
72 | GNUNET_i2s (&p->id)); | ||
73 | ret = 0; | ||
74 | GNUNET_SCHEDULER_add_now (&end, | ||
75 | NULL); | ||
76 | } | ||
77 | |||
78 | |||
79 | static void | ||
80 | run (void *cls, | ||
81 | char *const *args, | ||
82 | const char *cfgfile, | ||
83 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
84 | { | ||
85 | ret = 1; | ||
86 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
87 | GNUNET_assert (NULL != tth); | ||
88 | |||
89 | timeout_task = | ||
90 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | ||
91 | &end_badly, | ||
92 | NULL); | ||
93 | |||
94 | p = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
95 | cfgfile, | ||
96 | 1, | ||
97 | NULL, /* receive cb */ | ||
98 | NULL, /* connect cb */ | ||
99 | NULL, /* disconnect cb */ | ||
100 | NULL, /* nc/nd closure */ | ||
101 | &start_cb, /* startup cb */ | ||
102 | NULL); /* closure */ | ||
103 | if (NULL == p) | ||
104 | { | ||
105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n"); | ||
106 | if (timeout_task != NULL) | ||
107 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
108 | timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | |||
113 | int | ||
114 | main (int argc, char *argv[]) | ||
115 | { | ||
116 | char *const argv_1[] = { "test_transport_testing", | ||
117 | "-c", | ||
118 | "test_transport_api_data.conf", | ||
119 | NULL }; | ||
120 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
121 | GNUNET_GETOPT_OPTION_END | ||
122 | }; | ||
123 | |||
124 | GNUNET_log_setup ("test_transport_testing_startstop", | ||
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); | ||
133 | |||
134 | return ret; | ||
135 | } | ||
136 | |||
137 | |||
138 | /* end of test_transport_testing_startstop.c */ | ||