aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/test_statistics_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/statistics/test_statistics_api.c
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/statistics/test_statistics_api.c')
-rw-r--r--src/statistics/test_statistics_api.c89
1 files changed, 42 insertions, 47 deletions
diff --git a/src/statistics/test_statistics_api.c b/src/statistics/test_statistics_api.c
index fff2b78b7..de05d6c69 100644
--- a/src/statistics/test_statistics_api.c
+++ b/src/statistics/test_statistics_api.c
@@ -39,10 +39,8 @@ check_1 (void *cls,
39 const char *name, uint64_t value, int is_persistent) 39 const char *name, uint64_t value, int is_persistent)
40{ 40{
41 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 41 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
42 "Received value %llu for `%s:%s\n", 42 "Received value %llu for `%s:%s\n",
43 (unsigned long long) value, 43 (unsigned long long) value, subsystem, name);
44 subsystem,
45 name);
46 GNUNET_assert (0 == strcmp (name, "test-1")); 44 GNUNET_assert (0 == strcmp (name, "test-1"));
47 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); 45 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
48 GNUNET_assert (value == 1); 46 GNUNET_assert (value == 1);
@@ -56,10 +54,8 @@ check_2 (void *cls,
56 const char *name, uint64_t value, int is_persistent) 54 const char *name, uint64_t value, int is_persistent)
57{ 55{
58 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
59 "Received value %llu for `%s:%s\n", 57 "Received value %llu for `%s:%s\n",
60 (unsigned long long) value, 58 (unsigned long long) value, subsystem, name);
61 subsystem,
62 name);
63 GNUNET_assert (0 == strcmp (name, "test-2")); 59 GNUNET_assert (0 == strcmp (name, "test-2"));
64 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); 60 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
65 GNUNET_assert (value == 2); 61 GNUNET_assert (value == 2);
@@ -73,10 +69,8 @@ check_3 (void *cls,
73 const char *name, uint64_t value, int is_persistent) 69 const char *name, uint64_t value, int is_persistent)
74{ 70{
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 71 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
76 "Received value %llu for `%s:%s\n", 72 "Received value %llu for `%s:%s\n",
77 (unsigned long long) value, 73 (unsigned long long) value, subsystem, name);
78 subsystem,
79 name);
80 GNUNET_assert (0 == strcmp (name, "test-3")); 74 GNUNET_assert (0 == strcmp (name, "test-3"));
81 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); 75 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
82 GNUNET_assert (value == 3); 76 GNUNET_assert (value == 3);
@@ -100,54 +94,54 @@ static void
100next (void *cls, int success) 94next (void *cls, int success)
101{ 95{
102 GNUNET_assert (success == GNUNET_OK); 96 GNUNET_assert (success == GNUNET_OK);
103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n");
104 "Issuing GET request\n");
105 GNUNET_break (NULL != 98 GNUNET_break (NULL !=
106 GNUNET_STATISTICS_get (h, NULL, "test-2", 99 GNUNET_STATISTICS_get (h, NULL, "test-2",
107 GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, cls)); 100 GNUNET_TIME_UNIT_SECONDS, &next_fin,
101 &check_2, cls));
108} 102}
109 103
110static void 104static void
111run (void *cls, 105run (void *cls,
112 char *const *args, 106 char *const *args,
113 const char *cfgfile, 107 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
114 const struct GNUNET_CONFIGURATION_Handle *cfg)
115{ 108{
116 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); 109 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
117 GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO); 110 GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO);
118 GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO); 111 GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO);
119 GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO); 112 GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO);
120 GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES); 113 GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES);
121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n");
122 "Issuing GET request\n"); 115 GNUNET_break (NULL !=
123 GNUNET_break (NULL != 116 GNUNET_STATISTICS_get (h, NULL, "test-1",
124 GNUNET_STATISTICS_get (h, NULL, "test-1", 117 GNUNET_TIME_UNIT_SECONDS, &next,
125 GNUNET_TIME_UNIT_SECONDS, &next, &check_1, cls)); 118 &check_1, cls));
126} 119}
127 120
128static void 121static void
129run_more (void *cls, 122run_more (void *cls,
130 char *const *args, 123 char *const *args,
131 const char *cfgfile, 124 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
132 const struct GNUNET_CONFIGURATION_Handle *cfg)
133{ 125{
134 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); 126 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
135 GNUNET_break (NULL != 127 GNUNET_break (NULL !=
136 GNUNET_STATISTICS_get (h, NULL, "test-3", 128 GNUNET_STATISTICS_get (h, NULL, "test-3",
137 GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_3, cls)); 129 GNUNET_TIME_UNIT_SECONDS, &next_fin,
130 &check_3, cls));
138} 131}
139 132
140static int 133static int
141check () 134check ()
142{ 135{
143 int ok = 1; 136 int ok = 1;
137
144 char *const argv[] = { "test-statistics-api", 138 char *const argv[] = { "test-statistics-api",
145 "-c", 139 "-c",
146 "test_statistics_api_data.conf", 140 "test_statistics_api_data.conf",
147#if DEBUG_STATISTICS 141#if DEBUG_STATISTICS
148 "-L", "DEBUG", 142 "-L", "DEBUG",
149#else 143#else
150 "-L", "WARNING", 144 "-L", "WARNING",
151#endif 145#endif
152 NULL 146 NULL
153 }; 147 };
@@ -156,22 +150,23 @@ check ()
156 }; 150 };
157#if START_SERVICE 151#if START_SERVICE
158 struct GNUNET_OS_Process *proc; 152 struct GNUNET_OS_Process *proc;
153
159 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", 154 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
160 "gnunet-service-statistics", 155 "gnunet-service-statistics",
161#if DEBUG_STATISTICS 156#if DEBUG_STATISTICS
162 "-L", "DEBUG", 157 "-L", "DEBUG",
163#endif 158#endif
164 "-c", "test_statistics_api_data.conf", NULL); 159 "-c", "test_statistics_api_data.conf", NULL);
165#endif 160#endif
166 GNUNET_assert (NULL != proc); 161 GNUNET_assert (NULL != proc);
167 GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", 162 GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp",
168 options, &run, &ok); 163 options, &run, &ok);
169#if START_SERVICE 164#if START_SERVICE
170 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 165 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
171 { 166 {
172 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 167 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
173 ok = 1; 168 ok = 1;
174 } 169 }
175 GNUNET_OS_process_wait (proc); 170 GNUNET_OS_process_wait (proc);
176 GNUNET_OS_process_close (proc); 171 GNUNET_OS_process_close (proc);
177 proc = NULL; 172 proc = NULL;
@@ -182,20 +177,20 @@ check ()
182#if START_SERVICE 177#if START_SERVICE
183 /* restart to check persistence! */ 178 /* restart to check persistence! */
184 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", 179 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
185 "gnunet-service-statistics", 180 "gnunet-service-statistics",
186#if DEBUG_STATISTICS 181#if DEBUG_STATISTICS
187 "-L", "DEBUG", 182 "-L", "DEBUG",
188#endif 183#endif
189 "-c", "test_statistics_api_data.conf", NULL); 184 "-c", "test_statistics_api_data.conf", NULL);
190#endif 185#endif
191 GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", 186 GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp",
192 options, &run_more, &ok); 187 options, &run_more, &ok);
193#if START_SERVICE 188#if START_SERVICE
194 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 189 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
195 { 190 {
196 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 191 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
197 ok = 1; 192 ok = 1;
198 } 193 }
199 GNUNET_OS_process_wait (proc); 194 GNUNET_OS_process_wait (proc);
200 GNUNET_OS_process_close (proc); 195 GNUNET_OS_process_close (proc);
201 proc = NULL; 196 proc = NULL;
@@ -208,13 +203,13 @@ main (int argc, char *argv[])
208{ 203{
209 int ret; 204 int ret;
210 205
211 GNUNET_log_setup ("test_statistics_api", 206 GNUNET_log_setup ("test_statistics_api",
212#if DEBUG_STATISTICS 207#if DEBUG_STATISTICS
213 "DEBUG", 208 "DEBUG",
214#else 209#else
215 "WARNING", 210 "WARNING",
216#endif 211#endif
217 NULL); 212 NULL);
218 ret = check (); 213 ret = check ();
219 214
220 return ret; 215 return ret;