testing_api_cmd_exec_aggregator.c (4931B)
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_aggregator.c 21 * @brief run the taler-exchange-aggregator 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 "aggregator" CMD. 33 */ 34 struct AggregatorState 35 { 36 37 /** 38 * Aggregator process. 39 */ 40 struct GNUNET_OS_Process *aggregator_proc; 41 42 /** 43 * Configuration file used by the aggregator. 44 */ 45 const char *config_filename; 46 47 /** 48 * Run with KYC restrictions on. 49 */ 50 bool kyc_on; 51 }; 52 53 54 /** 55 * Run the command. Use the `taler-exchange-aggregator' program. 56 * 57 * @param cls closure. 58 * @param cmd command being run. 59 * @param is interpreter state. 60 */ 61 static void 62 aggregator_run (void *cls, 63 const struct TALER_TESTING_Command *cmd, 64 struct TALER_TESTING_Interpreter *is) 65 { 66 struct AggregatorState *as = cls; 67 68 (void) cmd; 69 as->aggregator_proc 70 = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL, 71 NULL, NULL, NULL, 72 "taler-exchange-aggregator", 73 "taler-exchange-aggregator", 74 "-c", as->config_filename, 75 "-L", "INFO", 76 "-t", /* exit when done */ 77 (as->kyc_on) 78 ? NULL 79 : "-y", /* skip KYC */ 80 NULL); 81 if (NULL == as->aggregator_proc) 82 { 83 GNUNET_break (0); 84 TALER_TESTING_interpreter_fail (is); 85 return; 86 } 87 TALER_TESTING_wait_for_sigchld (is); 88 } 89 90 91 /** 92 * Free the state of a "aggregator" CMD, and possibly kill its 93 * process if it did not terminate correctly. 94 * 95 * @param cls closure. 96 * @param cmd the command being freed. 97 */ 98 static void 99 aggregator_cleanup (void *cls, 100 const struct TALER_TESTING_Command *cmd) 101 { 102 struct AggregatorState *as = cls; 103 104 (void) cmd; 105 if (NULL != as->aggregator_proc) 106 { 107 GNUNET_break (0 == 108 GNUNET_OS_process_kill (as->aggregator_proc, 109 SIGKILL)); 110 GNUNET_OS_process_wait (as->aggregator_proc); 111 GNUNET_OS_process_destroy (as->aggregator_proc); 112 as->aggregator_proc = NULL; 113 } 114 GNUNET_free (as); 115 } 116 117 118 /** 119 * Offer "aggregator" CMD internal data to other commands. 120 * 121 * @param cls closure. 122 * @param[out] ret result. 123 * @param trait name of the trait. 124 * @param index index number of the object to offer. 125 * @return #GNUNET_OK on success 126 */ 127 static enum GNUNET_GenericReturnValue 128 aggregator_traits (void *cls, 129 const void **ret, 130 const char *trait, 131 unsigned int index) 132 { 133 struct AggregatorState *as = cls; 134 struct TALER_TESTING_Trait traits[] = { 135 TALER_TESTING_make_trait_process (&as->aggregator_proc), 136 TALER_TESTING_trait_end () 137 }; 138 139 return TALER_TESTING_get_trait (traits, 140 ret, 141 trait, 142 index); 143 } 144 145 146 struct TALER_TESTING_Command 147 TALER_TESTING_cmd_exec_aggregator (const char *label, 148 const char *config_filename) 149 { 150 struct AggregatorState *as; 151 152 as = GNUNET_new (struct AggregatorState); 153 as->config_filename = config_filename; 154 { 155 struct TALER_TESTING_Command cmd = { 156 .cls = as, 157 .label = label, 158 .run = &aggregator_run, 159 .cleanup = &aggregator_cleanup, 160 .traits = &aggregator_traits 161 }; 162 163 return cmd; 164 } 165 } 166 167 168 struct TALER_TESTING_Command 169 TALER_TESTING_cmd_exec_aggregator_with_kyc (const char *label, 170 const char *config_filename) 171 { 172 struct AggregatorState *as; 173 174 as = GNUNET_new (struct AggregatorState); 175 as->config_filename = config_filename; 176 as->kyc_on = true; 177 { 178 struct TALER_TESTING_Command cmd = { 179 .cls = as, 180 .label = label, 181 .run = &aggregator_run, 182 .cleanup = &aggregator_cleanup, 183 .traits = &aggregator_traits 184 }; 185 186 return cmd; 187 } 188 } 189 190 191 /* end of testing_api_cmd_exec_aggregator.c */