aboutsummaryrefslogtreecommitdiff
path: root/src/lib/testing_api_loop.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/testing_api_loop.c')
-rw-r--r--src/lib/testing_api_loop.c99
1 files changed, 51 insertions, 48 deletions
diff --git a/src/lib/testing_api_loop.c b/src/lib/testing_api_loop.c
index bebd159de..38139de25 100644
--- a/src/lib/testing_api_loop.c
+++ b/src/lib/testing_api_loop.c
@@ -47,7 +47,7 @@ static struct GNUNET_DISK_PipeHandle *sigpipe;
47const struct TALER_TESTING_Command * 47const struct TALER_TESTING_Command *
48TALER_TESTING_interpreter_lookup_command 48TALER_TESTING_interpreter_lookup_command
49 (struct TALER_TESTING_Interpreter *is, 49 (struct TALER_TESTING_Interpreter *is,
50 const char *label) 50 const char *label)
51{ 51{
52 if (NULL == label) 52 if (NULL == label)
53 { 53 {
@@ -56,7 +56,7 @@ TALER_TESTING_interpreter_lookup_command
56 return NULL; 56 return NULL;
57 } 57 }
58 /* Search backwards as we most likely reference recent commands */ 58 /* Search backwards as we most likely reference recent commands */
59 for (int i=is->ip; i >= 0; i--) 59 for (int i = is->ip; i >= 0; i--)
60 { 60 {
61 const struct TALER_TESTING_Command *cmd = &is->commands[i]; 61 const struct TALER_TESTING_Command *cmd = &is->commands[i];
62 62
@@ -75,7 +75,7 @@ TALER_TESTING_interpreter_lookup_command
75 TALER_TESTING_get_trait_cmd (cmd, 75 TALER_TESTING_get_trait_cmd (cmd,
76 BATCH_INDEX, 76 BATCH_INDEX,
77 &batch)); 77 &batch));
78 for (unsigned int j=0; 78 for (unsigned int j = 0;
79 NULL != (cmd = &batch[j])->label; 79 NULL != (cmd = &batch[j])->label;
80 j++) 80 j++)
81 { 81 {
@@ -125,8 +125,8 @@ TALER_TESTING_interpreter_get_fakebank
125void 125void
126TALER_TESTING_run_with_fakebank 126TALER_TESTING_run_with_fakebank
127 (struct TALER_TESTING_Interpreter *is, 127 (struct TALER_TESTING_Interpreter *is,
128 struct TALER_TESTING_Command *commands, 128 struct TALER_TESTING_Command *commands,
129 const char *bank_url) 129 const char *bank_url)
130{ 130{
131 const char *port; 131 const char *port;
132 long pnum; 132 long pnum;
@@ -183,8 +183,9 @@ TALER_TESTING_interpreter_next (struct TALER_TESTING_Interpreter *is)
183 if (0 != ipc) 183 if (0 != ipc)
184 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 184 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
185 "Interpreter executed 1000 instructions in %s\n", 185 "Interpreter executed 1000 instructions in %s\n",
186 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (last_report), 186 GNUNET_STRINGS_relative_time_to_string (
187 GNUNET_YES)); 187 GNUNET_TIME_absolute_get_duration (last_report),
188 GNUNET_YES));
188 last_report = GNUNET_TIME_absolute_get (); 189 last_report = GNUNET_TIME_absolute_get ();
189 } 190 }
190 ipc++; 191 ipc++;
@@ -208,12 +209,12 @@ TALER_TESTING_interpreter_fail
208 "Failed at command `%s'\n", 209 "Failed at command `%s'\n",
209 cmd->label); 210 cmd->label);
210 while (TALER_TESTING_cmd_is_batch (cmd)) 211 while (TALER_TESTING_cmd_is_batch (cmd))
211 { 212 {
212 cmd = TALER_TESTING_cmd_batch_get_current (cmd); 213 cmd = TALER_TESTING_cmd_batch_get_current (cmd);
213 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 214 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
214 "Batch is at command `%s'\n", 215 "Batch is at command `%s'\n",
215 cmd->label); 216 cmd->label);
216 } 217 }
217 is->result = GNUNET_SYSERR; 218 is->result = GNUNET_SYSERR;
218 GNUNET_SCHEDULER_shutdown (); 219 GNUNET_SCHEDULER_shutdown ();
219} 220}
@@ -301,7 +302,7 @@ do_shutdown (void *cls)
301 "Executing shutdown at `%s'\n", 302 "Executing shutdown at `%s'\n",
302 label); 303 label);
303 304
304 for (unsigned int j=0; 305 for (unsigned int j = 0;
305 NULL != (cmd = &is->commands[j])->label; 306 NULL != (cmd = &is->commands[j])->label;
306 j++) 307 j++)
307 cmd->cleanup (cmd->cls, 308 cmd->cleanup (cmd->cls,
@@ -433,7 +434,7 @@ maint_child_death (void *cls)
433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
434 "Triggering key state reload at exchange\n"); 435 "Triggering key state reload at exchange\n");
435 GNUNET_break (0 == GNUNET_OS_process_kill 436 GNUNET_break (0 == GNUNET_OS_process_kill
436 (is->exchanged, SIGUSR1)); 437 (is->exchanged, SIGUSR1));
437 sleep (5); /* make sure signal was received and processed */ 438 sleep (5); /* make sure signal was received and processed */
438 } 439 }
439 } 440 }
@@ -490,16 +491,16 @@ TALER_TESTING_run2 (struct TALER_TESTING_Interpreter *is,
490 is->timeout_task = NULL; 491 is->timeout_task = NULL;
491 } 492 }
492 /* get the number of commands */ 493 /* get the number of commands */
493 for (i=0;NULL != commands[i].label;i++) ; 494 for (i = 0; NULL != commands[i].label; i++);
494 is->commands = GNUNET_new_array (i + 1, 495 is->commands = GNUNET_new_array (i + 1,
495 struct TALER_TESTING_Command); 496 struct TALER_TESTING_Command);
496 memcpy (is->commands, 497 memcpy (is->commands,
497 commands, 498 commands,
498 sizeof (struct TALER_TESTING_Command) * i); 499 sizeof (struct TALER_TESTING_Command) * i);
499 is->timeout_task = GNUNET_SCHEDULER_add_delayed 500 is->timeout_task = GNUNET_SCHEDULER_add_delayed
500 (timeout, 501 (timeout,
501 &do_timeout, 502 &do_timeout,
502 is); 503 is);
503 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, is); 504 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, is);
504 is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is); 505 is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is);
505} 506}
@@ -570,12 +571,13 @@ static void
570sighandler_child_death () 571sighandler_child_death ()
571{ 572{
572 static char c; 573 static char c;
573 int old_errno = errno; /* back-up errno */ 574 int old_errno = errno; /* back-up errno */
574 575
575 GNUNET_break (1 == GNUNET_DISK_file_write 576 GNUNET_break (1 == GNUNET_DISK_file_write
576 (GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_WRITE), 577 (GNUNET_DISK_pipe_handle (sigpipe,
577 &c, sizeof (c))); 578 GNUNET_DISK_PIPE_END_WRITE),
578 errno = old_errno; /* restore errno */ 579 &c, sizeof (c)));
580 errno = old_errno; /* restore errno */
579} 581}
580 582
581 583
@@ -591,8 +593,8 @@ sighandler_child_death ()
591void 593void
592TALER_TESTING_cert_cb 594TALER_TESTING_cert_cb
593 (void *cls, 595 (void *cls,
594 const struct TALER_EXCHANGE_Keys *keys, 596 const struct TALER_EXCHANGE_Keys *keys,
595 enum TALER_EXCHANGE_VersionCompatibility compat) 597 enum TALER_EXCHANGE_VersionCompatibility compat)
596{ 598{
597 struct MainContext *main_ctx = cls; 599 struct MainContext *main_ctx = cls;
598 struct TALER_TESTING_Interpreter *is = main_ctx->is; 600 struct TALER_TESTING_Interpreter *is = main_ctx->is;
@@ -603,23 +605,23 @@ TALER_TESTING_cert_cb
603 { 605 {
604 GNUNET_log 606 GNUNET_log
605 (GNUNET_ERROR_TYPE_WARNING, 607 (GNUNET_ERROR_TYPE_WARNING,
606 "Got NULL response for /keys" 608 "Got NULL response for /keys"
607 " during startup, retrying!\n"); 609 " during startup, retrying!\n");
608 TALER_EXCHANGE_disconnect (is->exchange); 610 TALER_EXCHANGE_disconnect (is->exchange);
609 GNUNET_assert 611 GNUNET_assert
610 (NULL != (is->exchange = TALER_EXCHANGE_connect 612 (NULL != (is->exchange = TALER_EXCHANGE_connect
611 (is->ctx, 613 (is->ctx,
612 main_ctx->exchange_url, 614 main_ctx->exchange_url,
613 &TALER_TESTING_cert_cb, 615 &TALER_TESTING_cert_cb,
614 main_ctx, 616 main_ctx,
615 TALER_EXCHANGE_OPTION_END))); 617 TALER_EXCHANGE_OPTION_END)));
616 return; 618 return;
617 } 619 }
618 else 620 else
619 GNUNET_log 621 GNUNET_log
620 (GNUNET_ERROR_TYPE_ERROR, 622 (GNUNET_ERROR_TYPE_ERROR,
621 "Got NULL response for /keys" 623 "Got NULL response for /keys"
622 " during execution!\n"); 624 " during execution!\n");
623 } 625 }
624 else 626 else
625 { 627 {
@@ -705,7 +707,7 @@ do_abort (void *cls)
705static int 707static int
706main_exchange_connect_with_cfg 708main_exchange_connect_with_cfg
707 (void *cls, 709 (void *cls,
708 const struct GNUNET_CONFIGURATION_Handle *cfg) 710 const struct GNUNET_CONFIGURATION_Handle *cfg)
709{ 711{
710 struct MainContext *main_ctx = cls; 712 struct MainContext *main_ctx = cls;
711 struct TALER_TESTING_Interpreter *is = main_ctx->is; 713 struct TALER_TESTING_Interpreter *is = main_ctx->is;
@@ -725,14 +727,14 @@ main_exchange_connect_with_cfg
725 main_ctx->exchange_url = exchange_url; 727 main_ctx->exchange_url = exchange_url;
726 is->cfg = cfg; 728 is->cfg = cfg;
727 is->timeout_task = GNUNET_SCHEDULER_add_shutdown (&do_abort, 729 is->timeout_task = GNUNET_SCHEDULER_add_shutdown (&do_abort,
728 main_ctx); 730 main_ctx);
729 GNUNET_break 731 GNUNET_break
730 (NULL != (is->exchange = TALER_EXCHANGE_connect 732 (NULL != (is->exchange = TALER_EXCHANGE_connect
731 (is->ctx, 733 (is->ctx,
732 exchange_url, 734 exchange_url,
733 &TALER_TESTING_cert_cb, 735 &TALER_TESTING_cert_cb,
734 main_ctx, 736 main_ctx,
735 TALER_EXCHANGE_OPTION_END))); 737 TALER_EXCHANGE_OPTION_END)));
736 is->cfg = NULL; 738 is->cfg = NULL;
737 return GNUNET_OK; 739 return GNUNET_OK;
738} 740}
@@ -751,7 +753,8 @@ main_wrapper_exchange_connect (void *cls)
751 753
752 GNUNET_break (GNUNET_OK == 754 GNUNET_break (GNUNET_OK ==
753 GNUNET_CONFIGURATION_parse_and_run (main_ctx->config_filename, 755 GNUNET_CONFIGURATION_parse_and_run (main_ctx->config_filename,
754 &main_exchange_connect_with_cfg, 756 &
757 main_exchange_connect_with_cfg,
755 main_ctx)); 758 main_ctx));
756} 759}
757 760
@@ -802,11 +805,11 @@ TALER_TESTING_setup (TALER_TESTING_Main main_cb,
802 GNUNET_NO, GNUNET_NO); 805 GNUNET_NO, GNUNET_NO);
803 GNUNET_assert (NULL != sigpipe); 806 GNUNET_assert (NULL != sigpipe);
804 shc_chld = GNUNET_SIGNAL_handler_install 807 shc_chld = GNUNET_SIGNAL_handler_install
805 (GNUNET_SIGCHLD, 808 (GNUNET_SIGCHLD,
806 &sighandler_child_death); 809 &sighandler_child_death);
807 is.ctx = GNUNET_CURL_init 810 is.ctx = GNUNET_CURL_init
808 (&GNUNET_CURL_gnunet_scheduler_reschedule, 811 (&GNUNET_CURL_gnunet_scheduler_reschedule,
809 &is.rc); 812 &is.rc);
810 GNUNET_CURL_enable_async_scope_header (is.ctx, "Taler-Correlation-Id"); 813 GNUNET_CURL_enable_async_scope_header (is.ctx, "Taler-Correlation-Id");
811 GNUNET_assert (NULL != is.ctx); 814 GNUNET_assert (NULL != is.ctx);
812 is.rc = GNUNET_CURL_gnunet_rc_create (is.ctx); 815 is.rc = GNUNET_CURL_gnunet_rc_create (is.ctx);
@@ -817,8 +820,8 @@ TALER_TESTING_setup (TALER_TESTING_Main main_cb,
817 GNUNET_SCHEDULER_run (&main_wrapper_exchange_connect, 820 GNUNET_SCHEDULER_run (&main_wrapper_exchange_connect,
818 &main_ctx); 821 &main_ctx);
819 else 822 else
820 GNUNET_SCHEDULER_run (&main_wrapper_exchange_agnostic, 823 GNUNET_SCHEDULER_run (&main_wrapper_exchange_agnostic,
821 &main_ctx); 824 &main_ctx);
822 if (NULL != is.final_cleanup_cb) 825 if (NULL != is.final_cleanup_cb)
823 is.final_cleanup_cb (is.final_cleanup_cb_cls); 826 is.final_cleanup_cb (is.final_cleanup_cb_cls);
824 GNUNET_free_non_null (main_ctx.exchange_url); 827 GNUNET_free_non_null (main_ctx.exchange_url);