2 This file is part of GNUnet.
3 Copyright (C) 2008-2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file util/test_common_logging_dummy.c
23 * @brief dummy labrat for the testcase for the logging module (runtime
24 * log level adjustment)
28 #undef GNUNET_EXTRA_LOGGING
29 #define GNUNET_EXTRA_LOGGING GNUNET_YES
31 #include "gnunet_util_lib.h"
34 * Artificial delay attached to each log call that is not skipped out.
35 * This must be long enough for us to not to mistake skipped log call
36 * on a slow machine for a non-skipped one.
38 #define OUTPUT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 1000)
41 my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component,
42 const char *date, const char *msg)
44 if (strncmp ("test-common-logging-dummy", component, 25) != 0)
46 FPRINTF (stdout, "%s", msg);
51 #if !defined(GNUNET_CULL_LOGGING)
55 return GNUNET_NETWORK_socket_select (NULL, NULL, NULL, OUTPUT_DELAY);
60 #define pr(kind,lvl) {\
61 struct GNUNET_TIME_Absolute t1, t2;\
62 t1 = GNUNET_TIME_absolute_get ();\
63 GNUNET_log (kind, "L%s %d\n", lvl, expensive_func());\
64 t2 = GNUNET_TIME_absolute_get ();\
65 printf ("1%s %llu\n", lvl,\
66 (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2).rel_value_us); \
69 #define pr2(kind,lvl) {\
70 struct GNUNET_TIME_Absolute t1, t2;\
71 t1 = GNUNET_TIME_absolute_get ();\
72 GNUNET_log (kind, "L%s %d\n", lvl, expensive_func());\
73 t2 = GNUNET_TIME_absolute_get ();\
74 printf ("2%s %llu\n", lvl,\
75 (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2).rel_value_us); \
79 main (int argc, char *argv[])
81 /* We set up logging with NULL level - will be overrided by
82 * GNUNET_LOG or GNUNET_FORCE_LOG at runtime.
84 GNUNET_log_setup ("test-common-logging-dummy", NULL, "/dev/null");
85 GNUNET_logger_add (&my_log, NULL);
86 pr (GNUNET_ERROR_TYPE_ERROR, "ERROR");
87 pr (GNUNET_ERROR_TYPE_WARNING, "WARNING");
88 pr (GNUNET_ERROR_TYPE_INFO, "INFO");
89 pr (GNUNET_ERROR_TYPE_DEBUG, "DEBUG");
91 /* We set up logging with WARNING level - will onle be overrided by
92 * GNUNET_FORCE_LOG at runtime.
94 GNUNET_log_setup ("test-common-logging-dummy", "WARNING", "/dev/null");
95 pr2 (GNUNET_ERROR_TYPE_ERROR, "ERROR");
96 pr2 (GNUNET_ERROR_TYPE_WARNING, "WARNING");
97 pr2 (GNUNET_ERROR_TYPE_INFO, "INFO");
98 pr2 (GNUNET_ERROR_TYPE_DEBUG, "DEBUG");
102 /* end of test_common_logging_dummy.c */