2 This file is part of GNUnet
3 (C) 2008--2013 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file testbed/test_testbed_logger_api.c
23 * @brief testcases for the testbed logger api
24 * @author Sree Harsha Totakura
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testing_lib.h"
30 #include "gnunet_testbed_logger_service.h"
33 * Generic logging shortcut
35 #define LOG(kind,...) \
36 GNUNET_log (kind, __VA_ARGS__)
39 * Relative time seconds shorthand
41 #define TIME_REL_SECS(sec) \
42 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
45 * Opaque handle for the logging service
47 struct GNUNET_TESTBED_LOGGER_Handle *h;
50 * Abort task identifier
52 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
53 static GNUNET_SCHEDULER_TaskIdentifier write_task;
57 #define CANCEL_TASK(task) do { \
58 if (GNUNET_SCHEDULER_NO_TASK != task) \
60 GNUNET_SCHEDULER_cancel (task); \
61 task = GNUNET_SCHEDULER_NO_TASK; \
66 * shortcut to exit during failure
68 #define FAIL_TEST(cond, ret) do { \
71 CANCEL_TASK (abort_task); \
72 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
81 * @param tc the task context
86 CANCEL_TASK (abort_task);
87 CANCEL_TASK (write_task);
88 GNUNET_SCHEDULER_shutdown ();
93 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
95 LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
96 abort_task = GNUNET_SCHEDULER_NO_TASK;
104 * Functions of this type are called to notify a successful transmission of the
105 * message to the logger service
107 * @param cls the closure given to GNUNET_TESTBED_LOGGER_send()
108 * @param size the amount of data sent
111 flush_comp (void *cls, size_t size)
113 FAIL_TEST (&write_task == cls, return);
114 FAIL_TEST ((BSIZE * 2) == size, return);
121 do_write (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
126 write_task = GNUNET_SCHEDULER_NO_TASK;
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);
133 GNUNET_TESTBED_LOGGER_flush (h, &flush_comp, &write_task);
138 * Signature of the 'main' function for a (single-peer) testcase that
139 * is run using 'GNUNET_TESTING_peer_run'.
142 * @param cfg configuration of the peer that was started
143 * @param peer identity of the peer that was created
146 test_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
147 struct GNUNET_TESTING_Peer *peer)
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),
160 main (int argc, char **argv)
164 result = GNUNET_SYSERR;
165 ret = GNUNET_TESTING_service_run ("test-testbed-logger",
167 "test_testbed_logger_api.conf",
172 if (GNUNET_OK != result)