aboutsummaryrefslogtreecommitdiff
path: root/src/core/test_core_api_send_to_self.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-23 21:24:12 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-23 21:24:12 +0000
commit9f77bf9ff14edd69e58ff17e16f51663ae945c46 (patch)
tree622dd28051c1d8d4fd50ed32bc60d066749181a7 /src/core/test_core_api_send_to_self.c
parentda5597cf69b9bb505c0171490a6fefe358583f63 (diff)
downloadgnunet-9f77bf9ff14edd69e58ff17e16f51663ae945c46.tar.gz
gnunet-9f77bf9ff14edd69e58ff17e16f51663ae945c46.zip
-use testing lib
Diffstat (limited to 'src/core/test_core_api_send_to_self.c')
-rw-r--r--src/core/test_core_api_send_to_self.c108
1 files changed, 23 insertions, 85 deletions
diff --git a/src/core/test_core_api_send_to_self.c b/src/core/test_core_api_send_to_self.c
index 3827cdb77..75a2be1c5 100644
--- a/src/core/test_core_api_send_to_self.c
+++ b/src/core/test_core_api_send_to_self.c
@@ -23,12 +23,12 @@
23 * @brief 23 * @brief
24 * @author Philipp Toelke 24 * @author Philipp Toelke
25 */ 25 */
26#include <platform.h> 26#include "platform.h"
27#include <gnunet_common.h> 27#include "gnunet_util_lib.h"
28#include <gnunet_program_lib.h> 28#include "gnunet_testing_lib-new.h"
29#include <gnunet_protocols.h> 29#include "gnunet_protocols.h"
30#include <gnunet_core_service.h> 30#include "gnunet_core_service.h"
31#include <gnunet_constants.h> 31#include "gnunet_constants.h"
32 32
33/** 33/**
34 * Final status code. 34 * Final status code.
@@ -40,22 +40,16 @@ static int ret;
40 */ 40 */
41GNUNET_SCHEDULER_TaskIdentifier die_task; 41GNUNET_SCHEDULER_TaskIdentifier die_task;
42 42
43static struct GNUNET_PeerIdentity myself;
44
45/** 43/**
46 * Configuration to load for the new peer. 44 * Identity of this peer.
47 */ 45 */
48struct GNUNET_CONFIGURATION_Handle *core_cfg; 46static struct GNUNET_PeerIdentity myself;
49 47
50/** 48/**
51 * The handle to core 49 * The handle to core
52 */ 50 */
53struct GNUNET_CORE_Handle *core; 51struct GNUNET_CORE_Handle *core;
54 52
55/**
56 * Handle to gnunet-service-arm.
57 */
58struct GNUNET_OS_Process *arm_proc;
59 53
60/** 54/**
61 * Function scheduled as very last function, cleans up after us 55 * Function scheduled as very last function, cleans up after us
@@ -71,22 +65,10 @@ cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tskctx)
71 GNUNET_CORE_disconnect (core); 65 GNUNET_CORE_disconnect (core);
72 core = NULL; 66 core = NULL;
73 } 67 }
74
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peer\n");
76 if (0 != GNUNET_OS_process_kill (arm_proc, SIGTERM))
77 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
78
79 if (GNUNET_OS_process_wait (arm_proc) != GNUNET_OK)
80 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
81
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
83 GNUNET_OS_process_get_pid (arm_proc));
84 GNUNET_OS_process_destroy (arm_proc);
85 arm_proc = NULL;
86
87 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n"); 68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
88} 69}
89 70
71
90static int 72static int
91receive (void *cls, const struct GNUNET_PeerIdentity *other, 73receive (void *cls, const struct GNUNET_PeerIdentity *other,
92 const struct GNUNET_MessageHeader *message, 74 const struct GNUNET_MessageHeader *message,
@@ -101,6 +83,7 @@ receive (void *cls, const struct GNUNET_PeerIdentity *other,
101 return GNUNET_OK; 83 return GNUNET_OK;
102} 84}
103 85
86
104static size_t 87static size_t
105send_message (void *cls, size_t size, void *buf) 88send_message (void *cls, size_t size, void *buf)
106{ 89{
@@ -117,6 +100,7 @@ send_message (void *cls, size_t size, void *buf)
117 return ntohs (hdr->size); 100 return ntohs (hdr->size);
118} 101}
119 102
103
120static void 104static void
121init (void *cls, struct GNUNET_CORE_Handle *core, 105init (void *cls, struct GNUNET_CORE_Handle *core,
122 const struct GNUNET_PeerIdentity *my_identity) 106 const struct GNUNET_PeerIdentity *my_identity)
@@ -132,6 +116,7 @@ init (void *cls, struct GNUNET_CORE_Handle *core,
132 memcpy (&myself, my_identity, sizeof (struct GNUNET_PeerIdentity)); 116 memcpy (&myself, my_identity, sizeof (struct GNUNET_PeerIdentity));
133} 117}
134 118
119
135static void 120static void
136connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer, 121connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
137 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 122 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
@@ -154,71 +139,29 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
154 * Main function that will be run by the scheduler. 139 * Main function that will be run by the scheduler.
155 * 140 *
156 * @param cls closure 141 * @param cls closure
157 * @param args remaining command-line arguments
158 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
159 * @param cfg configuration 142 * @param cfg configuration
160 */ 143 */
161static void 144static void
162run (void *cls, char *const *args, const char *cfgfile, 145run (void *cls,
163 const struct GNUNET_CONFIGURATION_Handle *cfg) 146 const struct GNUNET_CONFIGURATION_Handle *cfg,
147 struct GNUNET_TESTING_Peer *peer)
164{ 148{
165 const static struct GNUNET_CORE_MessageHandler handlers[] = { 149 const static struct GNUNET_CORE_MessageHandler handlers[] = {
166 {&receive, GNUNET_MESSAGE_TYPE_DUMMY, 0}, 150 {&receive, GNUNET_MESSAGE_TYPE_DUMMY, 0},
167 {NULL, 0, 0} 151 {NULL, 0, 0}
168 }; 152 };
169
170 core_cfg = GNUNET_CONFIGURATION_create ();
171
172 arm_proc =
173 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
174 "gnunet-service-arm",
175#if VERBOSE
176 "-L", "DEBUG",
177#endif
178 "-c", "test_core_api_peer1.conf", NULL);
179
180 GNUNET_assert (GNUNET_OK ==
181 GNUNET_CONFIGURATION_load (core_cfg,
182 "test_core_api_peer1.conf"));
183
184 core = 153 core =
185 GNUNET_CORE_connect (core_cfg, NULL, &init, &connect_cb, NULL, NULL, 154 GNUNET_CORE_connect (cfg, NULL, &init, &connect_cb, NULL, NULL,
186 0, NULL, 0, handlers); 155 0, NULL, 0, handlers);
187
188 die_task = 156 die_task =
189 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 157 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
190 (GNUNET_TIME_UNIT_SECONDS, 300), &cleanup, 158 (GNUNET_TIME_UNIT_SECONDS, 300), &cleanup,
191 cls); 159 NULL);
192} 160}
193 161
194 162
195static int
196check ()
197{
198 char *const argv[] = { "test-core-api-send-to-self",
199 "-c",
200 "test_core_api_data.conf",
201#if VERBOSE
202 "-L", "DEBUG",
203#endif
204 NULL
205 };
206
207 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
208 GNUNET_GETOPT_OPTION_END
209 };
210
211 ret = 1;
212
213 return (GNUNET_OK ==
214 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
215 "test_core_api_send_to_self",
216 gettext_noop ("help text"), options, &run,
217 NULL)) ? ret : 1;
218}
219
220/** 163/**
221 * The main function to obtain template from gnunetd. 164 * The main function to test sending a message to the local peer via core
222 * 165 *
223 * @param argc number of arguments from the command line 166 * @param argc number of arguments from the command line
224 * @param argv command line arguments 167 * @param argv command line arguments
@@ -227,15 +170,10 @@ check ()
227int 170int
228main (int argc, char *argv[]) 171main (int argc, char *argv[])
229{ 172{
230 GNUNET_log_setup ("test-core-api-send-to-self", 173 if (0 != GNUNET_TESTING_peer_run ("test-core-api-send-to-self",
231#if VERBOSE 174 "test_core_api_peer1.conf",
232 "DEBUG", 175 &run, NULL))
233#else 176 return 1;
234 "WARNING",
235#endif
236 NULL);
237 ret = check ();
238 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
239 return ret; 177 return ret;
240} 178}
241 179