diff options
Diffstat (limited to 'src/testbed-logger/test_testbed_logger_api.c')
-rw-r--r-- | src/testbed-logger/test_testbed_logger_api.c | 228 |
1 files changed, 114 insertions, 114 deletions
diff --git a/src/testbed-logger/test_testbed_logger_api.c b/src/testbed-logger/test_testbed_logger_api.c index 11c166f25..3d228cdb1 100644 --- a/src/testbed-logger/test_testbed_logger_api.c +++ b/src/testbed-logger/test_testbed_logger_api.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -30,14 +30,14 @@ | |||
30 | /** | 30 | /** |
31 | * Generic logging shortcut | 31 | * Generic logging shortcut |
32 | */ | 32 | */ |
33 | #define LOG(kind,...) \ | 33 | #define LOG(kind, ...) \ |
34 | GNUNET_log (kind, __VA_ARGS__) | 34 | GNUNET_log(kind, __VA_ARGS__) |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Relative time seconds shorthand | 37 | * Relative time seconds shorthand |
38 | */ | 38 | */ |
39 | #define TIME_REL_SECS(sec) \ | 39 | #define TIME_REL_SECS(sec) \ |
40 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) | 40 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, sec) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Opaque handle for the logging service | 43 | * Opaque handle for the logging service |
@@ -57,23 +57,23 @@ static struct GNUNET_SCHEDULER_Task *write_task; | |||
57 | static int result; | 57 | static int result; |
58 | 58 | ||
59 | #define CANCEL_TASK(task) do { \ | 59 | #define CANCEL_TASK(task) do { \ |
60 | if (NULL != task) \ | 60 | if (NULL != task) \ |
61 | { \ | 61 | { \ |
62 | GNUNET_SCHEDULER_cancel (task); \ | 62 | GNUNET_SCHEDULER_cancel(task); \ |
63 | task = NULL; \ | 63 | task = NULL; \ |
64 | } \ | 64 | } \ |
65 | } while (0) | 65 | } while (0) |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * shortcut to exit during failure | 68 | * shortcut to exit during failure |
69 | */ | 69 | */ |
70 | #define FAIL_TEST(cond, ret) do { \ | 70 | #define FAIL_TEST(cond, ret) do { \ |
71 | if (!(cond)) { \ | 71 | if (!(cond)) { \ |
72 | GNUNET_break(0); \ | 72 | GNUNET_break(0); \ |
73 | CANCEL_TASK (abort_task); \ | 73 | CANCEL_TASK(abort_task); \ |
74 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \ | 74 | abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); \ |
75 | ret; \ | 75 | ret; \ |
76 | } \ | 76 | } \ |
77 | } while (0) | 77 | } while (0) |
78 | 78 | ||
79 | 79 | ||
@@ -84,24 +84,24 @@ static int result; | |||
84 | * @param tc the task context | 84 | * @param tc the task context |
85 | */ | 85 | */ |
86 | static void | 86 | static void |
87 | shutdown_now () | 87 | shutdown_now() |
88 | { | 88 | { |
89 | CANCEL_TASK (abort_task); | 89 | CANCEL_TASK(abort_task); |
90 | CANCEL_TASK (write_task); | 90 | CANCEL_TASK(write_task); |
91 | GNUNET_free_non_null (search_dir); | 91 | GNUNET_free_non_null(search_dir); |
92 | if (NULL != h) | 92 | if (NULL != h) |
93 | GNUNET_TESTBED_LOGGER_disconnect (h); | 93 | GNUNET_TESTBED_LOGGER_disconnect(h); |
94 | GNUNET_SCHEDULER_shutdown (); | 94 | GNUNET_SCHEDULER_shutdown(); |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
98 | static void | 98 | static void |
99 | do_abort (void *cls) | 99 | do_abort(void *cls) |
100 | { | 100 | { |
101 | LOG (GNUNET_ERROR_TYPE_WARNING, | 101 | LOG(GNUNET_ERROR_TYPE_WARNING, |
102 | "Aborting\n"); | 102 | "Aborting\n"); |
103 | abort_task = NULL; | 103 | abort_task = NULL; |
104 | shutdown_now (); | 104 | shutdown_now(); |
105 | } | 105 | } |
106 | 106 | ||
107 | 107 | ||
@@ -118,40 +118,40 @@ do_abort (void *cls) | |||
118 | * #GNUNET_SYSERR to abort iteration with error! | 118 | * #GNUNET_SYSERR to abort iteration with error! |
119 | */ | 119 | */ |
120 | static int | 120 | static int |
121 | iterator_cb (void *cls, | 121 | iterator_cb(void *cls, |
122 | const char *filename) | 122 | const char *filename) |
123 | { | 123 | { |
124 | const char *fn; | 124 | const char *fn; |
125 | size_t len; | 125 | size_t len; |
126 | uint64_t fs; | 126 | uint64_t fs; |
127 | 127 | ||
128 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 128 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
129 | "Iterator sees file %s\n", | 129 | "Iterator sees file %s\n", |
130 | filename); | 130 | filename); |
131 | len = strlen (filename); | 131 | len = strlen(filename); |
132 | fn = filename + len; | 132 | fn = filename + len; |
133 | if (0 != strcasecmp (".dat", fn - 4)) | 133 | if (0 != strcasecmp(".dat", fn - 4)) |
134 | return GNUNET_OK; | 134 | return GNUNET_OK; |
135 | if (GNUNET_OK != | 135 | if (GNUNET_OK != |
136 | GNUNET_DISK_file_size (filename, | 136 | GNUNET_DISK_file_size(filename, |
137 | &fs, | 137 | &fs, |
138 | GNUNET_NO, | 138 | GNUNET_NO, |
139 | GNUNET_YES)) | 139 | GNUNET_YES)) |
140 | { | 140 | { |
141 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 141 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
142 | "Failed to obtain file size for file %s\n", | 142 | "Failed to obtain file size for file %s\n", |
143 | filename); | 143 | filename); |
144 | return GNUNET_SYSERR; | 144 | return GNUNET_SYSERR; |
145 | } | 145 | } |
146 | if ((BSIZE * 2) != fs) | 146 | if ((BSIZE * 2) != fs) |
147 | { | 147 | { |
148 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 148 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
149 | "Unexpected file size for file %s\n", | 149 | "Unexpected file size for file %s\n", |
150 | filename); | 150 | filename); |
151 | /* The file size should be equal to what we | 151 | /* The file size should be equal to what we |
152 | have written */ | 152 | have written */ |
153 | return GNUNET_SYSERR; | 153 | return GNUNET_SYSERR; |
154 | } | 154 | } |
155 | result = GNUNET_OK; | 155 | result = GNUNET_OK; |
156 | return GNUNET_OK; | 156 | return GNUNET_OK; |
157 | } | 157 | } |
@@ -165,52 +165,52 @@ iterator_cb (void *cls, | |||
165 | * @param size the amount of data sent | 165 | * @param size the amount of data sent |
166 | */ | 166 | */ |
167 | static void | 167 | static void |
168 | flush_comp (void *cls, | 168 | flush_comp(void *cls, |
169 | size_t size) | 169 | size_t size) |
170 | { | 170 | { |
171 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 171 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
172 | "Flush running\n"); | 172 | "Flush running\n"); |
173 | FAIL_TEST (&write_task == cls, | 173 | FAIL_TEST(&write_task == cls, |
174 | return); | 174 | return ); |
175 | FAIL_TEST ((BSIZE * 2) == size, | 175 | FAIL_TEST((BSIZE * 2) == size, |
176 | return); | 176 | return ); |
177 | FAIL_TEST (GNUNET_OK == | 177 | FAIL_TEST(GNUNET_OK == |
178 | GNUNET_TESTING_peer_stop (peer), | 178 | GNUNET_TESTING_peer_stop(peer), |
179 | return); | 179 | return ); |
180 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 180 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
181 | "Peer stopped, scanning %s\n", | 181 | "Peer stopped, scanning %s\n", |
182 | search_dir); | 182 | search_dir); |
183 | FAIL_TEST (GNUNET_SYSERR != | 183 | FAIL_TEST(GNUNET_SYSERR != |
184 | GNUNET_DISK_directory_scan (search_dir, | 184 | GNUNET_DISK_directory_scan(search_dir, |
185 | &iterator_cb, | 185 | &iterator_cb, |
186 | NULL), | 186 | NULL), |
187 | return); | 187 | return ); |
188 | shutdown_now (); | 188 | shutdown_now(); |
189 | } | 189 | } |
190 | 190 | ||
191 | 191 | ||
192 | static void | 192 | static void |
193 | do_write (void *cls) | 193 | do_write(void *cls) |
194 | { | 194 | { |
195 | static int i; | 195 | static int i; |
196 | char buf[BSIZE]; | 196 | char buf[BSIZE]; |
197 | 197 | ||
198 | write_task = NULL; | 198 | write_task = NULL; |
199 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 199 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
200 | "Write task running\n"); | 200 | "Write task running\n"); |
201 | if (0 == i) | 201 | if (0 == i) |
202 | write_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(1), | 202 | write_task = GNUNET_SCHEDULER_add_delayed(TIME_REL_SECS(1), |
203 | &do_write, | 203 | &do_write, |
204 | NULL); | 204 | NULL); |
205 | (void) memset (buf, i, BSIZE); | 205 | (void)memset(buf, i, BSIZE); |
206 | GNUNET_TESTBED_LOGGER_write (h, | 206 | GNUNET_TESTBED_LOGGER_write(h, |
207 | buf, | 207 | buf, |
208 | BSIZE); | 208 | BSIZE); |
209 | if (0 == i++) | 209 | if (0 == i++) |
210 | return; | 210 | return; |
211 | GNUNET_TESTBED_LOGGER_flush (h, | 211 | GNUNET_TESTBED_LOGGER_flush(h, |
212 | &flush_comp, | 212 | &flush_comp, |
213 | &write_task); | 213 | &write_task); |
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
@@ -223,26 +223,26 @@ do_write (void *cls) | |||
223 | * @param peer identity of the peer that was created | 223 | * @param peer identity of the peer that was created |
224 | */ | 224 | */ |
225 | static void | 225 | static void |
226 | test_main (void *cls, | 226 | test_main(void *cls, |
227 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 227 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
228 | struct GNUNET_TESTING_Peer *p) | 228 | struct GNUNET_TESTING_Peer *p) |
229 | { | 229 | { |
230 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 230 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
231 | "Connecting to logger\n"); | 231 | "Connecting to logger\n"); |
232 | FAIL_TEST (NULL != (h = GNUNET_TESTBED_LOGGER_connect (cfg)), | 232 | FAIL_TEST(NULL != (h = GNUNET_TESTBED_LOGGER_connect(cfg)), |
233 | return); | 233 | return ); |
234 | FAIL_TEST (GNUNET_OK == | 234 | FAIL_TEST(GNUNET_OK == |
235 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 235 | GNUNET_CONFIGURATION_get_value_filename(cfg, |
236 | "testbed-logger", | 236 | "testbed-logger", |
237 | "dir", | 237 | "dir", |
238 | &search_dir), | 238 | &search_dir), |
239 | return); | 239 | return ); |
240 | peer = p; | 240 | peer = p; |
241 | write_task = GNUNET_SCHEDULER_add_now (&do_write, | 241 | write_task = GNUNET_SCHEDULER_add_now(&do_write, |
242 | NULL); | 242 | NULL); |
243 | abort_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (10), | 243 | abort_task = GNUNET_SCHEDULER_add_delayed(TIME_REL_SECS(10), |
244 | &do_abort, | 244 | &do_abort, |
245 | NULL); | 245 | NULL); |
246 | } | 246 | } |
247 | 247 | ||
248 | 248 | ||
@@ -250,23 +250,23 @@ test_main (void *cls, | |||
250 | * Main function | 250 | * Main function |
251 | */ | 251 | */ |
252 | int | 252 | int |
253 | main (int argc, char **argv) | 253 | main(int argc, char **argv) |
254 | { | 254 | { |
255 | int ret; | 255 | int ret; |
256 | 256 | ||
257 | result = GNUNET_SYSERR; | 257 | result = GNUNET_SYSERR; |
258 | GNUNET_log_setup ("test-testbed-logger-api", | 258 | GNUNET_log_setup("test-testbed-logger-api", |
259 | "WARNING", | 259 | "WARNING", |
260 | NULL); | 260 | NULL); |
261 | GNUNET_break (GNUNET_OK == | 261 | GNUNET_break(GNUNET_OK == |
262 | GNUNET_DISK_directory_remove ("/tmp/test-testbed")); | 262 | GNUNET_DISK_directory_remove("/tmp/test-testbed")); |
263 | ret = GNUNET_TESTING_service_run ("test-testbed-logger", | 263 | ret = GNUNET_TESTING_service_run("test-testbed-logger", |
264 | "testbed-logger", | 264 | "testbed-logger", |
265 | "test_testbed_logger_api.conf", | 265 | "test_testbed_logger_api.conf", |
266 | &test_main, | 266 | &test_main, |
267 | NULL); | 267 | NULL); |
268 | GNUNET_break (GNUNET_OK == | 268 | GNUNET_break(GNUNET_OK == |
269 | GNUNET_DISK_directory_remove ("/tmp/test-testbed")); | 269 | GNUNET_DISK_directory_remove("/tmp/test-testbed")); |
270 | if (0 != ret) | 270 | if (0 != ret) |
271 | return 1; | 271 | return 1; |
272 | if (GNUNET_OK != result) | 272 | if (GNUNET_OK != result) |