diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-11-11 16:45:09 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-11-11 16:45:09 +0100 |
commit | 17edb09f384689da5923689dfe4b6d071797091c (patch) | |
tree | 826f63700898dd4c939ef0a8d105c210cc60c7a5 /src/auditor-lib | |
parent | 4885b899c76d11de06cf0ac5050985698045505b (diff) |
extend testing logic to setup handle for the auditor
Diffstat (limited to 'src/auditor-lib')
-rw-r--r-- | src/auditor-lib/Makefile.am | 1 | ||||
-rw-r--r-- | src/auditor-lib/test_auditor_api.c | 6 | ||||
-rw-r--r-- | src/auditor-lib/testing_auditor_api_helpers.c | 187 |
3 files changed, 191 insertions, 3 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 */ |