aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/auditor-lib/Makefile.am1
-rw-r--r--src/auditor-lib/test_auditor_api.c6
-rw-r--r--src/auditor-lib/testing_auditor_api_helpers.c187
-rw-r--r--src/exchange-lib/testing_api_loop.c62
-rw-r--r--src/include/taler_testing_auditor_lib.h18
-rw-r--r--src/include/taler_testing_lib.h28
6 files changed, 275 insertions, 27 deletions
diff --git a/src/auditor-lib/Makefile.am b/src/auditor-lib/Makefile.am
index c0323b250..4589bc975 100644
--- a/src/auditor-lib/Makefile.am
+++ b/src/auditor-lib/Makefile.am
@@ -40,6 +40,7 @@ libtalerauditortesting_la_LDFLAGS = \
-version-info 0:0:0 \
-no-undefined
libtalerauditortesting_la_SOURCES = \
+ testing_auditor_api_helpers.c \
testing_auditor_api_cmd_exec_auditor.c \
testing_auditor_api_cmd_exec_wire_auditor.c
libtalerauditortesting_la_LIBADD = \
diff --git a/src/auditor-lib/test_auditor_api.c b/src/auditor-lib/test_auditor_api.c
index 56f7cd01a..6393ce351 100644
--- a/src/auditor-lib/test_auditor_api.c
+++ b/src/auditor-lib/test_auditor_api.c
@@ -185,9 +185,9 @@ main (int argc,
* start/stop the exchange. It calls TALER_TESTING_setup
* which creates the 'is' object.
*/
- TALER_TESTING_setup_with_auditor_and_exchange (&run,
- NULL,
- CONFIG_FILE))
+ TALER_TESTING_AUDITOR_setup (&run,
+ NULL,
+ CONFIG_FILE))
return 1;
break;
default:
diff --git a/src/auditor-lib/testing_auditor_api_helpers.c b/src/auditor-lib/testing_auditor_api_helpers.c
new file mode 100644
index 000000000..a87fe9d00
--- /dev/null
+++ b/src/auditor-lib/testing_auditor_api_helpers.c
@@ -0,0 +1,187 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2018 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file auditor-lib/testing_auditor_api_helpers.c
+ * @brief helper functions
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+#include "taler_testing_auditor_lib.h"
+#include "taler_auditor_service.h"
+
+
+/**
+ * Closure for #cleanup_auditor.
+ */
+struct CleanupContext
+{
+ /**
+ * Where we find the state to clean up.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Next cleanup routine to call, NULL for none.
+ */
+ GNUNET_SCHEDULER_TaskCallback fcb;
+
+ /**
+ * Closure for @e fcb
+ */
+ void *fcb_cls;
+};
+
+
+/**
+ * Function to clean up the auditor connection.
+ *
+ * @param cls a `struct CleanupContext`
+ */
+static void
+cleanup_auditor (void *cls)
+{
+ struct CleanupContext *cc = cls;
+ struct TALER_TESTING_Interpreter *is = cc->is;
+
+ TALER_AUDITOR_disconnect (is->auditor);
+ is->auditor = NULL;
+ if (NULL != cc->fcb)
+ cc->fcb (cc->fcb_cls);
+ GNUNET_free (cc);
+}
+
+
+
+/**
+ * Function called with information about the auditor.
+ *
+ * @param cls closure
+ * @param vi basic information about the auditor
+ * @param compat protocol compatibility information
+ */
+static void
+auditor_version_cb (void *cls,
+ const struct TALER_AUDITOR_VersionInformation *vi,
+ enum TALER_AUDITOR_VersionCompatibility compat)
+{
+ struct TALER_TESTING_Interpreter *is = cls;
+
+ /* TODO: check vi/compat? */
+ is->auditor_working = GNUNET_YES;
+}
+
+
+
+/**
+ * Closure for #auditor_main_wrapper()
+ */
+struct MainWrapperContext
+{
+ /**
+ * Main function to launch.
+ */
+ TALER_TESTING_Main main_cb;
+
+ /**
+ * Closure for @e main_cb.
+ */
+ void *main_cb_cls;
+
+};
+
+
+/**
+ * Setup the @a is 'auditor' member before running the main test loop.
+ *
+ * @param cls must be a `struct MainWrapperContext *`
+ * @param is[in,out] interpreter state to setup
+ */
+static void
+auditor_main_wrapper (void *cls,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct MainWrapperContext *mwc = cls;
+ struct CleanupContext *cc;
+ char *auditor_base_url;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (is->cfg,
+ "auditor",
+ "BASE_URL",
+ &auditor_base_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "auditor",
+ "BASE_URL");
+ return;
+ }
+ is->auditor = TALER_AUDITOR_connect (is->ctx,
+ auditor_base_url,
+ &auditor_version_cb,
+ is);
+ GNUNET_free (auditor_base_url);
+ if (NULL == is->auditor)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ cc = GNUNET_new (struct CleanupContext);
+ cc->is = is;
+ cc->fcb = is->final_cleanup_cb;
+ cc->fcb_cls = is->final_cleanup_cb;
+ is->final_cleanup_cb = &cleanup_auditor;
+ is->final_cleanup_cb_cls = cc;
+ mwc->main_cb (mwc->main_cb_cls,
+ is);
+}
+
+
+/**
+ * Install signal handlers plus schedules the main wrapper
+ * around the "run" method.
+ *
+ * @param main_cb the "run" method which contains all the
+ * commands.
+ * @param main_cb_cls a closure for "run", typically NULL.
+ * @param config_filename configuration filename.
+ * @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
+ * non-GNUNET_OK codes are #GNUNET_SYSERR most of the
+ * times.
+ */
+int
+TALER_TESTING_AUDITOR_setup (TALER_TESTING_Main main_cb,
+ void *main_cb_cls,
+ const char *config_filename)
+{
+ struct MainWrapperContext mwc = {
+ .main_cb = main_cb,
+ .main_cb_cls = main_cb_cls
+ };
+
+ return TALER_TESTING_setup_with_auditor_and_exchange (&auditor_main_wrapper,
+ &mwc,
+ config_filename);
+}
+
+
+/* end of testing_auditor_api_helpers.c */
diff --git a/src/exchange-lib/testing_api_loop.c b/src/exchange-lib/testing_api_loop.c
index 52bf9173b..67b9a7a7d 100644
--- a/src/exchange-lib/testing_api_loop.c
+++ b/src/exchange-lib/testing_api_loop.c
@@ -675,23 +675,17 @@ do_abort (void *cls)
* Initialize scheduler loop and curl context for the testcase,
* and responsible to run the "run" method.
*
- * @param cls closure, typically the "run" method, the
- * interpreter state and a closure for "run".
+ * @param cls a `struct MainContext *`
+ * @param cfg configuration to use
*/
-static void
-main_wrapper_exchange_connect (void *cls)
+static int
+main_exchange_connect_with_cfg (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct MainContext *main_ctx = cls;
struct TALER_TESTING_Interpreter *is = main_ctx->is;
- struct GNUNET_CONFIGURATION_Handle *cfg;
char *exchange_url;
- cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_load (cfg,
- main_ctx->config_filename))
- return;
-
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"exchange",
@@ -701,19 +695,38 @@ main_wrapper_exchange_connect (void *cls)
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"exchange",
"BASE_URL");
- GNUNET_CONFIGURATION_destroy (cfg);
- return;
+ return GNUNET_SYSERR;
}
main_ctx->exchange_url = exchange_url;
+ is->cfg = cfg;
is->timeout_task = GNUNET_SCHEDULER_add_shutdown (&do_abort,
main_ctx);
- GNUNET_assert (NULL !=
- (is->exchange = TALER_EXCHANGE_connect (is->ctx,
- exchange_url,
- &cert_cb,
- main_ctx,
- TALER_EXCHANGE_OPTION_END)));
- GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_break (NULL !=
+ (is->exchange = TALER_EXCHANGE_connect (is->ctx,
+ exchange_url,
+ &cert_cb,
+ main_ctx,
+ TALER_EXCHANGE_OPTION_END)));
+ is->cfg = NULL;
+ return GNUNET_OK;
+}
+
+
+/**
+ * Initialize scheduler loop and curl context for the testcase,
+ * and responsible to run the "run" method.
+ *
+ * @param cls a `struct MainContext *`
+ */
+static void
+main_wrapper_exchange_connect (void *cls)
+{
+ struct MainContext *main_ctx = cls;
+
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONFIGURATION_parse_and_run (main_ctx->config_filename,
+ &main_exchange_connect_with_cfg,
+ main_ctx));
}
@@ -721,7 +734,7 @@ main_wrapper_exchange_connect (void *cls)
* Install signal handlers plus schedules the main wrapper
* around the "run" method.
*
- * @param main_cb the "run" method which coontains all the
+ * @param main_cb the "run" method which contains all the
* commands.
* @param main_cb_cls a closure for "run", typically NULL.
* @param config_filename configuration filename.
@@ -730,8 +743,8 @@ main_wrapper_exchange_connect (void *cls)
* signal to it, for example to let it know to reload the
* key state.. if NULL, the interpreter will run without
* trying to connect to the exchange first.
- * @param exchange_connect GNUNET_YES if the test should connect
- * to the exchange, GNUNET_NO otherwise
+ * @param exchange_connect #GNUNET_YES if the test should connect
+ * to the exchange, #GNUNET_NO otherwise
* @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
* non-GNUNET_OK codes are #GNUNET_SYSERR most of the
* times.
@@ -779,11 +792,12 @@ TALER_TESTING_setup (TALER_TESTING_Main main_cb,
else
GNUNET_SCHEDULER_run (&main_wrapper_exchange_agnostic,
&main_ctx);
+ if (NULL != is.final_cleanup_cb)
+ is.final_cleanup_cb (is.final_cleanup_cb_cls);
GNUNET_free_non_null (main_ctx.exchange_url);
GNUNET_SIGNAL_handler_uninstall (shc_chld);
GNUNET_DISK_pipe_close (sigpipe);
sigpipe = NULL;
-
return is.result;
}
diff --git a/src/include/taler_testing_auditor_lib.h b/src/include/taler_testing_auditor_lib.h
index 2a11b74cb..554fadf5c 100644
--- a/src/include/taler_testing_auditor_lib.h
+++ b/src/include/taler_testing_auditor_lib.h
@@ -36,4 +36,22 @@
/* ********************* Helper functions ********************* */
+/**
+ * Install signal handlers plus schedules the main wrapper
+ * around the "run" method.
+ *
+ * @param main_cb the "run" method which contains all the
+ * commands.
+ * @param main_cb_cls a closure for "run", typically NULL.
+ * @param config_filename configuration filename.
+ * @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
+ * non-GNUNET_OK codes are #GNUNET_SYSERR most of the
+ * times.
+ */
+int
+TALER_TESTING_AUDITOR_setup (TALER_TESTING_Main main_cb,
+ void *main_cb_cls,
+ const char *config_filename);
+
+
#endif
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index cbc28f535..9ea10f7e7 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -281,6 +281,11 @@ struct TALER_TESTING_Interpreter
struct GNUNET_CURL_Context *ctx;
/**
+ * Our configuration.
+ */
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
* Context for running the CURL event loop.
*/
struct GNUNET_CURL_RescheduleContext *rc;
@@ -297,6 +302,16 @@ struct TALER_TESTING_Interpreter
struct GNUNET_SCHEDULER_Task *timeout_task;
/**
+ * Function to call for cleanup at the end. Can be NULL.
+ */
+ GNUNET_SCHEDULER_TaskCallback final_cleanup_cb;
+
+ /**
+ * Closure for #final_cleanup_cb().
+ */
+ void *final_cleanup_cb_cls;
+
+ /**
* Instruction pointer. Tells #interpreter_run() which
* instruction to run next. Need (signed) int because
* it gets -1 when rewinding the interpreter to the first
@@ -315,6 +330,13 @@ struct TALER_TESTING_Interpreter
struct TALER_EXCHANGE_Handle *exchange;
/**
+ * Handle to the auditor. NULL unless specifically initialized
+ * as part of libtalertestingauditor's
+ * #TALER_TESTING_AUDITOR_main_wrapper().
+ */
+ struct TALER_AUDITOR_Handle *auditor;
+
+ /**
* Handle to exchange process; some commands need it
* to send signals. E.g. to trigger the key state reload.
*/
@@ -334,6 +356,12 @@ struct TALER_TESTING_Interpreter
int working;
/**
+ * Is the auditor running (#GNUNET_YES) or waiting
+ * for /version (#GNUNET_NO)?
+ */
+ int auditor_working;
+
+ /**
* How often have we gotten a /keys response so far?
*/
unsigned int key_generation;