diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/taler_testing_lib.h | 38 | ||||
-rw-r--r-- | src/testing/Makefile.am | 6 | ||||
-rw-r--r-- | src/testing/test_auditor_api.c | 6 | ||||
-rw-r--r-- | src/testing/test_exchange_api.c | 20 | ||||
-rw-r--r-- | src/testing/test_taler_exchange_aggregator.c | 97 | ||||
-rw-r--r-- | src/testing/test_taler_exchange_wirewatch.c | 22 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_exec_closer.c | 166 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_exec_transfer.c | 166 |
8 files changed, 453 insertions, 68 deletions
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h index 7dadc1f47..62f0b95c7 100644 --- a/src/include/taler_testing_lib.h +++ b/src/include/taler_testing_lib.h @@ -1100,32 +1100,57 @@ TALER_TESTING_cmd_exec_wirewatch (const char *label, * @param label command label. * @param config_filename configuration file for the * aggregator to use. - * * @return the command. */ struct TALER_TESTING_Command TALER_TESTING_cmd_exec_aggregator (const char *label, const char *config_filename); + +/** + * Make a "closer" CMD. + * + * @param label command label. + * @param config_filename configuration file for the + * closer to use. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_exec_closer (const char *label, + const char *config_filename); + + +/** + * Make a "transfer" CMD. + * + * @param label command label. + * @param config_filename configuration file for the + * transfer to use. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_exec_transfer (const char *label, + const char *config_filename); + + /** * Make the "keyup" CMD. * * @param label command label. * @param config_filename configuration filename. - * * @return the command. */ struct TALER_TESTING_Command TALER_TESTING_cmd_exec_keyup (const char *label, const char *config_filename); + /** * Make the "keyup" CMD, with "--timestamp" option. * * @param label command label. * @param config_filename configuration filename. * @param now Unix timestamp representing the fake "now". - * * @return the command. */ struct TALER_TESTING_Command @@ -1161,7 +1186,6 @@ TALER_TESTING_cmd_check_keys_with_now (const char *label, * * @param label command label * @param config_filename configuration filename - * * @return the command. */ struct TALER_TESTING_Command @@ -1196,7 +1220,6 @@ TALER_TESTING_cmd_withdraw_amount (const char *label, * from; will provide reserve priv to sign the request. * @param dk denomination public key. * @param expected_response_code expected HTTP response code. - * * @return the command. */ struct TALER_TESTING_Command @@ -1228,7 +1251,6 @@ TALER_TESTING_cmd_withdraw_with_retry (struct TALER_TESTING_Command cmd); * @param expected_fee the fee the exchange should charge. * @param expected_response_code the HTTP response the exchange * should return. - * * @return the command. */ struct TALER_TESTING_Command @@ -1239,13 +1261,12 @@ TALER_TESTING_cmd_wire (const char *label, /** - * Create a "reserve status" command. + * Create a GET "reserves" command. * * @param label the command label. * @param reserve_reference reference to the reserve to check. * @param expected_balance expected balance for the reserve. * @param expected_response_code expected HTTP response code. - * * @return the command. */ struct TALER_TESTING_Command @@ -1271,7 +1292,6 @@ TALER_TESTING_cmd_status (const char *label, * @param refund_deadline refund deadline, zero means 'no refunds'. * @param amount how much is going to be deposited. * @param expected_response_code expected HTTP response code. - * * @return the command. */ struct TALER_TESTING_Command diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index e839a32b1..73f9b9ec7 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -51,9 +51,11 @@ libtalertesting_la_SOURCES = \ testing_api_cmd_check_keys.c \ testing_api_cmd_deposit.c \ testing_api_cmd_exec_aggregator.c \ - testing_api_cmd_exec_wirewatch.c \ - testing_api_cmd_exec_keyup.c \ testing_api_cmd_exec_auditor-sign.c \ + testing_api_cmd_exec_closer.c \ + testing_api_cmd_exec_keyup.c \ + testing_api_cmd_exec_transfer.c \ + testing_api_cmd_exec_wirewatch.c \ testing_api_cmd_recoup.c \ testing_api_cmd_refund.c \ testing_api_cmd_refresh.c \ diff --git a/src/testing/test_auditor_api.c b/src/testing/test_auditor_api.c index a2d7e00ab..af6f82030 100644 --- a/src/testing/test_auditor_api.c +++ b/src/testing/test_auditor_api.c @@ -64,13 +64,15 @@ static struct TALER_TESTING_BankConfiguration bc; TALER_TESTING_cmd_exec_wirewatch (label, CONFIG_FILE) /** - * Execute the taler-exchange-aggregator command with + * Execute the taler-exchange-aggregator, closer and transfer commands with * our configuration file. * * @param label label to use for the command. */ #define CMD_EXEC_AGGREGATOR(label) \ - TALER_TESTING_cmd_exec_aggregator (label, CONFIG_FILE) + TALER_TESTING_cmd_exec_aggregator (label, CONFIG_FILE), \ + TALER_TESTING_cmd_exec_closer (label, CONFIG_FILE), \ + TALER_TESTING_cmd_exec_transfer (label, CONFIG_FILE) /** * Run wire transfer of funds from some user's account to the diff --git a/src/testing/test_exchange_api.c b/src/testing/test_exchange_api.c index ba655d9b8..3f7a1aed8 100644 --- a/src/testing/test_exchange_api.c +++ b/src/testing/test_exchange_api.c @@ -65,13 +65,16 @@ static struct TALER_TESTING_BankConfiguration bc; TALER_TESTING_cmd_exec_wirewatch (label, CONFIG_FILE) /** - * Execute the taler-exchange-aggregator command with + * Execute the taler-exchange-aggregator, closer and transfer commands with * our configuration file. * * @param label label to use for the command. */ #define CMD_EXEC_AGGREGATOR(label) \ - TALER_TESTING_cmd_exec_aggregator (label, CONFIG_FILE) + TALER_TESTING_cmd_exec_aggregator (label "-aggregator", CONFIG_FILE), \ + TALER_TESTING_cmd_exec_closer (label "-closer", CONFIG_FILE), \ + TALER_TESTING_cmd_exec_transfer (label "-transfer", CONFIG_FILE) + /** * Run wire transfer of funds from some user's account to the @@ -547,7 +550,8 @@ run (void *cls, * Run transfers. This will do the transfer as refund deadline * was 0, except of course because the refund succeeded, the * transfer should no longer be done. - */CMD_EXEC_AGGREGATOR ("run-aggregator-3b"), + */// + CMD_EXEC_AGGREGATOR ("run-aggregator-3b"), /* check that aggregator didn't do anything, as expected */ TALER_TESTING_cmd_check_bank_empty ("check-refund-fast-not-run"), TALER_TESTING_cmd_end () @@ -621,8 +625,10 @@ run (void *cls, TALER_TESTING_cmd_exec_wirewatch ("short-lived-aggregation", CONFIG_FILE_EXPIRE_RESERVE_NOW), - TALER_TESTING_cmd_exec_aggregator ("close-reserves", - CONFIG_FILE_EXPIRE_RESERVE_NOW), + TALER_TESTING_cmd_exec_closer ("close-reserves", + CONFIG_FILE_EXPIRE_RESERVE_NOW), + TALER_TESTING_cmd_exec_transfer ("close-reserves-transfer", + CONFIG_FILE_EXPIRE_RESERVE_NOW), TALER_TESTING_cmd_status ("short-lived-status", "short-lived-reserve", @@ -740,8 +746,8 @@ run (void *cls, = TALER_TESTING_cmd_exec_wirewatch ("reserve-open-close-wirewatch", CONFIG_FILE_EXPIRE_RESERVE_NOW); reserve_open_close[(i * RESERVE_OPEN_CLOSE_CHUNK) + 2] - = TALER_TESTING_cmd_exec_aggregator ("reserve-open-close-aggregation", - CONFIG_FILE_EXPIRE_RESERVE_NOW); + = TALER_TESTING_cmd_exec_closer ("reserve-open-close-aggregation", + CONFIG_FILE_EXPIRE_RESERVE_NOW); reserve_open_close[(i * RESERVE_OPEN_CLOSE_CHUNK) + 3] = TALER_TESTING_cmd_status ("reserve-open-close-status", "reserve-open-close-key", diff --git a/src/testing/test_taler_exchange_aggregator.c b/src/testing/test_taler_exchange_aggregator.c index 2e8a35ce2..66cdecffa 100644 --- a/src/testing/test_taler_exchange_aggregator.c +++ b/src/testing/test_taler_exchange_aggregator.c @@ -59,6 +59,19 @@ static char *config_filename; /** + * Execute the taler-exchange-aggregator, closer and transfer commands with + * our configuration file. + * + * @param label label to use for the command. + * @param cfg_fn configuration file to use + */ +#define CMD_EXEC_AGGREGATOR(label, cfg_fn) \ + TALER_TESTING_cmd_exec_aggregator (label "-aggregator", cfg_fn), \ + TALER_TESTING_cmd_exec_closer (label "-closer", cfg_fn), \ + TALER_TESTING_cmd_exec_transfer (label "-transfer", cfg_fn) + + +/** * Collects all the tests. */ static void @@ -68,8 +81,8 @@ run (void *cls, struct TALER_TESTING_Command all[] = { // check no aggregation happens on a empty database - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-on-empty-db", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-on-empty-db", + config_filename), TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-on-start"), /* check aggregation happens on the simplest case: @@ -81,8 +94,8 @@ run (void *cls, GNUNET_TIME_UNIT_ZERO, "EUR:1", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-on-deposit-1", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-on-deposit-1", + config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-1", ec.exchange_url, @@ -108,8 +121,8 @@ run (void *cls, "EUR:1", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-2", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-2", + config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-2", ec.exchange_url, @@ -140,8 +153,8 @@ run (void *cls, GNUNET_TIME_UNIT_ZERO, "EUR:1", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-3", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-3", + config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-3a", ec.exchange_url, @@ -179,15 +192,15 @@ run (void *cls, 5), "EUR:0.2", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-4-early", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-4-early", + config_filename), TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-4-fast"), TALER_TESTING_cmd_sleep ("wait (5s)", 5), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-4-delayed", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-4-delayed", + config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-4", ec.exchange_url, "EUR:0.19", @@ -214,15 +227,15 @@ run (void *cls, 5), "EUR:0.2", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-5-early", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-5-early", + config_filename), TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-5-early"), TALER_TESTING_cmd_sleep ("wait (5s)", 5), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-5-delayed", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-5-delayed", + config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-5", ec.exchange_url, "EUR:0.19", @@ -236,8 +249,8 @@ run (void *cls, GNUNET_TIME_UNIT_ZERO, "EUR:0.102", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-6a-tiny", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-6a-tiny", + config_filename), TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-6a-tiny"), TALER_TESTING_cmd_insert_deposit ("do-deposit-6b", @@ -254,8 +267,8 @@ run (void *cls, GNUNET_TIME_UNIT_ZERO, "EUR:0.102", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-6c-tiny", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-6c-tiny", + config_filename), TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-6c-tiny"), TALER_TESTING_cmd_insert_deposit ("do-deposit-6d", @@ -265,8 +278,8 @@ run (void *cls, GNUNET_TIME_UNIT_ZERO, "EUR:0.102", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-6d-tiny", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-6d-tiny", + config_filename), TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-6d-tiny"), TALER_TESTING_cmd_insert_deposit ("do-deposit-6e", @@ -276,8 +289,8 @@ run (void *cls, GNUNET_TIME_UNIT_ZERO, "EUR:0.112", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-6e", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-6e", + config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-6", ec.exchange_url, "EUR:0.01", @@ -292,8 +305,8 @@ run (void *cls, GNUNET_TIME_UNIT_ZERO, "EUR:0.109", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-7a-tiny", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-7a-tiny", + config_filename), TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-7a-tiny"), TALER_TESTING_cmd_insert_deposit ("do-deposit-7b", @@ -303,8 +316,8 @@ run (void *cls, GNUNET_TIME_UNIT_ZERO, "EUR:0.119", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-7-profit", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-7-profit", + config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-7", ec.exchange_url, "EUR:0.01", @@ -319,8 +332,8 @@ run (void *cls, GNUNET_TIME_UNIT_ZERO, "EUR:0.122", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-7-loss", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-7-loss", + config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-7", ec.exchange_url, "EUR:0.01", @@ -337,8 +350,8 @@ run (void *cls, 5), "EUR:0.109", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-8a-tiny", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-8a-tiny", + config_filename), TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-8a-tiny"), TALER_TESTING_cmd_insert_deposit ("do-deposit-8b", @@ -350,8 +363,8 @@ run (void *cls, 5), "EUR:0.109", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-8b-tiny", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-8b-tiny", + config_filename), TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-8b-tiny"), @@ -363,8 +376,8 @@ run (void *cls, GNUNET_TIME_UNIT_ZERO, "EUR:0.122", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-8", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-8", + config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-8", ec.exchange_url, "EUR:0.03", @@ -381,8 +394,8 @@ run (void *cls, 5), "EUR:0.104", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-9a-tiny", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-9a-tiny", + config_filename), TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-9a-tiny"), TALER_TESTING_cmd_insert_deposit ("do-deposit-9b", @@ -394,8 +407,8 @@ run (void *cls, 5), "EUR:0.105", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-9b-tiny", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-9b-tiny", + config_filename), TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-9b-tiny"), @@ -407,8 +420,8 @@ run (void *cls, GNUNET_TIME_UNIT_ZERO, "EUR:0.112", "EUR:0.1"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-deposit-9", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-9", + config_filename), /* 0.009 + 0.009 + 0.022 - 0.001 - 0.002 - 0.008 = 0.029 => 0.02 */ TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-9", ec.exchange_url, diff --git a/src/testing/test_taler_exchange_wirewatch.c b/src/testing/test_taler_exchange_wirewatch.c index ab3246b7e..34d70190c 100644 --- a/src/testing/test_taler_exchange_wirewatch.c +++ b/src/testing/test_taler_exchange_wirewatch.c @@ -48,6 +48,19 @@ static struct TALER_TESTING_ExchangeConfiguration ec; */ static char *config_filename; + +/** + * Execute the taler-exchange-aggregator, closer and transfer commands with + * our configuration file. + * + * @param label label to use for the command. + */ +#define CMD_EXEC_AGGREGATOR(label) \ + TALER_TESTING_cmd_exec_aggregator (label "-aggregator", config_filename), \ + TALER_TESTING_cmd_exec_closer (label "-closer", config_filename), \ + TALER_TESTING_cmd_exec_transfer (label "-transfer", config_filename) + + static struct TALER_TESTING_Command transfer_to_exchange (const char *label, const char *amount) @@ -71,8 +84,7 @@ run (void *cls, { struct TALER_TESTING_Command all[] = { TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-on-start"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-on-empty", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-on-empty"), TALER_TESTING_cmd_exec_wirewatch ("run-wirewatch-on-empty", config_filename), TALER_TESTING_cmd_check_bank_empty ("expect-transfers-empty-after-dry-run"), @@ -89,14 +101,12 @@ run (void *cls, bc.exchange_payto, // credit "run-transfer-good-to-exchange"), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-non-expired-reserve", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-non-expired-reserve"), TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-1"), TALER_TESTING_cmd_sleep ("wait (5s)", 5), - TALER_TESTING_cmd_exec_aggregator ("run-aggregator-on-expired-reserve", - config_filename), + CMD_EXEC_AGGREGATOR ("run-aggregator-on-expired-reserve"), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-1", ec.exchange_url, "EUR:4.99", diff --git a/src/testing/testing_api_cmd_exec_closer.c b/src/testing/testing_api_cmd_exec_closer.c new file mode 100644 index 000000000..d40c563c2 --- /dev/null +++ b/src/testing/testing_api_cmd_exec_closer.c @@ -0,0 +1,166 @@ +/* + 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 testing/testing_api_cmd_exec_closer.c + * @brief run the taler-exchange-closer command + * @author Marcello Stanisci + */ +#include "platform.h" +#include "taler_json_lib.h" +#include <gnunet/gnunet_curl_lib.h> +#include "taler_signatures.h" +#include "taler_testing_lib.h" + + +/** + * State for a "closer" CMD. + */ +struct CloserState +{ + + /** + * Closer process. + */ + struct GNUNET_OS_Process *closer_proc; + + /** + * Configuration file used by the closer. + */ + const char *config_filename; +}; + + +/** + * Run the command. Use the `taler-exchange-closer' program. + * + * @param cls closure. + * @param cmd command being run. + * @param is interpreter state. + */ +static void +closer_run (void *cls, + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) +{ + struct CloserState *as = cls; + + as->closer_proc + = GNUNET_OS_start_process (GNUNET_NO, + GNUNET_OS_INHERIT_STD_ALL, + NULL, NULL, NULL, + "taler-exchange-closer", + "taler-exchange-closer", + "-c", as->config_filename, + "-t", /* exit when done */ + NULL); + if (NULL == as->closer_proc) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + TALER_TESTING_wait_for_sigchld (is); +} + + +/** + * Free the state of a "closer" CMD, and possibly kill its + * process if it did not terminate correctly. + * + * @param cls closure. + * @param cmd the command being freed. + */ +static void +closer_cleanup (void *cls, + const struct TALER_TESTING_Command *cmd) +{ + struct CloserState *as = cls; + + if (NULL != as->closer_proc) + { + GNUNET_break (0 == + GNUNET_OS_process_kill (as->closer_proc, + SIGKILL)); + GNUNET_OS_process_wait (as->closer_proc); + GNUNET_OS_process_destroy (as->closer_proc); + as->closer_proc = NULL; + } + GNUNET_free (as); +} + + +/** + * Offer "closer" CMD internal data to other commands. + * + * @param cls closure. + * @param[out] ret result. + * @param trait name of the trait. + * @param index index number of the object to offer. + * @return #GNUNET_OK on success + */ +static int +closer_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + struct CloserState *as = cls; + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_process (0, &as->closer_proc), + TALER_TESTING_trait_end () + }; + + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); +} + + +/** + * Make a "closer" CMD. + * + * @param label command label. + * @param config_filename configuration file for the + * closer to use. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_exec_closer (const char *label, + const char *config_filename) +{ + struct CloserState *as; + + as = GNUNET_new (struct CloserState); + as->config_filename = config_filename; + { + struct TALER_TESTING_Command cmd = { + .cls = as, + .label = label, + .run = &closer_run, + .cleanup = &closer_cleanup, + .traits = &closer_traits + }; + + return cmd; + } +} + + +/* end of testing_api_cmd_exec_closer.c */ diff --git a/src/testing/testing_api_cmd_exec_transfer.c b/src/testing/testing_api_cmd_exec_transfer.c new file mode 100644 index 000000000..c8764f93d --- /dev/null +++ b/src/testing/testing_api_cmd_exec_transfer.c @@ -0,0 +1,166 @@ +/* + 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 testing/testing_api_cmd_exec_transfer.c + * @brief run the taler-exchange-transfer command + * @author Marcello Stanisci + */ +#include "platform.h" +#include "taler_json_lib.h" +#include <gnunet/gnunet_curl_lib.h> +#include "taler_signatures.h" +#include "taler_testing_lib.h" + + +/** + * State for a "transfer" CMD. + */ +struct TransferState +{ + + /** + * Transfer process. + */ + struct GNUNET_OS_Process *transfer_proc; + + /** + * Configuration file used by the transfer. + */ + const char *config_filename; +}; + + +/** + * Run the command. Use the `taler-exchange-transfer' program. + * + * @param cls closure. + * @param cmd command being run. + * @param is interpreter state. + */ +static void +transfer_run (void *cls, + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) +{ + struct TransferState *as = cls; + + as->transfer_proc + = GNUNET_OS_start_process (GNUNET_NO, + GNUNET_OS_INHERIT_STD_ALL, + NULL, NULL, NULL, + "taler-exchange-transfer", + "taler-exchange-transfer", + "-c", as->config_filename, + "-t", /* exit when done */ + NULL); + if (NULL == as->transfer_proc) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + TALER_TESTING_wait_for_sigchld (is); +} + + +/** + * Free the state of a "transfer" CMD, and possibly kill its + * process if it did not terminate correctly. + * + * @param cls closure. + * @param cmd the command being freed. + */ +static void +transfer_cleanup (void *cls, + const struct TALER_TESTING_Command *cmd) +{ + struct TransferState *as = cls; + + if (NULL != as->transfer_proc) + { + GNUNET_break (0 == + GNUNET_OS_process_kill (as->transfer_proc, + SIGKILL)); + GNUNET_OS_process_wait (as->transfer_proc); + GNUNET_OS_process_destroy (as->transfer_proc); + as->transfer_proc = NULL; + } + GNUNET_free (as); +} + + +/** + * Offer "transfer" CMD internal data to other commands. + * + * @param cls closure. + * @param[out] ret result. + * @param trait name of the trait. + * @param index index number of the object to offer. + * @return #GNUNET_OK on success + */ +static int +transfer_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + struct TransferState *as = cls; + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_process (0, &as->transfer_proc), + TALER_TESTING_trait_end () + }; + + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); +} + + +/** + * Make a "transfer" CMD. + * + * @param label command label. + * @param config_filename configuration file for the + * transfer to use. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_exec_transfer (const char *label, + const char *config_filename) +{ + struct TransferState *as; + + as = GNUNET_new (struct TransferState); + as->config_filename = config_filename; + { + struct TALER_TESTING_Command cmd = { + .cls = as, + .label = label, + .run = &transfer_run, + .cleanup = &transfer_cleanup, + .traits = &transfer_traits + }; + + return cmd; + } +} + + +/* end of testing_api_cmd_exec_transfer.c */ |