testing_api_cmd_exec_transfer.c (4168B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2018 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it 6 under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3, or (at your 8 option) any later version. 9 10 TALER is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public 16 License along with TALER; see the file COPYING. If not, 17 see <http://www.gnu.org/licenses/> 18 */ 19 /** 20 * @file testing/testing_api_cmd_exec_transfer.c 21 * @brief run the taler-exchange-transfer command 22 * @author Marcello Stanisci 23 */ 24 #include "taler/platform.h" 25 #include "taler/taler_json_lib.h" 26 #include <gnunet/gnunet_curl_lib.h> 27 #include "taler/taler_signatures.h" 28 #include "taler/taler_testing_lib.h" 29 30 31 /** 32 * State for a "transfer" CMD. 33 */ 34 struct TransferState 35 { 36 37 /** 38 * Transfer process. 39 */ 40 struct GNUNET_OS_Process *transfer_proc; 41 42 /** 43 * Configuration file used by the transfer. 44 */ 45 const char *config_filename; 46 }; 47 48 49 /** 50 * Run the command. Use the `taler-exchange-transfer' program. 51 * 52 * @param cls closure. 53 * @param cmd command being run. 54 * @param is interpreter state. 55 */ 56 static void 57 transfer_run (void *cls, 58 const struct TALER_TESTING_Command *cmd, 59 struct TALER_TESTING_Interpreter *is) 60 { 61 struct TransferState *as = cls; 62 63 (void) cmd; 64 as->transfer_proc 65 = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL, 66 NULL, NULL, NULL, 67 "taler-exchange-transfer", 68 "taler-exchange-transfer", 69 "-c", as->config_filename, 70 "-S", "1", 71 "-w", "0", 72 "-t", /* exit when done */ 73 NULL); 74 if (NULL == as->transfer_proc) 75 { 76 GNUNET_break (0); 77 TALER_TESTING_interpreter_fail (is); 78 return; 79 } 80 TALER_TESTING_wait_for_sigchld (is); 81 } 82 83 84 /** 85 * Free the state of a "transfer" CMD, and possibly kill its 86 * process if it did not terminate correctly. 87 * 88 * @param cls closure. 89 * @param cmd the command being freed. 90 */ 91 static void 92 transfer_cleanup (void *cls, 93 const struct TALER_TESTING_Command *cmd) 94 { 95 struct TransferState *as = cls; 96 97 (void) cmd; 98 if (NULL != as->transfer_proc) 99 { 100 GNUNET_break (0 == 101 GNUNET_OS_process_kill (as->transfer_proc, 102 SIGKILL)); 103 GNUNET_OS_process_wait (as->transfer_proc); 104 GNUNET_OS_process_destroy (as->transfer_proc); 105 as->transfer_proc = NULL; 106 } 107 GNUNET_free (as); 108 } 109 110 111 /** 112 * Offer "transfer" CMD internal data to other commands. 113 * 114 * @param cls closure. 115 * @param[out] ret result. 116 * @param trait name of the trait. 117 * @param index index number of the object to offer. 118 * @return #GNUNET_OK on success 119 */ 120 static enum GNUNET_GenericReturnValue 121 transfer_traits (void *cls, 122 const void **ret, 123 const char *trait, 124 unsigned int index) 125 { 126 struct TransferState *as = cls; 127 struct TALER_TESTING_Trait traits[] = { 128 TALER_TESTING_make_trait_process (&as->transfer_proc), 129 TALER_TESTING_trait_end () 130 }; 131 132 return TALER_TESTING_get_trait (traits, 133 ret, 134 trait, 135 index); 136 } 137 138 139 struct TALER_TESTING_Command 140 TALER_TESTING_cmd_exec_transfer (const char *label, 141 const char *config_filename) 142 { 143 struct TransferState *as; 144 145 as = GNUNET_new (struct TransferState); 146 as->config_filename = config_filename; 147 { 148 struct TALER_TESTING_Command cmd = { 149 .cls = as, 150 .label = label, 151 .run = &transfer_run, 152 .cleanup = &transfer_cleanup, 153 .traits = &transfer_traits 154 }; 155 156 return cmd; 157 } 158 } 159 160 161 /* end of testing_api_cmd_exec_transfer.c */