aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-04-23 15:30:49 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-04-23 15:30:49 +0000
commit0793e4b7af79a49bf1bc275be95f306136ac8cbb (patch)
tree838cd314a7b6fb4bdc26bac25495ca63a3d7967e /src/testbed
parent8fb73cef0924f46c39d09aabbb3b5748e7ae68c7 (diff)
downloadgnunet-0793e4b7af79a49bf1bc275be95f306136ac8cbb.tar.gz
gnunet-0793e4b7af79a49bf1bc275be95f306136ac8cbb.zip
- test cases for testbed logger
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/Makefile.am9
-rw-r--r--src/testbed/test_testbed_logger_api.c175
-rw-r--r--src/testbed/test_testbed_logger_api.conf3
-rw-r--r--src/testbed/testbed_logger_api.c2
4 files changed, 188 insertions, 1 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index 7d65e9fc2..3802cfebe 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -121,6 +121,7 @@ libgnunettestbedlogger_la_LDFLAGS = \
121 121
122check_PROGRAMS = \ 122check_PROGRAMS = \
123 test_testbed_api_hosts \ 123 test_testbed_api_hosts \
124 test_testbed_logger_api \
124 test_gnunet_helper_testbed \ 125 test_gnunet_helper_testbed \
125 test_testbed_api_controllerlink \ 126 test_testbed_api_controllerlink \
126 test_testbed_api_2peers_1controller \ 127 test_testbed_api_2peers_1controller \
@@ -148,6 +149,7 @@ check_PROGRAMS = \
148if ENABLE_TEST_RUN 149if ENABLE_TEST_RUN
149 TESTS = \ 150 TESTS = \
150 test_testbed_api \ 151 test_testbed_api \
152 test_testbed_logger_api \
151 test_testbed_api_sd \ 153 test_testbed_api_sd \
152 test_testbed_api_operations \ 154 test_testbed_api_operations \
153 test_testbed_api_hosts \ 155 test_testbed_api_hosts \
@@ -187,6 +189,13 @@ test_testbed_api_LDADD = \
187 $(top_builddir)/src/dht/libgnunetdht.la \ 189 $(top_builddir)/src/dht/libgnunetdht.la \
188 libgnunettestbed.la 190 libgnunettestbed.la
189 191
192test_testbed_logger_api_SOURCES = \
193 test_testbed_logger_api.c
194test_testbed_logger_api_LDADD = \
195 $(top_builddir)/src/util/libgnunetutil.la \
196 $(top_builddir)/src/testing/libgnunettesting.la \
197 libgnunettestbedlogger.la
198
190test_testbed_api_sd_SOURCES = \ 199test_testbed_api_sd_SOURCES = \
191 test_testbed_api_sd.c 200 test_testbed_api_sd.c
192test_testbed_api_sd_LDADD = \ 201test_testbed_api_sd_LDADD = \
diff --git a/src/testbed/test_testbed_logger_api.c b/src/testbed/test_testbed_logger_api.c
new file mode 100644
index 000000000..f2fef7e41
--- /dev/null
+++ b/src/testbed/test_testbed_logger_api.c
@@ -0,0 +1,175 @@
1/*
2 This file is part of GNUnet
3 (C) 2008--2013 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file testbed/test_testbed_logger_api.c
23 * @brief testcases for the testbed logger api
24 * @author Sree Harsha Totakura
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_testing_lib.h"
30#include "gnunet_testbed_logger_service.h"
31
32/**
33 * Generic logging shortcut
34 */
35#define LOG(kind,...) \
36 GNUNET_log (kind, __VA_ARGS__)
37
38/**
39 * Relative time seconds shorthand
40 */
41#define TIME_REL_SECS(sec) \
42 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
43
44/**
45 * Opaque handle for the logging service
46 */
47struct GNUNET_TESTBED_LOGGER_Handle *h;
48
49/**
50 * Abort task identifier
51 */
52static GNUNET_SCHEDULER_TaskIdentifier abort_task;
53static GNUNET_SCHEDULER_TaskIdentifier write_task;
54
55static int result;
56
57#define CANCEL_TASK(task) do { \
58 if (GNUNET_SCHEDULER_NO_TASK != task) \
59 { \
60 GNUNET_SCHEDULER_cancel (task); \
61 task = GNUNET_SCHEDULER_NO_TASK; \
62 } \
63 } while (0)
64
65/**
66 * shortcut to exit during failure
67 */
68#define FAIL_TEST(cond, ret) do { \
69 if (!(cond)) { \
70 GNUNET_break(0); \
71 CANCEL_TASK (abort_task); \
72 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
73 ret; \
74 } \
75 } while (0)
76
77/**
78 * Shutdown nicely
79 *
80 * @param cls NULL
81 * @param tc the task context
82 */
83static void
84shutdown_now ()
85{
86 CANCEL_TASK (abort_task);
87 CANCEL_TASK (write_task);
88 GNUNET_SCHEDULER_shutdown ();
89}
90
91
92static void
93do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
94{
95 LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
96 abort_task = GNUNET_SCHEDULER_NO_TASK;
97 shutdown_now ();
98}
99
100
101#define BSIZE 1024
102
103/**
104 * Functions of this type are called to notify a successful transmission of the
105 * message to the logger service
106 *
107 * @param cls the closure given to GNUNET_TESTBED_LOGGER_send()
108 * @param size the amount of data sent
109 */
110static void
111flush_comp (void *cls, size_t size)
112{
113 FAIL_TEST (&write_task == cls, return);
114 FAIL_TEST ((BSIZE * 2) == size, return);
115 result = GNUNET_OK;
116 shutdown_now ();
117}
118
119
120static void
121do_write (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
122{
123 static int i;
124 char buf[BSIZE];
125
126 write_task = GNUNET_SCHEDULER_NO_TASK;
127 if (0 == i)
128 write_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(1), &do_write, NULL);
129 (void) memset (buf, i, BSIZE);
130 GNUNET_TESTBED_LOGGER_write (h, buf, BSIZE);
131 if (0 == i++)
132 return;
133 GNUNET_TESTBED_LOGGER_flush (h, &flush_comp, &write_task);
134}
135
136
137/**
138 * Signature of the 'main' function for a (single-peer) testcase that
139 * is run using 'GNUNET_TESTING_peer_run'.
140 *
141 * @param cls closure
142 * @param cfg configuration of the peer that was started
143 * @param peer identity of the peer that was created
144 */
145static void
146test_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
147 struct GNUNET_TESTING_Peer *peer)
148{
149 FAIL_TEST (NULL != (h = GNUNET_TESTBED_LOGGER_connect (cfg)), return);
150 write_task = GNUNET_SCHEDULER_add_now (&do_write, NULL);
151 abort_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (10),
152 &do_abort, NULL);
153}
154
155
156/**
157 * Main function
158 */
159int
160main (int argc, char **argv)
161{
162 int ret;
163
164 result = GNUNET_SYSERR;
165 ret = GNUNET_TESTING_service_run ("test-testbed-logger",
166 "testbed-logger",
167 "test_testbed_logger_api.conf",
168 &test_main,
169 NULL);
170 if (0 != ret)
171 return 1;
172 if (GNUNET_OK != result)
173 return 2;
174 return 0;
175}
diff --git a/src/testbed/test_testbed_logger_api.conf b/src/testbed/test_testbed_logger_api.conf
new file mode 100644
index 000000000..82bffc31d
--- /dev/null
+++ b/src/testbed/test_testbed_logger_api.conf
@@ -0,0 +1,3 @@
1[testbed-logger]
2UNIXPATH=/tmp/testbed-logger.sock
3DIR=$SERVICEHOME/data \ No newline at end of file
diff --git a/src/testbed/testbed_logger_api.c b/src/testbed/testbed_logger_api.c
index 652280850..674a170d3 100644
--- a/src/testbed/testbed_logger_api.c
+++ b/src/testbed/testbed_logger_api.c
@@ -199,7 +199,7 @@ transmit_ready_notify (void *cls, size_t size, void *buf)
199 GNUNET_free (mq->msg); 199 GNUNET_free (mq->msg);
200 GNUNET_CONTAINER_DLL_remove (h->mq_head, h->mq_tail, mq); 200 GNUNET_CONTAINER_DLL_remove (h->mq_head, h->mq_tail, mq);
201 GNUNET_free (mq); 201 GNUNET_free (mq);
202 h->bwrote += size; 202 h->bwrote += (size - sizeof (struct GNUNET_MessageHeader));
203 mq = h->mq_head; 203 mq = h->mq_head;
204 if (NULL != mq) 204 if (NULL != mq)
205 { 205 {