LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_exec_aggregator.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_aggregator.c
      21             :  * @brief run the taler-exchange-aggregator 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 "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             : 
      49             : /**
      50             :  * Run the command.  Use the `taler-exchange-aggregator' program.
      51             :  *
      52             :  * @param cls closure.
      53             :  * @param cmd command being run.
      54             :  * @param is interpreter state.
      55             :  */
      56             : static void
      57          33 : aggregator_run (void *cls,
      58             :                 const struct TALER_TESTING_Command *cmd,
      59             :                 struct TALER_TESTING_Interpreter *is)
      60             : {
      61          33 :   struct AggregatorState *as = cls;
      62             : 
      63             :   (void) cmd;
      64             :   as->aggregator_proc
      65          33 :     = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
      66             :                                NULL, NULL, NULL,
      67             :                                "taler-exchange-aggregator",
      68             :                                "taler-exchange-aggregator",
      69             :                                "-c", as->config_filename,
      70             :                                "-t", /* exit when done */
      71             :                                NULL);
      72          33 :   if (NULL == as->aggregator_proc)
      73             :   {
      74           0 :     GNUNET_break (0);
      75           0 :     TALER_TESTING_interpreter_fail (is);
      76           0 :     return;
      77             :   }
      78          33 :   TALER_TESTING_wait_for_sigchld (is);
      79             : }
      80             : 
      81             : 
      82             : /**
      83             :  * Free the state of a "aggregator" CMD, and possibly kill its
      84             :  * process if it did not terminate correctly.
      85             :  *
      86             :  * @param cls closure.
      87             :  * @param cmd the command being freed.
      88             :  */
      89             : static void
      90          33 : aggregator_cleanup (void *cls,
      91             :                     const struct TALER_TESTING_Command *cmd)
      92             : {
      93          33 :   struct AggregatorState *as = cls;
      94             : 
      95             :   (void) cmd;
      96          33 :   if (NULL != as->aggregator_proc)
      97             :   {
      98           0 :     GNUNET_break (0 ==
      99             :                   GNUNET_OS_process_kill (as->aggregator_proc,
     100             :                                           SIGKILL));
     101           0 :     GNUNET_OS_process_wait (as->aggregator_proc);
     102           0 :     GNUNET_OS_process_destroy (as->aggregator_proc);
     103           0 :     as->aggregator_proc = NULL;
     104             :   }
     105          33 :   GNUNET_free (as);
     106          33 : }
     107             : 
     108             : 
     109             : /**
     110             :  * Offer "aggregator" CMD internal data to other commands.
     111             :  *
     112             :  * @param cls closure.
     113             :  * @param[out] ret result.
     114             :  * @param trait name of the trait.
     115             :  * @param index index number of the object to offer.
     116             :  * @return #GNUNET_OK on success
     117             :  */
     118             : static int
     119          69 : aggregator_traits (void *cls,
     120             :                    const void **ret,
     121             :                    const char *trait,
     122             :                    unsigned int index)
     123             : {
     124          69 :   struct AggregatorState *as = cls;
     125             :   struct TALER_TESTING_Trait traits[] = {
     126          69 :     TALER_TESTING_make_trait_process (0, &as->aggregator_proc),
     127          69 :     TALER_TESTING_trait_end ()
     128             :   };
     129             : 
     130          69 :   return TALER_TESTING_get_trait (traits,
     131             :                                   ret,
     132             :                                   trait,
     133             :                                   index);
     134             : }
     135             : 
     136             : 
     137             : /**
     138             :  * Make a "aggregator" CMD.
     139             :  *
     140             :  * @param label command label.
     141             :  * @param config_filename configuration file for the
     142             :  *                        aggregator to use.
     143             :  * @return the command.
     144             :  */
     145             : struct TALER_TESTING_Command
     146          33 : TALER_TESTING_cmd_exec_aggregator (const char *label,
     147             :                                    const char *config_filename)
     148             : {
     149             :   struct AggregatorState *as;
     150             : 
     151          33 :   as = GNUNET_new (struct AggregatorState);
     152          33 :   as->config_filename = config_filename;
     153             :   {
     154          33 :     struct TALER_TESTING_Command cmd = {
     155             :       .cls = as,
     156             :       .label = label,
     157             :       .run = &aggregator_run,
     158             :       .cleanup = &aggregator_cleanup,
     159             :       .traits = &aggregator_traits
     160             :     };
     161             : 
     162          33 :     return cmd;
     163             :   }
     164             : }
     165             : 
     166             : 
     167             : /* end of testing_api_cmd_exec_aggregator.c */

Generated by: LCOV version 1.14