diff options
author | t3sserakt <t3ss@posteo.de> | 2021-03-15 10:45:45 +0100 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2021-03-15 10:45:45 +0100 |
commit | a550f7863bff0792c8972609869d409b77efc1dd (patch) | |
tree | 3e176423be8a3bdafb16d8891ebc3befc7fe3ffe /src/testing/testing_api_loop.c | |
parent | b47586e76bc4f3c2c4ab6829028b5dd2f03e702d (diff) | |
download | gnunet-a550f7863bff0792c8972609869d409b77efc1dd.tar.gz gnunet-a550f7863bff0792c8972609869d409b77efc1dd.zip |
- added hello world test with command style
Diffstat (limited to 'src/testing/testing_api_loop.c')
-rw-r--r-- | src/testing/testing_api_loop.c | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index 993777de6..f29329a60 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c | |||
@@ -29,17 +29,16 @@ | |||
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_testing_ng_lib.h" | 30 | #include "gnunet_testing_ng_lib.h" |
31 | 31 | ||
32 | struct GNUNET_TESTING_Interpreter *is; | ||
33 | |||
32 | /** | 34 | /** |
33 | * Lookup command by label. | 35 | * Lookup command by label. |
34 | * | 36 | * |
35 | * @param is interpreter state to search | ||
36 | * @param label label to look for | 37 | * @param label label to look for |
37 | * @return NULL if command was not found | 38 | * @return NULL if command was not found |
38 | */ | 39 | */ |
39 | const struct GNUNET_TESTING_Command * | 40 | const struct GNUNET_TESTING_Command * |
40 | GNUNET_TESTING_interpreter_lookup_command (struct | 41 | GNUNET_TESTING_interpreter_lookup_command (const char *label) |
41 | GNUNET_TESTING_Interpreter *is, | ||
42 | const char *label) | ||
43 | { | 42 | { |
44 | if (NULL == label) | 43 | if (NULL == label) |
45 | { | 44 | { |
@@ -203,7 +202,7 @@ GNUNET_TESTING_interpreter_get_current_label (struct | |||
203 | static void | 202 | static void |
204 | interpreter_run (void *cls) | 203 | interpreter_run (void *cls) |
205 | { | 204 | { |
206 | struct GNUNET_TESTING_Interpreter *is = cls; | 205 | (void) cls; |
207 | struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; | 206 | struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; |
208 | 207 | ||
209 | is->task = NULL; | 208 | is->task = NULL; |
@@ -237,10 +236,10 @@ interpreter_run (void *cls) | |||
237 | * | 236 | * |
238 | * @param cls the interpreter state. | 237 | * @param cls the interpreter state. |
239 | */ | 238 | */ |
240 | /*static void | 239 | static void |
241 | do_shutdown (void *cls) | 240 | do_shutdown (void *cls) |
242 | { | 241 | { |
243 | struct GNUNET_TESTING_Interpreter *is = cls; | 242 | (void) cls; |
244 | struct GNUNET_TESTING_Command *cmd; | 243 | struct GNUNET_TESTING_Command *cmd; |
245 | const char *label; | 244 | const char *label; |
246 | 245 | ||
@@ -269,7 +268,24 @@ do_shutdown (void *cls) | |||
269 | is->timeout_task = NULL; | 268 | is->timeout_task = NULL; |
270 | } | 269 | } |
271 | GNUNET_free (is->commands); | 270 | GNUNET_free (is->commands); |
272 | }*/ | 271 | } |
272 | |||
273 | |||
274 | /** | ||
275 | * Function run when the test terminates (good or bad) with timeout. | ||
276 | * | ||
277 | * @param cls NULL | ||
278 | */ | ||
279 | static void | ||
280 | do_timeout (void *cls) | ||
281 | { | ||
282 | (void) cls; | ||
283 | |||
284 | is->timeout_task = NULL; | ||
285 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
286 | "Terminating test due to timeout\n"); | ||
287 | GNUNET_SCHEDULER_shutdown (); | ||
288 | } | ||
273 | 289 | ||
274 | 290 | ||
275 | /** | 291 | /** |
@@ -289,17 +305,28 @@ GNUNET_TESTING_run (const char *cfg_filename, | |||
289 | { | 305 | { |
290 | unsigned int i; | 306 | unsigned int i; |
291 | 307 | ||
308 | is = GNUNET_new (struct GNUNET_TESTING_Interpreter); | ||
309 | |||
310 | if (NULL != is->timeout_task) | ||
311 | { | ||
312 | GNUNET_SCHEDULER_cancel (is->timeout_task); | ||
313 | is->timeout_task = NULL; | ||
314 | } | ||
292 | /* get the number of commands */ | 315 | /* get the number of commands */ |
293 | for (i = 0; NULL != commands[i].label; i++) | 316 | for (i = 0; NULL != commands[i].label; i++) |
294 | ; | 317 | ; |
318 | is->commands = GNUNET_new_array (i + 1, | ||
319 | struct GNUNET_TESTING_Command); | ||
320 | memcpy (is->commands, | ||
321 | commands, | ||
322 | sizeof (struct GNUNET_TESTING_Command) * i); | ||
295 | 323 | ||
296 | 324 | is->timeout_task = GNUNET_SCHEDULER_add_delayed | |
297 | /*is->timeout_task = GNUNET_SCHEDULER_add_delayed | ||
298 | (timeout, | 325 | (timeout, |
299 | &do_timeout, | 326 | &do_timeout, |
300 | is); | 327 | is); |
301 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, is); | 328 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, is); |
302 | is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is);*/ | 329 | is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is); |
303 | return GNUNET_OK; | 330 | return GNUNET_OK; |
304 | } | 331 | } |
305 | 332 | ||