From d34c6401b415edeceb205782dbcccd8b38c8e1b7 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 2 May 2016 01:30:13 +0200 Subject: fixing #4470 --- src/exchangedb/Makefile.am | 13 ++-- src/exchangedb/perf_taler_exchangedb_interpreter.c | 9 +-- src/exchangedb/perf_taler_exchangedb_interpreter.h | 20 +++--- src/exchangedb/test_exchangedb.c | 10 +-- src/exchangedb/test_exchangedb_deposits.c | 78 ++++++++++++---------- src/exchangedb/test_perf_taler_exchangedb.c | 15 +++-- 6 files changed, 82 insertions(+), 63 deletions(-) (limited to 'src/exchangedb') diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am index 83be82a23..98745ecac 100644 --- a/src/exchangedb/Makefile.am +++ b/src/exchangedb/Makefile.am @@ -56,7 +56,7 @@ libtalerexchangedb_la_LDFLAGS = \ check_PROGRAMS = \ - test-exchangedb-deposits \ + test-exchangedb-deposits-postgres \ test-exchangedb-keyio \ test-exchangedb-postgres \ test-perf-taler-exchangedb \ @@ -65,17 +65,18 @@ check_PROGRAMS = \ AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH; TESTS = \ test-exchangedb-postgres \ - test-perf-taler-exchangedb + test-perf-taler-exchangedb \ + test-exchangedb-keyio \ + test-exchangedb-deposits-postgres -test_exchangedb_deposits_SOURCES = \ +test_exchangedb_deposits_postgres_SOURCES = \ test_exchangedb_deposits.c -test_exchangedb_deposits_LDADD = \ +test_exchangedb_deposits_postgres_LDADD = \ libtalerexchangedb.la \ $(top_srcdir)/src/util/libtalerutil.la \ $(top_srcdir)/src/pq/libtalerpq.la \ -lgnunetutil \ - -ljansson \ - -lpq + -ljansson test_exchangedb_keyio_SOURCES = \ test_exchangedb_keyio.c diff --git a/src/exchangedb/perf_taler_exchangedb_interpreter.c b/src/exchangedb/perf_taler_exchangedb_interpreter.c index 78b58a5ae..897a06eed 100644 --- a/src/exchangedb/perf_taler_exchangedb_interpreter.c +++ b/src/exchangedb/perf_taler_exchangedb_interpreter.c @@ -1833,7 +1833,8 @@ PERF_TALER_EXCHANGEDB_interpret (struct TALER_EXCHANGEDB_Plugin *db_plugin, * @param init the commands to use for the database initialisation, * if #NULL the standard initialization is used * @param benchmark the commands for the benchmark - * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure + * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure, #GNUNET_NO + * if we failed to init the database */ int PERF_TALER_EXCHANGEDB_run_benchmark (const char *benchmark_name, @@ -1940,7 +1941,7 @@ PERF_TALER_EXCHANGEDB_run_benchmark (const char *benchmark_name, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error connectiong to the database\n"); - return ret; + return GNUNET_NO; } ret = plugin->create_tables (plugin->cls, GNUNET_YES); @@ -1948,7 +1949,7 @@ PERF_TALER_EXCHANGEDB_run_benchmark (const char *benchmark_name, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error while creating the database architecture\n"); - return ret; + return GNUNET_NO; } /* * Running the initialization @@ -1958,7 +1959,7 @@ PERF_TALER_EXCHANGEDB_run_benchmark (const char *benchmark_name, init = init_def; } ret = PERF_TALER_EXCHANGEDB_interpret (plugin, - init); + init); if (GNUNET_OK != ret) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, diff --git a/src/exchangedb/perf_taler_exchangedb_interpreter.h b/src/exchangedb/perf_taler_exchangedb_interpreter.h index a83251c60..1c2659dd1 100644 --- a/src/exchangedb/perf_taler_exchangedb_interpreter.h +++ b/src/exchangedb/perf_taler_exchangedb_interpreter.h @@ -467,7 +467,7 @@ /** * Get informations about a refresh session - * + * * @param _label the label of the command * @param _label_hash the label of the hash to search */ @@ -933,8 +933,8 @@ union PERF_TALER_EXCHANGEDB_CMD_Details */ const char *label_denom; unsigned int index_denom; - } insert_denomination; - + } insert_denomination; + /** * Extra data requiered by the #PERF_TALER_EXCHANGEDB_CMD_GET_DENOMINATION command */ @@ -1283,13 +1283,14 @@ struct PERF_TALER_EXCHANGEDB_Cmd * @param init the commands to use for the database initialisation, * if #NULL the standard initialization is used * @param benchmark the commands for the benchmark - * @return GNUNET_OK upon success; GNUNET_SYSERR upon failure + * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure, + * #GNUNET_NO if we failed to init the database */ int PERF_TALER_EXCHANGEDB_run_benchmark (const char *benchmark_name, - const char *configuration_file, - struct PERF_TALER_EXCHANGEDB_Cmd *init, - struct PERF_TALER_EXCHANGEDB_Cmd *benchmark); + const char *configuration_file, + struct PERF_TALER_EXCHANGEDB_Cmd *init, + struct PERF_TALER_EXCHANGEDB_Cmd *benchmark); /** @@ -1300,9 +1301,8 @@ PERF_TALER_EXCHANGEDB_run_benchmark (const char *benchmark_name, * @param cmd the commands to run */ int -PERF_TALER_EXCHANGEDB_interpret( - struct TALER_EXCHANGEDB_Plugin *db_plugin, - struct PERF_TALER_EXCHANGEDB_Cmd cmd[]); +PERF_TALER_EXCHANGEDB_interpret(struct TALER_EXCHANGEDB_Plugin *db_plugin, + struct PERF_TALER_EXCHANGEDB_Cmd cmd[]); /** diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 3bb9b9f2c..063b7b6cb 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -172,9 +172,10 @@ static struct TALER_Amount fee_refresh; static struct TALER_Amount fee_refund; static struct TALER_Amount amount_with_fee; + static void -free_refresh_commit_coins_array(struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins, - unsigned int size) +free_refresh_commit_coins_array (struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins, + unsigned int size) { unsigned int cnt; struct TALER_EXCHANGEDB_RefreshCommitCoin *ccoin; @@ -282,6 +283,7 @@ test_refresh_commit_coins (struct TALER_EXCHANGEDB_Session *session, return ret; } + /** * Function to test melting of coins as part of a refresh session * @@ -658,14 +660,14 @@ run (void *cls) if (NULL == (plugin = TALER_EXCHANGEDB_plugin_load (cfg))) { - result = 1; + result = 77; return; } if (GNUNET_OK != plugin->create_tables (plugin->cls, GNUNET_YES)) { - result = 2; + result = 77; goto drop; } if (NULL == diff --git a/src/exchangedb/test_exchangedb_deposits.c b/src/exchangedb/test_exchangedb_deposits.c index 09c65b2b2..bd1914f8a 100644 --- a/src/exchangedb/test_exchangedb_deposits.c +++ b/src/exchangedb/test_exchangedb_deposits.c @@ -19,7 +19,6 @@ * @author Sree Harsha Totakura */ #include "platform.h" -#include #include #include "taler_pq_lib.h" #include "taler_exchangedb_lib.h" @@ -43,11 +42,6 @@ } while (0) -/** - * Should we not interact with a temporary table? - */ -static int persistent; - /** * Testcase result */ @@ -58,20 +52,16 @@ static int result; */ static struct TALER_EXCHANGEDB_Plugin *plugin; + /** * Main function that will be run by the scheduler. * - * @param cls closure - * @param args remaining command-line arguments - * @param cfgfile name of the configuration file used (for saving, can be NULL!) - * @param cfg configuration + * @param cls configuration */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run (void *cls) { + const struct GNUNET_CONFIGURATION_Handle *cfg = cls; static const char wire[] = "{" "\"type\":\"SEPA\"," "\"IBAN\":\"DE67830654080004822650\"," @@ -84,11 +74,15 @@ run (void *cls, deposit = NULL; EXITIF (NULL == (plugin = TALER_EXCHANGEDB_plugin_load (cfg))); - EXITIF (GNUNET_OK != - plugin->create_tables (plugin->cls, - ! persistent)); + if (GNUNET_OK != + plugin->create_tables (plugin->cls, + GNUNET_YES)) + { + result = 77; + goto EXITIF_exit; + } session = plugin->get_session (plugin->cls, - ! persistent); + GNUNET_YES); EXITIF (NULL == session); deposit = GNUNET_malloc (sizeof (struct TALER_EXCHANGEDB_Deposit) + sizeof (wire)); /* Makeup a random coin public key */ @@ -117,7 +111,6 @@ run (void *cls, session, deposit)); result = GNUNET_OK; - EXITIF_exit: GNUNET_free_non_null (deposit); if (NULL != plugin) @@ -132,21 +125,38 @@ int main (int argc, char *const argv[]) { - static const struct GNUNET_GETOPT_CommandLineOption options[] = { - {'T', "persist", NULL, - gettext_noop ("Use a persistent database table instead of a temporary one"), - GNUNET_NO, &GNUNET_GETOPT_set_one, &persistent}, - GNUNET_GETOPT_OPTION_END - }; + const char *plugin_name; + char *config_filename; + char *testname; + struct GNUNET_CONFIGURATION_Handle *cfg; - - persistent = GNUNET_NO; - result = GNUNET_SYSERR; + result = -1; + if (NULL == (plugin_name = strrchr (argv[0], (int) '-'))) + { + GNUNET_break (0); + return -1; + } + GNUNET_log_setup (argv[0], + "WARNING", + NULL); + plugin_name++; + (void) GNUNET_asprintf (&testname, + "test-exchange-db-%s", plugin_name); + (void) GNUNET_asprintf (&config_filename, + "%s.conf", testname); + cfg = GNUNET_CONFIGURATION_create (); if (GNUNET_OK != - GNUNET_PROGRAM_run (argc, argv, - "test-exchange-deposits", - "testcase for exchange deposits", - options, &run, NULL)) - return 3; - return (GNUNET_OK == result) ? 0 : 1; + GNUNET_CONFIGURATION_parse (cfg, + config_filename)) + { + GNUNET_break (0); + GNUNET_free (config_filename); + GNUNET_free (testname); + return 2; + } + GNUNET_SCHEDULER_run (&run, cfg); + GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_free (config_filename); + GNUNET_free (testname); + return result; } diff --git a/src/exchangedb/test_perf_taler_exchangedb.c b/src/exchangedb/test_perf_taler_exchangedb.c index a4ec9591d..8f7aa55d5 100644 --- a/src/exchangedb/test_perf_taler_exchangedb.c +++ b/src/exchangedb/test_perf_taler_exchangedb.c @@ -35,6 +35,7 @@ #define NB_WITHDRAW_INIT 1 #define NB_WITHDRAW_SAVE 1 + /** * Allocate, copies and free all the data used in the interpreter * Used to check for memory leaks @@ -42,7 +43,8 @@ static void test_allocate () { - struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki, *dki_copy; + struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki; + struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki_copy; struct PERF_TALER_EXCHANGEDB_Reserve *reserve, *reserve_copy; struct PERF_TALER_EXCHANGEDB_Coin *coin, *coin_copy; struct TALER_EXCHANGEDB_Deposit *deposit, *deposit_copy; @@ -68,6 +70,7 @@ test_allocate () PERF_TALER_EXCHANGEDB_deposit_free (deposit_copy); } + /** * Runs the performances tests for the exchange database * and logs the results using Gauger @@ -170,13 +173,15 @@ main (int argc, char ** argv) // End of deposit initialization PERF_TALER_EXCHANGEDB_INIT_CMD_END ("end"), }; - + test_allocate (); ret = PERF_TALER_EXCHANGEDB_run_benchmark ("test-perf-taler-exchangedb", - "./test-exchange-db-postgres.conf", - init, - benchmark); + "./test-exchange-db-postgres.conf", + init, + benchmark); if (GNUNET_SYSERR == ret) return 1; + if (GNUNET_NO == ret) + return 77; /* testcase skipped */ return 0; } -- cgit v1.2.3