LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_exec_transfer.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 20 27 74.1 %
Date: 2021-08-30 06:43:37 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "platform.h"
      25             : #include "taler_json_lib.h"
      26             : #include <gnunet/gnunet_curl_lib.h>
      27             : #include "taler_signatures.h"
      28             : #include "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          35 : transfer_run (void *cls,
      58             :               const struct TALER_TESTING_Command *cmd,
      59             :               struct TALER_TESTING_Interpreter *is)
      60             : {
      61          35 :   struct TransferState *as = cls;
      62             : 
      63             :   as->transfer_proc
      64          35 :     = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
      65             :                                NULL, NULL, NULL,
      66             :                                "taler-exchange-transfer",
      67             :                                "taler-exchange-transfer",
      68             :                                "-c", as->config_filename,
      69             :                                "-t", /* exit when done */
      70             :                                NULL);
      71          35 :   if (NULL == as->transfer_proc)
      72             :   {
      73           0 :     GNUNET_break (0);
      74           0 :     TALER_TESTING_interpreter_fail (is);
      75           0 :     return;
      76             :   }
      77          35 :   TALER_TESTING_wait_for_sigchld (is);
      78             : }
      79             : 
      80             : 
      81             : /**
      82             :  * Free the state of a "transfer" CMD, and possibly kill its
      83             :  * process if it did not terminate correctly.
      84             :  *
      85             :  * @param cls closure.
      86             :  * @param cmd the command being freed.
      87             :  */
      88             : static void
      89          35 : transfer_cleanup (void *cls,
      90             :                   const struct TALER_TESTING_Command *cmd)
      91             : {
      92          35 :   struct TransferState *as = cls;
      93             : 
      94          35 :   if (NULL != as->transfer_proc)
      95             :   {
      96           0 :     GNUNET_break (0 ==
      97             :                   GNUNET_OS_process_kill (as->transfer_proc,
      98             :                                           SIGKILL));
      99           0 :     GNUNET_OS_process_wait (as->transfer_proc);
     100           0 :     GNUNET_OS_process_destroy (as->transfer_proc);
     101           0 :     as->transfer_proc = NULL;
     102             :   }
     103          35 :   GNUNET_free (as);
     104          35 : }
     105             : 
     106             : 
     107             : /**
     108             :  * Offer "transfer" CMD internal data to other commands.
     109             :  *
     110             :  * @param cls closure.
     111             :  * @param[out] ret result.
     112             :  * @param trait name of the trait.
     113             :  * @param index index number of the object to offer.
     114             :  * @return #GNUNET_OK on success
     115             :  */
     116             : static int
     117          75 : transfer_traits (void *cls,
     118             :                  const void **ret,
     119             :                  const char *trait,
     120             :                  unsigned int index)
     121             : {
     122          75 :   struct TransferState *as = cls;
     123             :   struct TALER_TESTING_Trait traits[] = {
     124          75 :     TALER_TESTING_make_trait_process (0, &as->transfer_proc),
     125          75 :     TALER_TESTING_trait_end ()
     126             :   };
     127             : 
     128          75 :   return TALER_TESTING_get_trait (traits,
     129             :                                   ret,
     130             :                                   trait,
     131             :                                   index);
     132             : }
     133             : 
     134             : 
     135             : /**
     136             :  * Make a "transfer" CMD.
     137             :  *
     138             :  * @param label command label.
     139             :  * @param config_filename configuration file for the
     140             :  *                        transfer to use.
     141             :  * @return the command.
     142             :  */
     143             : struct TALER_TESTING_Command
     144          35 : TALER_TESTING_cmd_exec_transfer (const char *label,
     145             :                                  const char *config_filename)
     146             : {
     147             :   struct TransferState *as;
     148             : 
     149          35 :   as = GNUNET_new (struct TransferState);
     150          35 :   as->config_filename = config_filename;
     151             :   {
     152          35 :     struct TALER_TESTING_Command cmd = {
     153             :       .cls = as,
     154             :       .label = label,
     155             :       .run = &transfer_run,
     156             :       .cleanup = &transfer_cleanup,
     157             :       .traits = &transfer_traits
     158             :     };
     159             : 
     160          35 :     return cmd;
     161             :   }
     162             : }
     163             : 
     164             : 
     165             : /* end of testing_api_cmd_exec_transfer.c */

Generated by: LCOV version 1.14