[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r26978 - gnunet/src/testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r26978 - gnunet/src/testbed |
Date: |
Tue, 23 Apr 2013 17:30:50 +0200 |
Author: harsha
Date: 2013-04-23 17:30:49 +0200 (Tue, 23 Apr 2013)
New Revision: 26978
Added:
gnunet/src/testbed/test_testbed_logger_api.c
gnunet/src/testbed/test_testbed_logger_api.conf
Modified:
gnunet/src/testbed/
gnunet/src/testbed/Makefile.am
gnunet/src/testbed/testbed_logger_api.c
Log:
- test cases for testbed logger
Index: gnunet/src/testbed
===================================================================
--- gnunet/src/testbed 2013-04-23 11:38:09 UTC (rev 26977)
+++ gnunet/src/testbed 2013-04-23 15:30:49 UTC (rev 26978)
Property changes on: gnunet/src/testbed
___________________________________________________________________
Modified: svn:ignore
## -11,6 +11,7 ##
testbed.conf
test_testbed_api_hosts
test_testbed_api
+test_testbed_logger_api
test_testbed_api_sd
test_testbed_api_2peers_1controller
test_testbed_api_3peers_3controllers
Modified: gnunet/src/testbed/Makefile.am
===================================================================
--- gnunet/src/testbed/Makefile.am 2013-04-23 11:38:09 UTC (rev 26977)
+++ gnunet/src/testbed/Makefile.am 2013-04-23 15:30:49 UTC (rev 26978)
@@ -121,6 +121,7 @@
check_PROGRAMS = \
test_testbed_api_hosts \
+ test_testbed_logger_api \
test_gnunet_helper_testbed \
test_testbed_api_controllerlink \
test_testbed_api_2peers_1controller \
@@ -148,6 +149,7 @@
if ENABLE_TEST_RUN
TESTS = \
test_testbed_api \
+ test_testbed_logger_api \
test_testbed_api_sd \
test_testbed_api_operations \
test_testbed_api_hosts \
@@ -187,6 +189,13 @@
$(top_builddir)/src/dht/libgnunetdht.la \
libgnunettestbed.la
+test_testbed_logger_api_SOURCES = \
+ test_testbed_logger_api.c
+test_testbed_logger_api_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ libgnunettestbedlogger.la
+
test_testbed_api_sd_SOURCES = \
test_testbed_api_sd.c
test_testbed_api_sd_LDADD = \
Added: gnunet/src/testbed/test_testbed_logger_api.c
===================================================================
--- gnunet/src/testbed/test_testbed_logger_api.c
(rev 0)
+++ gnunet/src/testbed/test_testbed_logger_api.c 2013-04-23 15:30:49 UTC
(rev 26978)
@@ -0,0 +1,175 @@
+/*
+ This file is part of GNUnet
+ (C) 2008--2013 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
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file testbed/test_testbed_logger_api.c
+ * @brief testcases for the testbed logger api
+ * @author Sree Harsha Totakura
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_lib.h"
+#include "gnunet_testbed_logger_service.h"
+
+/**
+ * Generic logging shortcut
+ */
+#define LOG(kind,...) \
+ GNUNET_log (kind, __VA_ARGS__)
+
+/**
+ * Relative time seconds shorthand
+ */
+#define TIME_REL_SECS(sec) \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
+
+/**
+ * Opaque handle for the logging service
+ */
+struct GNUNET_TESTBED_LOGGER_Handle *h;
+
+/**
+ * Abort task identifier
+ */
+static GNUNET_SCHEDULER_TaskIdentifier abort_task;
+static GNUNET_SCHEDULER_TaskIdentifier write_task;
+
+static int result;
+
+#define CANCEL_TASK(task) do { \
+ if (GNUNET_SCHEDULER_NO_TASK != task) \
+ { \
+ GNUNET_SCHEDULER_cancel (task); \
+ task = GNUNET_SCHEDULER_NO_TASK; \
+ } \
+ } while (0)
+
+/**
+ * shortcut to exit during failure
+ */
+#define FAIL_TEST(cond, ret) do { \
+ if (!(cond)) { \
+ GNUNET_break(0); \
+ CANCEL_TASK (abort_task); \
+ abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
+ ret; \
+ } \
+ } while (0)
+
+/**
+ * Shutdown nicely
+ *
+ * @param cls NULL
+ * @param tc the task context
+ */
+static void
+shutdown_now ()
+{
+ CANCEL_TASK (abort_task);
+ CANCEL_TASK (write_task);
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+static void
+do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
+ abort_task = GNUNET_SCHEDULER_NO_TASK;
+ shutdown_now ();
+}
+
+
+#define BSIZE 1024
+
+/**
+ * Functions of this type are called to notify a successful transmission of the
+ * message to the logger service
+ *
+ * @param cls the closure given to GNUNET_TESTBED_LOGGER_send()
+ * @param size the amount of data sent
+ */
+static void
+flush_comp (void *cls, size_t size)
+{
+ FAIL_TEST (&write_task == cls, return);
+ FAIL_TEST ((BSIZE * 2) == size, return);
+ result = GNUNET_OK;
+ shutdown_now ();
+}
+
+
+static void
+do_write (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ static int i;
+ char buf[BSIZE];
+
+ write_task = GNUNET_SCHEDULER_NO_TASK;
+ if (0 == i)
+ write_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(1), &do_write,
NULL);
+ (void) memset (buf, i, BSIZE);
+ GNUNET_TESTBED_LOGGER_write (h, buf, BSIZE);
+ if (0 == i++)
+ return;
+ GNUNET_TESTBED_LOGGER_flush (h, &flush_comp, &write_task);
+}
+
+
+/**
+ * Signature of the 'main' function for a (single-peer) testcase that
+ * is run using 'GNUNET_TESTING_peer_run'.
+ *
+ * @param cls closure
+ * @param cfg configuration of the peer that was started
+ * @param peer identity of the peer that was created
+ */
+static void
+test_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Peer *peer)
+{
+ FAIL_TEST (NULL != (h = GNUNET_TESTBED_LOGGER_connect (cfg)), return);
+ write_task = GNUNET_SCHEDULER_add_now (&do_write, NULL);
+ abort_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (10),
+ &do_abort, NULL);
+}
+
+
+/**
+ * Main function
+ */
+int
+main (int argc, char **argv)
+{
+ int ret;
+
+ result = GNUNET_SYSERR;
+ ret = GNUNET_TESTING_service_run ("test-testbed-logger",
+ "testbed-logger",
+ "test_testbed_logger_api.conf",
+ &test_main,
+ NULL);
+ if (0 != ret)
+ return 1;
+ if (GNUNET_OK != result)
+ return 2;
+ return 0;
+}
Added: gnunet/src/testbed/test_testbed_logger_api.conf
===================================================================
--- gnunet/src/testbed/test_testbed_logger_api.conf
(rev 0)
+++ gnunet/src/testbed/test_testbed_logger_api.conf 2013-04-23 15:30:49 UTC
(rev 26978)
@@ -0,0 +1,3 @@
+[testbed-logger]
+UNIXPATH=/tmp/testbed-logger.sock
+DIR=$SERVICEHOME/data
\ No newline at end of file
Modified: gnunet/src/testbed/testbed_logger_api.c
===================================================================
--- gnunet/src/testbed/testbed_logger_api.c 2013-04-23 11:38:09 UTC (rev
26977)
+++ gnunet/src/testbed/testbed_logger_api.c 2013-04-23 15:30:49 UTC (rev
26978)
@@ -199,7 +199,7 @@
GNUNET_free (mq->msg);
GNUNET_CONTAINER_DLL_remove (h->mq_head, h->mq_tail, mq);
GNUNET_free (mq);
- h->bwrote += size;
+ h->bwrote += (size - sizeof (struct GNUNET_MessageHeader));
mq = h->mq_head;
if (NULL != mq)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r26978 - gnunet/src/testbed,
gnunet <=