/*
This file is part of GNUnet.
- (C) 2009, 2010 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2009, 2010 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
#include "gauger.h"
#include "transport-testing.h"
+/**
+ * Allow making the problem "bigger".
+ */
+#define FACTOR 1
+
/**
* Total number of messages to send
*
* 'MAX_PENDING' in 'gnunet-service-transport_clients.c', otherwise
* messages may be dropped even for a reliable transport.
*/
-#define TOTAL_MSGS (1024 * 3)
+#define TOTAL_MSGS (1024 * 3 * FACTOR)
/**
* Message type of test messages
/**
* Testcase timeout
*/
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 900)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90 * FACTOR)
/**
* How long until we give up on transmitting the message?
*/
-#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60 * FACTOR)
/**
/**
* Bitmap storing which messages were received
*/
-
static char bitmap[TOTAL_MSGS / 8];
static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
unsigned long long delta;
unsigned long long rate;
char *value_name;
+ unsigned int i;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping peers\n");
/* Calculcate statistics */
delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
rate = (1000LL* 1000ll * total_bytes) / (1024 * delta);
- FPRINTF (stderr, "\nThroughput was %llu KiBytes/s\n",
- rate);
-
- GNUNET_asprintf (&value_name, "unreliable_%s", test_plugin);
- GAUGER ("TRANSPORT", value_name, (int) rate,
+ FPRINTF (stderr,
+ "\nThroughput was %llu KiBytes/s\n",
+ rate);
+
+ GNUNET_asprintf (&value_name,
+ "unreliable_%s",
+ test_plugin);
+ GAUGER ("TRANSPORT",
+ value_name,
+ (int) rate,
"kb/s");
GNUNET_free (value_name);
GNUNET_SCHEDULER_cancel (die_task);
if (th != NULL)
+ {
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
- th = NULL;
-
+ th = NULL;
+ }
if (cc != NULL)
+ {
GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
- cc = NULL;
-
+ cc = NULL;
+ }
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
-
GNUNET_TRANSPORT_TESTING_done (tth);
-
ok = 0;
-
- int i;
-
for (i = 0; i < TOTAL_MSGS; i++)
{
if (get_bit (bitmap, i) == 0)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not receive message %d\n", i);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Did not receive message %d\n",
+ i);
ok = -1;
}
}
}
+
static void
end_badly ()
{
- int i;
- die_task = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
+ unsigned int i;
+ die_task = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Fail! Stopping peers\n");
if (test_connected == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got connected\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Peers got connected\n");
else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Peers got NOT connected\n");
if (test_sending == GNUNET_NO)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
{
if (get_bit (bitmap, i) == 0)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not receive message %d\n", i);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Did not receive message %u\n",
+ i);
ok = -1;
}
}
if (th != NULL)
+ {
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
- th = NULL;
-
+ th = NULL;
+ }
if (cc != NULL)
+ {
GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
- cc = NULL;
-
+ cc = NULL;
+ }
if (p1 != NULL)
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
if (p2 != NULL)
* Sets a bit active in the bitmap.
*
* @param bitIdx which bit to set
- * @return GNUNET_SYSERR on error, GNUNET_OK on success
+ * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
*/
static int
set_bit (unsigned int bitIdx)
if (bitIdx >= sizeof (bitmap) * 8)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "tried to set bit %d of %d(!?!?)\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "tried to set bit %d of %d(!?!?)\n",
bitIdx, sizeof (bitmap) * 8);
return GNUNET_SYSERR;
}
return GNUNET_OK;
}
+
/**
* Obtain a bit from bitmap.
* @param map the bitmap
if (GNUNET_SYSERR == set_bit (ntohl (hdr->num)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Message id %u is bigger than maxmimum number of messages %u expected\n"),
- ntohl (hdr->num), TOTAL_MSGS);
+ "Message id %u is bigger than maxmimum number of messages %u expected\n",
+ ntohl (hdr->num),
+ TOTAL_MSGS);
}
test_sending = GNUNET_YES;
if (0 == (n % (TOTAL_MSGS / 100)))
#if VERBOSE
if (n % 5000 == 0)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u of size %u\n", n,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message %u of size %u\n",
+ n,
s);
}
#endif
else
{
FPRINTF (stderr, "%s", "\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages scheduled to be sent\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All messages scheduled to be sent\n");
if (NULL != die_task)
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
th = NULL;
}
+
static void
sendtask ()
{
start_time = GNUNET_TIME_absolute_get ();
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to send %u messages\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting to send %u messages\n",
TOTAL_MSGS);
th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0),
TIMEOUT_TRANSMIT, ¬ify_ready,
{
char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peers connected: %s <-> %s\n", p1_c,
GNUNET_i2s (&p2->id));
GNUNET_free (p1_c);
GNUNET_SCHEDULER_add_now (&sendtask, NULL);
}
+
static void
start_cb (struct PeerContext *p, void *cls)
{
static int started;
started++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %u (`%s') started\n",
+ p->no,
GNUNET_i2s (&p->id));
if (started != 2)
}
+
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly, NULL);
test_send_timeout = GNUNET_NO;
p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
char *test_source;
int ret;
- static char *const argv_new[] = { "test-transport-api-reliability",
+ static char *const argv_new[] = {
+ "test-transport-api-reliability",
"-c",
"test_transport_api_data.conf",
NULL
GNUNET_GETOPT_OPTION_END
};
- GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name);
-
+ GNUNET_TRANSPORT_TESTING_get_test_name (argv[0],
+ &test_name);
GNUNET_log_setup (test_name,
"WARNING",
NULL);
-
- GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
- GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
+ GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__,
+ &test_source);
+ GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0],
+ test_source,
&test_plugin);
tth = GNUNET_TRANSPORT_TESTING_init ();
GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1);
GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2);
-
-
#if WRITECONFIG
setTransportOptions ("test_transport_api_data.conf");
#endif
ok = GNUNET_SYSERR;
- ret = GNUNET_PROGRAM_run ((sizeof (argv_new) / sizeof (char *)) - 1, argv_new, test_name,
- "nohelp", options, &run, &ok);
+ ret = GNUNET_PROGRAM_run ((sizeof (argv_new) / sizeof (char *)) - 1,
+ argv_new, test_name,
+ "nohelp", options,
+ &run, &ok);
if (GNUNET_SYSERR == ret)
+ {
+ fprintf (stderr,
+ "Test failed: %d\n",
+ ok);
ok = -1;
-
+ }
GNUNET_free (cfg_file_p1);
GNUNET_free (cfg_file_p2);
-
GNUNET_free (test_source);
GNUNET_free (test_plugin);
GNUNET_free (test_name);