aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-04-28 08:14:26 +0000
committerChristian Grothoff <christian@grothoff.org>2011-04-28 08:14:26 +0000
commit66683153d35bf38d449a3bbfd071884cf1e0b156 (patch)
treed540bbd681736607357874977c3337681a8d1ded /src
parent6a0a83057847775a0f4cb74ae5fd1e9306fd975c (diff)
downloadgnunet-66683153d35bf38d449a3bbfd071884cf1e0b156.tar.gz
gnunet-66683153d35bf38d449a3bbfd071884cf1e0b156.zip
watchtest
Diffstat (limited to 'src')
-rw-r--r--src/statistics/test_statistics_api_watch.c170
1 files changed, 170 insertions, 0 deletions
diff --git a/src/statistics/test_statistics_api_watch.c b/src/statistics/test_statistics_api_watch.c
new file mode 100644
index 000000000..0e5b7ae86
--- /dev/null
+++ b/src/statistics/test_statistics_api_watch.c
@@ -0,0 +1,170 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009, 2011 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 * @file statistics/test_statistics_api_watch.c
22 * @brief testcase for statistics_api.c watch functions
23 */
24#include "platform.h"
25#include "gnunet_common.h"
26#include "gnunet_getopt_lib.h"
27#include "gnunet_os_lib.h"
28#include "gnunet_program_lib.h"
29#include "gnunet_scheduler_lib.h"
30#include "gnunet_statistics_service.h"
31
32#define VERBOSE GNUNET_YES
33
34#define START_SERVICE GNUNET_YES
35
36#define ROUNDS (1024 * 1024)
37
38static int ok;
39
40static struct GNUNET_STATISTICS_Handle *h;
41
42static struct GNUNET_STATISTICS_Handle *h2;
43
44static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
45
46static void
47force_shutdown (void *cls,
48 const struct GNUNET_SCHEDULER_TaskContext *tc)
49{
50 fprintf (stderr, "Timeout, failed to receive notifications: %d\n", ok);
51 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
52 GNUNET_STATISTICS_destroy (h2, GNUNET_NO);
53 ok = 7;
54}
55
56static int
57watch_1 (void *cls,
58 const char *subsystem,
59 const char *name,
60 uint64_t value,
61 int is_persistent)
62{
63 fprintf (stderr, "Value `%s' seen\n", name);
64 GNUNET_assert (value == 42);
65 GNUNET_assert (0 == strcmp (name, "test-1"));
66 ok &= ~1;
67 if (0 == ok)
68 {
69 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
70 GNUNET_STATISTICS_destroy (h2, GNUNET_NO);
71 GNUNET_SCHEDULER_cancel (shutdown_task);
72 }
73 return GNUNET_OK;
74}
75
76static int
77watch_2 (void *cls,
78 const char *subsystem,
79 const char *name,
80 uint64_t value,
81 int is_persistent)
82{
83 fprintf (stderr, "Value `%s' seen\n", name);
84 GNUNET_assert (value == 43);
85 GNUNET_assert (0 == strcmp (name, "test-2"));
86 ok &= ~2;
87 if (0 == ok)
88 {
89 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
90 GNUNET_STATISTICS_destroy (h2, GNUNET_NO);
91 GNUNET_SCHEDULER_cancel (shutdown_task);
92 }
93 return GNUNET_OK;
94}
95
96static void
97run (void *cls,
98 char *const *args,
99 const char *cfgfile,
100 const struct GNUNET_CONFIGURATION_Handle *cfg)
101{
102 h = GNUNET_STATISTICS_create ("dummy", cfg);
103 GNUNET_assert (GNUNET_OK ==
104 GNUNET_STATISTICS_watch (h,
105 "test-statistics-api-watch",
106 "test-1",
107 &watch_1,
108 NULL));
109 GNUNET_assert (GNUNET_OK ==
110 GNUNET_STATISTICS_watch (h,
111 "test-statistics-api-watch",
112 "test-2",
113 &watch_2,
114 NULL));
115 h2 = GNUNET_STATISTICS_create ("test-statistics-api-watch", cfg);
116 GNUNET_STATISTICS_set (h2, "test-1", 42, GNUNET_NO);
117 GNUNET_STATISTICS_set (h2, "test-2", 43, GNUNET_NO);
118 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
119 &force_shutdown, NULL);
120}
121
122
123static int
124check ()
125{
126 char *const argv[] = { "test-statistics-api",
127 "-c",
128 "test_statistics_api_data.conf",
129 NULL
130 };
131 struct GNUNET_GETOPT_CommandLineOption options[] = {
132 GNUNET_GETOPT_OPTION_END
133 };
134#if START_SERVICE
135 struct GNUNET_OS_Process *proc;
136 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
137 "gnunet-service-statistics",
138#if VERBOSE
139 "-L", "DEBUG",
140#endif
141 "-c", "test_statistics_api_data.conf", NULL);
142#endif
143 GNUNET_assert (NULL != proc);
144 ok = 3;
145 GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp",
146 options, &run, NULL);
147#if START_SERVICE
148 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
149 {
150 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
151 ok = 1;
152 }
153 GNUNET_OS_process_wait (proc);
154 GNUNET_OS_process_close (proc);
155 proc = NULL;
156#endif
157 return ok;
158}
159
160int
161main (int argc, char *argv[])
162{
163 int ret;
164
165 ret = check ();
166
167 return ret;
168}
169
170/* end of test_statistics_api_watch.c */