aboutsummaryrefslogtreecommitdiff
path: root/src/lib/util/test_common_logging_dummy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/test_common_logging_dummy.c')
-rw-r--r--src/lib/util/test_common_logging_dummy.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/lib/util/test_common_logging_dummy.c b/src/lib/util/test_common_logging_dummy.c
new file mode 100644
index 000000000..7e362c683
--- /dev/null
+++ b/src/lib/util/test_common_logging_dummy.c
@@ -0,0 +1,123 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2008-2013 GNUnet e.V.
4
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.
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 Affero General Public License for more details.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file util/test_common_logging_dummy.c
23 * @brief dummy labrat for the testcase for the logging module (runtime
24 * log level adjustment)
25 * @author LRN
26 */
27
28#include "platform.h"
29#include "gnunet_util_lib.h"
30
31#undef GNUNET_EXTRA_LOGGING
32#define GNUNET_EXTRA_LOGGING GNUNET_YES
33
34/**
35 * Artificial delay attached to each log call that is not skipped out.
36 * This must be long enough for us to not to mistake skipped log call
37 * on a slow machine for a non-skipped one.
38 */
39#define OUTPUT_DELAY \
40 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 1000)
41
42static void
43my_log (void *ctx,
44 enum GNUNET_ErrorType kind,
45 const char *component,
46 const char *date,
47 const char *msg)
48{
49 (void) ctx;
50 (void) kind;
51 (void) component;
52 (void) date;
53 if (strncmp ("test-common-logging-dummy", component, 25) != 0)
54 return;
55 fprintf (stdout, "%s", msg);
56 fflush (stdout);
57}
58
59
60#if ! defined(GNUNET_CULL_LOGGING)
61static int
62expensive_func ()
63{
64 return GNUNET_NETWORK_socket_select (NULL, NULL, NULL, OUTPUT_DELAY);
65}
66
67
68#endif
69
70
71#define pr(kind, lvl) \
72 { \
73 struct GNUNET_TIME_Absolute t1, t2; \
74 t1 = GNUNET_TIME_absolute_get (); \
75 GNUNET_log (kind, "L%s %d\n", lvl, expensive_func ()); \
76 t2 = GNUNET_TIME_absolute_get (); \
77 printf ("1%s %llu\n", \
78 lvl, \
79 (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2) \
80 .rel_value_us); \
81 }
82
83#define pr2(kind, lvl) \
84 { \
85 struct GNUNET_TIME_Absolute t1, t2; \
86 t1 = GNUNET_TIME_absolute_get (); \
87 GNUNET_log (kind, "L%s %d\n", lvl, expensive_func ()); \
88 t2 = GNUNET_TIME_absolute_get (); \
89 printf ("2%s %llu\n", \
90 lvl, \
91 (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2) \
92 .rel_value_us); \
93 }
94
95
96int
97main (int argc, char *argv[])
98{
99 (void) argc;
100 (void) argv;
101 /* We set up logging with NULL level - will be overridden by
102 * GNUNET_LOG or GNUNET_FORCE_LOG at runtime.
103 */
104 GNUNET_log_setup ("test-common-logging-dummy", NULL, "/dev/null");
105 GNUNET_logger_add (&my_log, NULL);
106 pr (GNUNET_ERROR_TYPE_ERROR, "ERROR");
107 pr (GNUNET_ERROR_TYPE_WARNING, "WARNING");
108 pr (GNUNET_ERROR_TYPE_INFO, "INFO");
109 pr (GNUNET_ERROR_TYPE_DEBUG, "DEBUG");
110
111 /* We set up logging with WARNING level - will onle be overridden by
112 * GNUNET_FORCE_LOG at runtime.
113 */
114 GNUNET_log_setup ("test-common-logging-dummy", "WARNING", "/dev/null");
115 pr2 (GNUNET_ERROR_TYPE_ERROR, "ERROR");
116 pr2 (GNUNET_ERROR_TYPE_WARNING, "WARNING");
117 pr2 (GNUNET_ERROR_TYPE_INFO, "INFO");
118 pr2 (GNUNET_ERROR_TYPE_DEBUG, "DEBUG");
119 return 0;
120} /* end of main */
121
122
123/* end of test_common_logging_dummy.c */