aboutsummaryrefslogtreecommitdiff
path: root/src/core
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
parentda5597cf69b9bb505c0171490a6fefe358583f63 (diff)
downloadgnunet-9f77bf9ff14edd69e58ff17e16f51663ae945c46.tar.gz
gnunet-9f77bf9ff14edd69e58ff17e16f51663ae945c46.zip
-use testing lib
Diffstat (limited to 'src/core')
-rw-r--r--src/core/Makefile.am2
-rw-r--r--src/core/test_core_api_send_to_self.c108
-rw-r--r--src/core/test_core_api_start_only.c24
3 files changed, 26 insertions, 108 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index e95cbcffd..4aa7a7c73 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -89,12 +89,14 @@ test_core_api_send_to_self_SOURCES = \
89 test_core_api_send_to_self.c 89 test_core_api_send_to_self.c
90test_core_api_send_to_self_LDADD = \ 90test_core_api_send_to_self_LDADD = \
91 $(top_builddir)/src/core/libgnunetcore.la \ 91 $(top_builddir)/src/core/libgnunetcore.la \
92 $(top_builddir)/src/testing/libgnunettesting.la \
92 $(top_builddir)/src/transport/libgnunettransport.la \ 93 $(top_builddir)/src/transport/libgnunettransport.la \
93 $(top_builddir)/src/util/libgnunetutil.la 94 $(top_builddir)/src/util/libgnunetutil.la
94 95
95test_core_api_start_only_SOURCES = \ 96test_core_api_start_only_SOURCES = \
96 test_core_api_start_only.c 97 test_core_api_start_only.c
97test_core_api_start_only_LDADD = \ 98test_core_api_start_only_LDADD = \
99 $(top_builddir)/src/testing/libgnunettesting.la \
98 $(top_builddir)/src/core/libgnunetcore.la \ 100 $(top_builddir)/src/core/libgnunetcore.la \
99 $(top_builddir)/src/util/libgnunetutil.la 101 $(top_builddir)/src/util/libgnunetutil.la
100 102
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
diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c
index 308814b21..7704b4387 100644
--- a/src/core/test_core_api_start_only.c
+++ b/src/core/test_core_api_start_only.c
@@ -31,12 +31,8 @@
31#include "gnunet_program_lib.h" 31#include "gnunet_program_lib.h"
32#include "gnunet_scheduler_lib.h" 32#include "gnunet_scheduler_lib.h"
33 33
34#define VERBOSE GNUNET_NO
35
36#define TIMEOUT 5 34#define TIMEOUT 5
37 35
38#define START_ARM GNUNET_YES
39
40#define MTYPE 12345 36#define MTYPE 12345
41 37
42struct PeerContext 38struct PeerContext
@@ -44,9 +40,7 @@ struct PeerContext
44 struct GNUNET_CONFIGURATION_Handle *cfg; 40 struct GNUNET_CONFIGURATION_Handle *cfg;
45 struct GNUNET_CORE_Handle *ch; 41 struct GNUNET_CORE_Handle *ch;
46 struct GNUNET_PeerIdentity id; 42 struct GNUNET_PeerIdentity id;
47#if START_ARM
48 struct GNUNET_OS_Process *arm_proc; 43 struct GNUNET_OS_Process *arm_proc;
49#endif
50}; 44};
51 45
52static struct PeerContext p1; 46static struct PeerContext p1;
@@ -115,8 +109,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
115} 109}
116 110
117 111
118
119
120static void 112static void
121init_notify (void *cls, struct GNUNET_CORE_Handle *server, 113init_notify (void *cls, struct GNUNET_CORE_Handle *server,
122 const struct GNUNET_PeerIdentity *my_identity) 114 const struct GNUNET_PeerIdentity *my_identity)
@@ -146,15 +138,10 @@ static void
146setup_peer (struct PeerContext *p, const char *cfgname) 138setup_peer (struct PeerContext *p, const char *cfgname)
147{ 139{
148 p->cfg = GNUNET_CONFIGURATION_create (); 140 p->cfg = GNUNET_CONFIGURATION_create ();
149#if START_ARM
150 p->arm_proc = 141 p->arm_proc =
151 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", 142 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
152 "gnunet-service-arm", 143 "gnunet-service-arm",
153#if VERBOSE
154 "-L", "DEBUG",
155#endif
156 "-c", cfgname, NULL); 144 "-c", cfgname, NULL);
157#endif
158 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 145 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
159} 146}
160 147
@@ -177,7 +164,6 @@ timeout_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
177} 164}
178 165
179 166
180
181static void 167static void
182run (void *cls, char *const *args, const char *cfgfile, 168run (void *cls, char *const *args, const char *cfgfile,
183 const struct GNUNET_CONFIGURATION_Handle *cfg) 169 const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -201,7 +187,6 @@ static void
201stop_arm (struct PeerContext *p) 187stop_arm (struct PeerContext *p)
202{ 188{
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peer\n"); 189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peer\n");
204#if START_ARM
205 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 190 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
206 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 191 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
207 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 192 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
@@ -210,7 +195,6 @@ stop_arm (struct PeerContext *p)
210 GNUNET_OS_process_get_pid (p->arm_proc)); 195 GNUNET_OS_process_get_pid (p->arm_proc));
211 GNUNET_OS_process_destroy (p->arm_proc); 196 GNUNET_OS_process_destroy (p->arm_proc);
212 p->arm_proc = NULL; 197 p->arm_proc = NULL;
213#endif
214 GNUNET_CONFIGURATION_destroy (p->cfg); 198 GNUNET_CONFIGURATION_destroy (p->cfg);
215} 199}
216 200
@@ -221,9 +205,6 @@ check ()
221 char *const argv[] = { "test-core-api-start-only", 205 char *const argv[] = { "test-core-api-start-only",
222 "-c", 206 "-c",
223 "test_core_api_data.conf", 207 "test_core_api_data.conf",
224#if VERBOSE
225 "-L", "DEBUG",
226#endif
227 NULL 208 NULL
228 }; 209 };
229 struct GNUNET_GETOPT_CommandLineOption options[] = { 210 struct GNUNET_GETOPT_CommandLineOption options[] = {
@@ -241,17 +222,14 @@ check ()
241 return ok; 222 return ok;
242} 223}
243 224
225
244int 226int
245main (int argc, char *argv[]) 227main (int argc, char *argv[])
246{ 228{
247 int ret; 229 int ret;
248 230
249 GNUNET_log_setup ("test-core-api-start-only", 231 GNUNET_log_setup ("test-core-api-start-only",
250#if VERBOSE
251 "DEBUG",
252#else
253 "WARNING", 232 "WARNING",
254#endif
255 NULL); 233 NULL);
256 ret = check (); 234 ret = check ();
257 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); 235 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");