aboutsummaryrefslogtreecommitdiff
path: root/src/stream
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-06-20 19:56:06 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-06-20 19:56:06 +0000
commitd0ddec50cd8ebed5269ce277195cc858b8ea709c (patch)
tree0d70d778660e546a72e3831f6973ee7ebd31c92e /src/stream
parent74405f8ead047a6f3ac9b31130b4f2e4f6a1292c (diff)
downloadgnunet-d0ddec50cd8ebed5269ce277195cc858b8ea709c.tar.gz
gnunet-d0ddec50cd8ebed5269ce277195cc858b8ea709c.zip
-stream testcases with new testing library
Diffstat (limited to 'src/stream')
-rw-r--r--src/stream/Makefile.am4
-rw-r--r--src/stream/test_stream_big.c6
-rw-r--r--src/stream/test_stream_local.c153
-rw-r--r--src/stream/test_stream_sequence_wraparound.c119
4 files changed, 66 insertions, 216 deletions
diff --git a/src/stream/Makefile.am b/src/stream/Makefile.am
index 10d87f042..54f2a6fa5 100644
--- a/src/stream/Makefile.am
+++ b/src/stream/Makefile.am
@@ -55,7 +55,7 @@ test_stream_local_SOURCES = \
55test_stream_local_LDADD = \ 55test_stream_local_LDADD = \
56 $(top_builddir)/src/stream/libgnunetstream.la \ 56 $(top_builddir)/src/stream/libgnunetstream.la \
57 $(top_builddir)/src/util/libgnunetutil.la \ 57 $(top_builddir)/src/util/libgnunetutil.la \
58 $(top_builddir)/src/testing_old/libgnunettesting_old.la 58 $(top_builddir)/src/testing/libgnunettesting.la
59 59
60test_stream_big_SOURCES = \ 60test_stream_big_SOURCES = \
61 test_stream_big.c 61 test_stream_big.c
@@ -69,4 +69,4 @@ test_stream_sequence_wraparound_SOURCES = \
69test_stream_sequence_wraparound_LDADD = \ 69test_stream_sequence_wraparound_LDADD = \
70 $(top_builddir)/src/stream/libgnunetstream.la \ 70 $(top_builddir)/src/stream/libgnunetstream.la \
71 $(top_builddir)/src/util/libgnunetutil.la \ 71 $(top_builddir)/src/util/libgnunetutil.la \
72 $(top_builddir)/src/testing_old/libgnunettesting_old.la \ No newline at end of file 72 $(top_builddir)/src/testing/libgnunettesting.la
diff --git a/src/stream/test_stream_big.c b/src/stream/test_stream_big.c
index 6815ae665..dff5cc0a6 100644
--- a/src/stream/test_stream_big.c
+++ b/src/stream/test_stream_big.c
@@ -381,9 +381,11 @@ run (void *cls,
381 */ 381 */
382int main (int argc, char **argv) 382int main (int argc, char **argv)
383{ 383{
384 if (0 != GNUNET_TESTING_peer_run ("test-stream-big", 384 if (0 != GNUNET_TESTING_peer_run ("test_stream_big",
385 "test_stream_local.conf", 385 "test_stream_local.conf",
386 &run, NULL)) 386 &run, NULL))
387 return 1; 387 return 1;
388 return (GNUNET_SYSERR == result) ? 1 : 0; 388 return (GNUNET_SYSERR == result) ? 1 : 0;
389} 389}
390
391/* end of test_stream_big.c */
diff --git a/src/stream/test_stream_local.c b/src/stream/test_stream_local.c
index bf0584015..e660d77d7 100644
--- a/src/stream/test_stream_local.c
+++ b/src/stream/test_stream_local.c
@@ -30,10 +30,11 @@
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_mesh_service.h" 31#include "gnunet_mesh_service.h"
32#include "gnunet_stream_lib.h" 32#include "gnunet_stream_lib.h"
33#include "gnunet_testing_lib.h" 33#include "gnunet_testing_lib-new.h"
34
35#define VERBOSE 1
36 34
35/**
36 * Relative seconds shorthand
37 */
37#define TIME_REL_SECS(sec) \ 38#define TIME_REL_SECS(sec) \
38 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) 39 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
39 40
@@ -69,15 +70,14 @@ struct PeerData
69 unsigned int bytes_read; 70 unsigned int bytes_read;
70}; 71};
71 72
72static struct GNUNET_OS_Process *arm_pid;
73static struct PeerData peer1; 73static struct PeerData peer1;
74static struct PeerData peer2; 74static struct PeerData peer2;
75static struct GNUNET_STREAM_ListenSocket *peer2_listen_socket; 75static struct GNUNET_STREAM_ListenSocket *peer2_listen_socket;
76static struct GNUNET_CONFIGURATION_Handle *config_peer1; 76static const struct GNUNET_CONFIGURATION_Handle *config;
77static struct GNUNET_CONFIGURATION_Handle *config_peer2; 77static struct GNUNET_TESTING_Peer *self;
78static struct GNUNET_PeerIdentity self_id;
78 79
79static GNUNET_SCHEDULER_TaskIdentifier abort_task; 80static GNUNET_SCHEDULER_TaskIdentifier abort_task;
80static GNUNET_SCHEDULER_TaskIdentifier test_task;
81 81
82static char *data = "ABCD"; 82static char *data = "ABCD";
83static int result; 83static int result;
@@ -85,6 +85,7 @@ static int result;
85static int writing_success; 85static int writing_success;
86static int reading_success; 86static int reading_success;
87 87
88
88/** 89/**
89 * Input processor 90 * Input processor
90 * 91 *
@@ -121,6 +122,7 @@ stream_read_task (void *cls,
121 GNUNET_assert (NULL != peer->io_read_handle); 122 GNUNET_assert (NULL != peer->io_read_handle);
122} 123}
123 124
125
124/** 126/**
125 * The write completion function; called upon writing some data to stream or 127 * The write completion function; called upon writing some data to stream or
126 * upon error 128 * upon error
@@ -159,6 +161,7 @@ stream_write_task (void *cls,
159 GNUNET_assert (NULL != peer->io_write_handle); 161 GNUNET_assert (NULL != peer->io_write_handle);
160 } 162 }
161 163
164
162/** 165/**
163 * Shutdown nicely 166 * Shutdown nicely
164 */ 167 */
@@ -175,17 +178,6 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
175 { 178 {
176 GNUNET_SCHEDULER_cancel (abort_task); 179 GNUNET_SCHEDULER_cancel (abort_task);
177 } 180 }
178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: arm\n");
179 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
180 {
181 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
182 }
183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Wait\n");
184 /* Free the duplicated configuration */
185 GNUNET_CONFIGURATION_destroy (config_peer1);
186 GNUNET_CONFIGURATION_destroy (config_peer2);
187 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
188 GNUNET_OS_process_destroy (arm_pid);
189} 181}
190 182
191 183
@@ -196,11 +188,6 @@ static void
196do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 188do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
197{ 189{
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: ABORT\n"); 190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: ABORT\n");
199 if (0 != test_task)
200 {
201 GNUNET_SCHEDULER_cancel (test_task);
202 }
203
204 result = GNUNET_SYSERR; 191 result = GNUNET_SYSERR;
205 abort_task = 0; 192 abort_task = 0;
206 do_shutdown (cls, tc); 193 do_shutdown (cls, tc);
@@ -225,7 +212,6 @@ write_completion (void *cls,
225 GNUNET_assert (GNUNET_STREAM_OK == status); 212 GNUNET_assert (GNUNET_STREAM_OK == status);
226 GNUNET_assert (size <= strlen (data)); 213 GNUNET_assert (size <= strlen (data));
227 peer->bytes_wrote += size; 214 peer->bytes_wrote += size;
228
229 if (peer->bytes_wrote < strlen(data)) /* Have more data to send */ 215 if (peer->bytes_wrote < strlen(data)) /* Have more data to send */
230 { 216 {
231 GNUNET_SCHEDULER_add_now (&stream_write_task, peer); 217 GNUNET_SCHEDULER_add_now (&stream_write_task, peer);
@@ -234,8 +220,7 @@ write_completion (void *cls,
234 { 220 {
235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
236 "Writing completed\n"); 222 "Writing completed\n");
237 223 if (&peer1 == peer) /* Peer1 has finished writing; should read now */
238 if (&peer1 == peer) /* Peer1 has finished writing; should read now */
239 { 224 {
240 peer->bytes_read = 0; 225 peer->bytes_read = 0;
241 GNUNET_SCHEDULER_add_now (&stream_read_task, peer); 226 GNUNET_SCHEDULER_add_now (&stream_read_task, peer);
@@ -265,7 +250,6 @@ stream_open_cb (void *cls,
265 GNUNET_assert (&peer1 == peer); 250 GNUNET_assert (&peer1 == peer);
266 GNUNET_assert (socket == peer1.socket); 251 GNUNET_assert (socket == peer1.socket);
267 GNUNET_assert (socket == peer->socket); 252 GNUNET_assert (socket == peer->socket);
268
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stream established from peer1\n"); 253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stream established from peer1\n");
270 peer->bytes_wrote = 0; 254 peer->bytes_wrote = 0;
271 GNUNET_SCHEDULER_add_now (&stream_write_task, peer); 255 GNUNET_SCHEDULER_add_now (&stream_write_task, peer);
@@ -295,8 +279,7 @@ input_processor (void *cls,
295 GNUNET_assert (0 == strncmp ((const char *) data + peer->bytes_read, 279 GNUNET_assert (0 == strncmp ((const char *) data + peer->bytes_read,
296 (const char *) input_data, 280 (const char *) input_data,
297 size)); 281 size));
298 peer->bytes_read += size; 282 peer->bytes_read += size;
299
300 if (peer->bytes_read < strlen (data)) 283 if (peer->bytes_read < strlen (data))
301 { 284 {
302 GNUNET_SCHEDULER_add_now (&stream_read_task, peer); 285 GNUNET_SCHEDULER_add_now (&stream_read_task, peer);
@@ -335,22 +318,15 @@ stream_listen_cb (void *cls,
335 const struct GNUNET_PeerIdentity *initiator) 318 const struct GNUNET_PeerIdentity *initiator)
336{ 319{
337 struct PeerData *peer=cls; 320 struct PeerData *peer=cls;
338 struct GNUNET_PeerIdentity self;
339 321
340 GNUNET_assert (NULL != socket); 322 GNUNET_assert (NULL != socket);
341 GNUNET_assert (socket != peer1.socket); 323 GNUNET_assert (socket != peer1.socket);
342 GNUNET_assert (&peer2 == peer); 324 GNUNET_assert (&peer2 == peer);
343 325 GNUNET_assert (0 == memcmp (&self_id,
344 /* Get our identity */
345 GNUNET_assert (GNUNET_OK == GNUNET_TESTING_get_peer_identity (config_peer1,
346 &self));
347 GNUNET_assert (0 == memcmp (&self,
348 initiator, 326 initiator,
349 sizeof (struct GNUNET_PeerIdentity))); 327 sizeof (struct GNUNET_PeerIdentity)));
350
351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
352 "Peer connected: %s\n", GNUNET_i2s(initiator)); 329 "Peer connected: %s\n", GNUNET_i2s(initiator));
353
354 peer->socket = socket; 330 peer->socket = socket;
355 peer->bytes_read = 0; 331 peer->bytes_read = 0;
356 GNUNET_SCHEDULER_add_now (&stream_read_task, &peer2); 332 GNUNET_SCHEDULER_add_now (&stream_read_task, &peer2);
@@ -368,14 +344,11 @@ static void
368stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 344stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
369{ 345{
370 struct PeerData *peer = cls; 346 struct PeerData *peer = cls;
371 struct GNUNET_PeerIdentity self;
372 347
373 GNUNET_assert (&peer1 == peer); 348 GNUNET_assert (&peer1 == peer);
374 GNUNET_assert (GNUNET_OK == GNUNET_TESTING_get_peer_identity (config_peer1,
375 &self));
376 /* Connect to stream library */ 349 /* Connect to stream library */
377 peer->socket = GNUNET_STREAM_open (config_peer1, 350 peer->socket = GNUNET_STREAM_open (config,
378 &self, /* Null for local peer? */ 351 &self_id,
379 10, /* App port */ 352 10, /* App port */
380 &stream_open_cb, 353 &stream_open_cb,
381 &peer1, 354 &peer1,
@@ -385,61 +358,27 @@ stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
385 358
386 359
387/** 360/**
388 * Testing function 361 * Initialize framework and start test
389 *
390 * @param cls NULL
391 * @param tc the task context
392 */ 362 */
393static void 363static void
394test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 364run (void *cls,
365 const struct GNUNET_CONFIGURATION_Handle *cfg,
366 struct GNUNET_TESTING_Peer *peer)
395{ 367{
396 struct GNUNET_PeerIdentity self; 368 config = cfg;
397 369 self = peer;
398 test_task = GNUNET_SCHEDULER_NO_TASK; 370 GNUNET_TESTING_peer_get_identity (peer, &self_id);
399 /* Get our identity */ 371 peer2_listen_socket = GNUNET_STREAM_listen (config,
400 GNUNET_assert (GNUNET_OK == GNUNET_TESTING_get_peer_identity (config_peer1,
401 &self));
402
403 peer2_listen_socket = GNUNET_STREAM_listen (config_peer2,
404 10, /* App port */ 372 10, /* App port */
405 &stream_listen_cb, 373 &stream_listen_cb,
406 &peer2, 374 &peer2,
407 GNUNET_STREAM_OPTION_END); 375 GNUNET_STREAM_OPTION_END);
408 GNUNET_assert (NULL != peer2_listen_socket); 376 GNUNET_assert (NULL != peer2_listen_socket);
409 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(2), &stream_connect, &peer1); 377 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(2), &stream_connect, &peer1);
410} 378 abort_task =
411 379 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
412/** 380 (GNUNET_TIME_UNIT_SECONDS, 30), &do_abort,
413 * Initialize framework and start test 381 NULL);
414 */
415static void
416run (void *cls, char *const *args, const char *cfgfile,
417 const struct GNUNET_CONFIGURATION_Handle *cfg)
418{
419 GNUNET_log_setup ("test_stream_local",
420#if VERBOSE
421 "DEBUG",
422#else
423 "WARNING",
424#endif
425 NULL);
426 /* Duplicate the configuration */
427 config_peer1 = GNUNET_CONFIGURATION_dup (cfg);
428 config_peer2 = GNUNET_CONFIGURATION_dup (cfg);
429 arm_pid =
430 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
431 "gnunet-service-arm",
432#if VERBOSE_ARM
433 "-L", "DEBUG",
434#endif
435 "-c", "test_stream_local.conf", NULL);
436
437 abort_task =
438 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
439 (GNUNET_TIME_UNIT_SECONDS, 60), &do_abort,
440 NULL);
441
442 test_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(2), &test, NULL);
443} 382}
444 383
445/** 384/**
@@ -447,35 +386,11 @@ run (void *cls, char *const *args, const char *cfgfile,
447 */ 386 */
448int main (int argc, char **argv) 387int main (int argc, char **argv)
449{ 388{
450 int ret; 389 if (0 != GNUNET_TESTING_peer_run ("test_stream_local",
451 390 "test_stream_local.conf",
452 char *const argv2[] = { "test-stream-local", 391 &run, NULL))
453 "-c", "test_stream_local.conf",
454#if VERBOSE
455 "-L", "DEBUG",
456#endif
457 NULL
458 };
459
460 struct GNUNET_GETOPT_CommandLineOption options[] = {
461 GNUNET_GETOPT_OPTION_END
462 };
463
464 ret =
465 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
466 "test-stream-local", "nohelp", options, &run, NULL);
467
468 if (GNUNET_OK != ret)
469 {
470 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n",
471 ret);
472 return 1; 392 return 1;
473 } 393 return (GNUNET_SYSERR == result) ? 1 : 0;
474 if (GNUNET_SYSERR == result)
475 {
476 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
477 return 1;
478 }
479 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test ok\n");
480 return 0;
481} 394}
395
396/* end of test_stream_local.c */
diff --git a/src/stream/test_stream_sequence_wraparound.c b/src/stream/test_stream_sequence_wraparound.c
index b71e96b27..b00de0b1c 100644
--- a/src/stream/test_stream_sequence_wraparound.c
+++ b/src/stream/test_stream_sequence_wraparound.c
@@ -29,11 +29,17 @@
29#include "platform.h" 29#include "platform.h"
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_stream_lib.h" 31#include "gnunet_stream_lib.h"
32#include "gnunet_testing_lib.h" 32#include "gnunet_testing_lib-new.h"
33 33
34/**
35 * Generic logging shorthand
36 */
34#define LOG(kind, ...) \ 37#define LOG(kind, ...) \
35 GNUNET_log (kind, __VA_ARGS__); 38 GNUNET_log (kind, __VA_ARGS__);
36 39
40/**
41 * Relative seconds shorthand
42 */
37#define TIME_REL_SECS(sec) \ 43#define TIME_REL_SECS(sec) \
38 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) 44 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
39 45
@@ -68,14 +74,14 @@ struct PeerData
68 unsigned int bytes_read; 74 unsigned int bytes_read;
69}; 75};
70 76
71static struct GNUNET_OS_Process *arm_pid;
72static struct PeerData peer1; 77static struct PeerData peer1;
73static struct PeerData peer2; 78static struct PeerData peer2;
74static struct GNUNET_STREAM_ListenSocket *peer2_listen_socket; 79static struct GNUNET_STREAM_ListenSocket *peer2_listen_socket;
75static struct GNUNET_CONFIGURATION_Handle *config; 80static const struct GNUNET_CONFIGURATION_Handle *config;
81static struct GNUNET_TESTING_Peer *self;
82static struct GNUNET_PeerIdentity self_id;
76 83
77static GNUNET_SCHEDULER_TaskIdentifier abort_task; 84static GNUNET_SCHEDULER_TaskIdentifier abort_task;
78static GNUNET_SCHEDULER_TaskIdentifier test_task;
79static GNUNET_SCHEDULER_TaskIdentifier read_task; 85static GNUNET_SCHEDULER_TaskIdentifier read_task;
80static GNUNET_SCHEDULER_TaskIdentifier write_task; 86static GNUNET_SCHEDULER_TaskIdentifier write_task;
81 87
@@ -99,16 +105,6 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
99 { 105 {
100 GNUNET_SCHEDULER_cancel (abort_task); 106 GNUNET_SCHEDULER_cancel (abort_task);
101 } 107 }
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: arm\n");
103 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
104 {
105 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
106 }
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Wait\n");
108 /* Free the duplicated configuration */
109 GNUNET_CONFIGURATION_destroy (config);
110 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
111 GNUNET_OS_process_destroy (arm_pid);
112} 108}
113 109
114 110
@@ -119,11 +115,7 @@ static void
119do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 115do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
120{ 116{
121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: ABORT\n"); 117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: ABORT\n");
122 if (0 != test_task) 118 if (GNUNET_SCHEDULER_NO_TASK != read_task)
123 {
124 GNUNET_SCHEDULER_cancel (test_task);
125 }
126 if (0 != read_task)
127 { 119 {
128 GNUNET_SCHEDULER_cancel (read_task); 120 GNUNET_SCHEDULER_cancel (read_task);
129 } 121 }
@@ -263,13 +255,6 @@ input_processor (void *cls,
263 { 255 {
264 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == read_task); 256 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == read_task);
265 read_task = GNUNET_SCHEDULER_add_now (&stream_read_task, &peer2); 257 read_task = GNUNET_SCHEDULER_add_now (&stream_read_task, &peer2);
266 /* peer->io_read_handle = GNUNET_STREAM_read ((struct GNUNET_STREAM_Socket *) */
267 /* peer->socket, */
268 /* GNUNET_TIME_relative_multiply */
269 /* (GNUNET_TIME_UNIT_SECONDS, 5), */
270 /* &input_processor, */
271 /* cls); */
272 /* GNUNET_assert (NULL != peer->io_read_handle); */
273 } 258 }
274 else 259 else
275 { 260 {
@@ -318,10 +303,8 @@ stream_listen_cb (void *cls,
318{ 303{
319 GNUNET_assert (NULL != socket); 304 GNUNET_assert (NULL != socket);
320 GNUNET_assert (socket != peer1.socket); 305 GNUNET_assert (socket != peer1.socket);
321
322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
323 "Peer connected: %s\n", GNUNET_i2s(initiator)); 307 "Peer connected: %s\n", GNUNET_i2s(initiator));
324
325 peer2.socket = socket; 308 peer2.socket = socket;
326 peer2.bytes_read = 0; 309 peer2.bytes_read = 0;
327 read_task = GNUNET_SCHEDULER_add_now (&stream_read_task, &peer2); 310 read_task = GNUNET_SCHEDULER_add_now (&stream_read_task, &peer2);
@@ -339,14 +322,11 @@ static void
339stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 322stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
340{ 323{
341 struct PeerData *peer = cls; 324 struct PeerData *peer = cls;
342 struct GNUNET_PeerIdentity self;
343 325
344 GNUNET_assert (&peer1 == peer); 326 GNUNET_assert (&peer1 == peer);
345 GNUNET_assert (GNUNET_OK == GNUNET_TESTING_get_peer_identity (config,
346 &self));
347 /* Connect to stream */ 327 /* Connect to stream */
348 peer->socket = GNUNET_STREAM_open (config, 328 peer->socket = GNUNET_STREAM_open (config,
349 &self, /* Null for local peer? */ 329 &self_id, /* Null for local peer? */
350 10, /* App port */ 330 10, /* App port */
351 &stream_open_cb, 331 &stream_open_cb,
352 &peer1, 332 &peer1,
@@ -359,21 +339,16 @@ stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
359 339
360 340
361/** 341/**
362 * Testing function 342 * Initialize framework and start test
363 *
364 * @param cls NULL
365 * @param tc the task context
366 */ 343 */
367static void 344static void
368test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 345run (void *cls,
346 const struct GNUNET_CONFIGURATION_Handle *cfg,
347 struct GNUNET_TESTING_Peer *peer)
369{ 348{
370 struct GNUNET_PeerIdentity self; 349 config = cfg;
371 350 self = peer;
372 test_task = GNUNET_SCHEDULER_NO_TASK; 351 (void) GNUNET_TESTING_peer_get_identity (peer, &self_id);
373 /* Get our identity */
374 GNUNET_assert (GNUNET_OK == GNUNET_TESTING_get_peer_identity (config,
375 &self));
376
377 peer2_listen_socket = GNUNET_STREAM_listen (config, 352 peer2_listen_socket = GNUNET_STREAM_listen (config,
378 10, /* App port */ 353 10, /* App port */
379 &stream_listen_cb, 354 &stream_listen_cb,
@@ -381,65 +356,23 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
381 GNUNET_STREAM_OPTION_END); 356 GNUNET_STREAM_OPTION_END);
382 GNUNET_assert (NULL != peer2_listen_socket); 357 GNUNET_assert (NULL != peer2_listen_socket);
383 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(2), &stream_connect, &peer1); 358 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(2), &stream_connect, &peer1);
384}
385
386
387/**
388 * Initialize framework and start test
389 */
390static void
391run (void *cls, char *const *args, const char *cfgfile,
392 const struct GNUNET_CONFIGURATION_Handle *cfg)
393{
394 /* Duplicate the configuration */
395 config = GNUNET_CONFIGURATION_dup (cfg);
396 arm_pid =
397 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
398 "gnunet-service-arm",
399#if VERBOSE_ARM
400 "-L", "DEBUG",
401#endif
402 "-c", "test_stream_local.conf", NULL);
403
404 abort_task = 359 abort_task =
405 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 360 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
406 (GNUNET_TIME_UNIT_SECONDS, 60), &do_abort, 361 (GNUNET_TIME_UNIT_SECONDS, 60), &do_abort,
407 NULL); 362 NULL);
408 test_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(3), &test, NULL);
409} 363}
410 364
365
411/** 366/**
412 * Main function 367 * Main function
413 */ 368 */
414int main (int argc, char **argv) 369int main (int argc, char **argv)
415{ 370{
416 int ret; 371 if (0 != GNUNET_TESTING_peer_run ("test_stream_sequence_wraparound",
417 372 "test_stream_local.conf",
418 char *const argv2[] = { "test-stream-big", 373 &run, NULL))
419 "-c", "test_stream_local.conf",
420 "-L", "DEBUG",
421 NULL
422 };
423
424 struct GNUNET_GETOPT_CommandLineOption options[] = {
425 GNUNET_GETOPT_OPTION_END
426 };
427
428 ret =
429 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
430 "test-stream-big", "nohelp", options, &run, NULL);
431
432 if (GNUNET_OK != ret)
433 {
434 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n",
435 ret);
436 return 1;
437 }
438 if (GNUNET_SYSERR == result)
439 {
440 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
441 return 1; 374 return 1;
442 } 375 return (GNUNET_SYSERR == result) ? 1 : 0;
443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test ok\n");
444 return 0;
445} 376}
377
378/* end of test_stream_sequence_wraparound.c */