diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-06 07:45:59 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-06 07:45:59 +0000 |
commit | 7c761db5dc34daba09b587c6b5abc3090b253010 (patch) | |
tree | 96ad5463d81ce5452c54b172214f3715fd29ab0b /src/util/test_common_logging_dummy.c | |
parent | 09ba4f230cd95676753a791c30db18489dca5c49 (diff) | |
download | gnunet-7c761db5dc34daba09b587c6b5abc3090b253010.tar.gz gnunet-7c761db5dc34daba09b587c6b5abc3090b253010.zip |
testcase for runtime loglevels form LRN
Diffstat (limited to 'src/util/test_common_logging_dummy.c')
-rw-r--r-- | src/util/test_common_logging_dummy.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/util/test_common_logging_dummy.c b/src/util/test_common_logging_dummy.c new file mode 100644 index 000000000..64d164a13 --- /dev/null +++ b/src/util/test_common_logging_dummy.c | |||
@@ -0,0 +1,92 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2008 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 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 | #include "platform.h" | ||
28 | #include "gnunet_common.h" | ||
29 | #include "gnunet_time_lib.h" | ||
30 | #include "gnunet_network_lib.h" | ||
31 | |||
32 | #define MS200 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 200) | ||
33 | |||
34 | static void | ||
35 | my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component, | ||
36 | const char *date, const char *msg) | ||
37 | { | ||
38 | if (strncmp ("test-common-logging-dummy", component, 25) != 0) | ||
39 | return; | ||
40 | fprintf (stdout, "%s", msg); | ||
41 | fflush (stdout); | ||
42 | } | ||
43 | |||
44 | static int | ||
45 | expensive_func () | ||
46 | { | ||
47 | return GNUNET_NETWORK_socket_select (NULL, NULL, NULL, MS200); | ||
48 | } | ||
49 | |||
50 | #define pr(kind,lvl) {\ | ||
51 | struct GNUNET_TIME_Absolute t1, t2;\ | ||
52 | t1 = GNUNET_TIME_absolute_get ();\ | ||
53 | GNUNET_log (kind, "L%s %d\n", lvl, expensive_func());\ | ||
54 | t2 = GNUNET_TIME_absolute_get ();\ | ||
55 | printf ("1%s %llu\n", lvl,\ | ||
56 | (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2).rel_value); \ | ||
57 | } | ||
58 | |||
59 | #define pr2(kind,lvl) {\ | ||
60 | struct GNUNET_TIME_Absolute t1, t2;\ | ||
61 | t1 = GNUNET_TIME_absolute_get ();\ | ||
62 | GNUNET_log (kind, "L%s %d\n", lvl, expensive_func());\ | ||
63 | t2 = GNUNET_TIME_absolute_get ();\ | ||
64 | printf ("2%s %llu\n", lvl,\ | ||
65 | (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2).rel_value); \ | ||
66 | } | ||
67 | |||
68 | int | ||
69 | main (int argc, char *argv[]) | ||
70 | { | ||
71 | /* We set up logging with NULL level - will be overrided by | ||
72 | * GNUNET_LOG or GNUNET_FORCE_LOG at runtime. | ||
73 | */ | ||
74 | GNUNET_log_setup ("test-common-logging-dummy", NULL, "/dev/null"); | ||
75 | GNUNET_logger_add (&my_log, NULL); | ||
76 | pr (GNUNET_ERROR_TYPE_ERROR, "ERROR"); | ||
77 | pr (GNUNET_ERROR_TYPE_WARNING, "WARNING"); | ||
78 | pr (GNUNET_ERROR_TYPE_INFO, "INFO"); | ||
79 | pr (GNUNET_ERROR_TYPE_DEBUG, "DEBUG"); | ||
80 | |||
81 | /* We set up logging with WARNING level - will onle be overrided by | ||
82 | * GNUNET_FORCE_LOG at runtime. | ||
83 | */ | ||
84 | GNUNET_log_setup ("test-common-logging-dummy", "WARNING", "/dev/null"); | ||
85 | pr2 (GNUNET_ERROR_TYPE_ERROR, "ERROR"); | ||
86 | pr2 (GNUNET_ERROR_TYPE_WARNING, "WARNING"); | ||
87 | pr2 (GNUNET_ERROR_TYPE_INFO, "INFO"); | ||
88 | pr2 (GNUNET_ERROR_TYPE_DEBUG, "DEBUG"); | ||
89 | return 0; | ||
90 | } /* end of main */ | ||
91 | |||
92 | /* end of test_common_logging_dummy.c */ | ||