extend testing logic to setup handle for the auditor
This commit is contained in:
parent
4885b899c7
commit
17edb09f38
@ -40,6 +40,7 @@ libtalerauditortesting_la_LDFLAGS = \
|
|||||||
-version-info 0:0:0 \
|
-version-info 0:0:0 \
|
||||||
-no-undefined
|
-no-undefined
|
||||||
libtalerauditortesting_la_SOURCES = \
|
libtalerauditortesting_la_SOURCES = \
|
||||||
|
testing_auditor_api_helpers.c \
|
||||||
testing_auditor_api_cmd_exec_auditor.c \
|
testing_auditor_api_cmd_exec_auditor.c \
|
||||||
testing_auditor_api_cmd_exec_wire_auditor.c
|
testing_auditor_api_cmd_exec_wire_auditor.c
|
||||||
libtalerauditortesting_la_LIBADD = \
|
libtalerauditortesting_la_LIBADD = \
|
||||||
|
@ -185,7 +185,7 @@ main (int argc,
|
|||||||
* start/stop the exchange. It calls TALER_TESTING_setup
|
* start/stop the exchange. It calls TALER_TESTING_setup
|
||||||
* which creates the 'is' object.
|
* which creates the 'is' object.
|
||||||
*/
|
*/
|
||||||
TALER_TESTING_setup_with_auditor_and_exchange (&run,
|
TALER_TESTING_AUDITOR_setup (&run,
|
||||||
NULL,
|
NULL,
|
||||||
CONFIG_FILE))
|
CONFIG_FILE))
|
||||||
return 1;
|
return 1;
|
||||||
|
187
src/auditor-lib/testing_auditor_api_helpers.c
Normal file
187
src/auditor-lib/testing_auditor_api_helpers.c
Normal file
@ -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 */
|
@ -675,23 +675,17 @@ do_abort (void *cls)
|
|||||||
* Initialize scheduler loop and curl context for the testcase,
|
* Initialize scheduler loop and curl context for the testcase,
|
||||||
* and responsible to run the "run" method.
|
* and responsible to run the "run" method.
|
||||||
*
|
*
|
||||||
* @param cls closure, typically the "run" method, the
|
* @param cls a `struct MainContext *`
|
||||||
* interpreter state and a closure for "run".
|
* @param cfg configuration to use
|
||||||
*/
|
*/
|
||||||
static void
|
static int
|
||||||
main_wrapper_exchange_connect (void *cls)
|
main_exchange_connect_with_cfg (void *cls,
|
||||||
|
const struct GNUNET_CONFIGURATION_Handle *cfg)
|
||||||
{
|
{
|
||||||
struct MainContext *main_ctx = cls;
|
struct MainContext *main_ctx = cls;
|
||||||
struct TALER_TESTING_Interpreter *is = main_ctx->is;
|
struct TALER_TESTING_Interpreter *is = main_ctx->is;
|
||||||
struct GNUNET_CONFIGURATION_Handle *cfg;
|
|
||||||
char *exchange_url;
|
char *exchange_url;
|
||||||
|
|
||||||
cfg = GNUNET_CONFIGURATION_create ();
|
|
||||||
if (GNUNET_OK !=
|
|
||||||
GNUNET_CONFIGURATION_load (cfg,
|
|
||||||
main_ctx->config_filename))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
GNUNET_CONFIGURATION_get_value_string (cfg,
|
GNUNET_CONFIGURATION_get_value_string (cfg,
|
||||||
"exchange",
|
"exchange",
|
||||||
@ -701,19 +695,38 @@ main_wrapper_exchange_connect (void *cls)
|
|||||||
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
|
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
|
||||||
"exchange",
|
"exchange",
|
||||||
"BASE_URL");
|
"BASE_URL");
|
||||||
GNUNET_CONFIGURATION_destroy (cfg);
|
return GNUNET_SYSERR;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
main_ctx->exchange_url = exchange_url;
|
main_ctx->exchange_url = exchange_url;
|
||||||
|
is->cfg = cfg;
|
||||||
is->timeout_task = GNUNET_SCHEDULER_add_shutdown (&do_abort,
|
is->timeout_task = GNUNET_SCHEDULER_add_shutdown (&do_abort,
|
||||||
main_ctx);
|
main_ctx);
|
||||||
GNUNET_assert (NULL !=
|
GNUNET_break (NULL !=
|
||||||
(is->exchange = TALER_EXCHANGE_connect (is->ctx,
|
(is->exchange = TALER_EXCHANGE_connect (is->ctx,
|
||||||
exchange_url,
|
exchange_url,
|
||||||
&cert_cb,
|
&cert_cb,
|
||||||
main_ctx,
|
main_ctx,
|
||||||
TALER_EXCHANGE_OPTION_END)));
|
TALER_EXCHANGE_OPTION_END)));
|
||||||
GNUNET_CONFIGURATION_destroy (cfg);
|
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
|
* Install signal handlers plus schedules the main wrapper
|
||||||
* around the "run" method.
|
* 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.
|
* commands.
|
||||||
* @param main_cb_cls a closure for "run", typically NULL.
|
* @param main_cb_cls a closure for "run", typically NULL.
|
||||||
* @param config_filename configuration filename.
|
* @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
|
* signal to it, for example to let it know to reload the
|
||||||
* key state.. if NULL, the interpreter will run without
|
* key state.. if NULL, the interpreter will run without
|
||||||
* trying to connect to the exchange first.
|
* trying to connect to the exchange first.
|
||||||
* @param exchange_connect GNUNET_YES if the test should connect
|
* @param exchange_connect #GNUNET_YES if the test should connect
|
||||||
* to the exchange, GNUNET_NO otherwise
|
* to the exchange, #GNUNET_NO otherwise
|
||||||
* @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
|
* @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
|
||||||
* non-GNUNET_OK codes are #GNUNET_SYSERR most of the
|
* non-GNUNET_OK codes are #GNUNET_SYSERR most of the
|
||||||
* times.
|
* times.
|
||||||
@ -779,11 +792,12 @@ TALER_TESTING_setup (TALER_TESTING_Main main_cb,
|
|||||||
else
|
else
|
||||||
GNUNET_SCHEDULER_run (&main_wrapper_exchange_agnostic,
|
GNUNET_SCHEDULER_run (&main_wrapper_exchange_agnostic,
|
||||||
&main_ctx);
|
&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_free_non_null (main_ctx.exchange_url);
|
||||||
GNUNET_SIGNAL_handler_uninstall (shc_chld);
|
GNUNET_SIGNAL_handler_uninstall (shc_chld);
|
||||||
GNUNET_DISK_pipe_close (sigpipe);
|
GNUNET_DISK_pipe_close (sigpipe);
|
||||||
sigpipe = NULL;
|
sigpipe = NULL;
|
||||||
|
|
||||||
return is.result;
|
return is.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,4 +36,22 @@
|
|||||||
/* ********************* Helper functions ********************* */
|
/* ********************* 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
|
#endif
|
||||||
|
@ -280,6 +280,11 @@ struct TALER_TESTING_Interpreter
|
|||||||
*/
|
*/
|
||||||
struct GNUNET_CURL_Context *ctx;
|
struct GNUNET_CURL_Context *ctx;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Our configuration.
|
||||||
|
*/
|
||||||
|
const struct GNUNET_CONFIGURATION_Handle *cfg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Context for running the CURL event loop.
|
* Context for running the CURL event loop.
|
||||||
*/
|
*/
|
||||||
@ -296,6 +301,16 @@ struct TALER_TESTING_Interpreter
|
|||||||
*/
|
*/
|
||||||
struct GNUNET_SCHEDULER_Task *timeout_task;
|
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 pointer. Tells #interpreter_run() which
|
||||||
* instruction to run next. Need (signed) int because
|
* instruction to run next. Need (signed) int because
|
||||||
@ -314,6 +329,13 @@ struct TALER_TESTING_Interpreter
|
|||||||
*/
|
*/
|
||||||
struct TALER_EXCHANGE_Handle *exchange;
|
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
|
* Handle to exchange process; some commands need it
|
||||||
* to send signals. E.g. to trigger the key state reload.
|
* to send signals. E.g. to trigger the key state reload.
|
||||||
@ -333,6 +355,12 @@ struct TALER_TESTING_Interpreter
|
|||||||
*/
|
*/
|
||||||
int working;
|
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?
|
* How often have we gotten a /keys response so far?
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user