LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_auditor_exec_auditor.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_auditor_exec_auditor.c
      21             :  * @brief run the taler-auditor command
      22             :  * @author Marcello Stanisci
      23             :  * @author Christian Grothoff
      24             :  */
      25             : #include "platform.h"
      26             : #include "taler_json_lib.h"
      27             : #include <gnunet/gnunet_curl_lib.h>
      28             : #include "taler_signatures.h"
      29             : #include "taler_testing_lib.h"
      30             : 
      31             : 
      32             : /**
      33             :  * State for a "auditor" CMD.
      34             :  */
      35             : struct AuditorState
      36             : {
      37             : 
      38             :   /**
      39             :    * Process for the "auditor" command.
      40             :    */
      41             :   struct GNUNET_OS_Process *auditor_proc;
      42             : 
      43             :   /**
      44             :    * Configuration file used by the command.
      45             :    */
      46             :   const char *config_filename;
      47             : };
      48             : 
      49             : 
      50             : /**
      51             :  * Run the command; calls the `taler-auditor' program.
      52             :  *
      53             :  * @param cls closure.
      54             :  * @param cmd the commaind being run.
      55             :  * @param is interpreter state.
      56             :  */
      57             : static void
      58           3 : auditor_run (void *cls,
      59             :              const struct TALER_TESTING_Command *cmd,
      60             :              struct TALER_TESTING_Interpreter *is)
      61             : {
      62           3 :   struct AuditorState *ks = cls;
      63             : 
      64             :   (void) cmd;
      65             :   ks->auditor_proc
      66           3 :     = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
      67             :                                NULL, NULL, NULL,
      68             :                                "taler-auditor",
      69             :                                "taler-auditor",
      70             :                                "-c", ks->config_filename,
      71             :                                NULL);
      72           3 :   if (NULL == ks->auditor_proc)
      73             :   {
      74           0 :     GNUNET_break (0);
      75           0 :     TALER_TESTING_interpreter_fail (is);
      76           0 :     return;
      77             :   }
      78           3 :   TALER_TESTING_wait_for_sigchld (is);
      79             : }
      80             : 
      81             : 
      82             : /**
      83             :  * Free the state of a "auditor" CMD, and possibly kills 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           3 : auditor_cleanup (void *cls,
      91             :                  const struct TALER_TESTING_Command *cmd)
      92             : {
      93           3 :   struct AuditorState *ks = cls;
      94             : 
      95             :   (void) cmd;
      96           3 :   if (NULL != ks->auditor_proc)
      97             :   {
      98           0 :     GNUNET_break (0 ==
      99             :                   GNUNET_OS_process_kill (ks->auditor_proc,
     100             :                                           SIGKILL));
     101           0 :     GNUNET_OS_process_wait (ks->auditor_proc);
     102           0 :     GNUNET_OS_process_destroy (ks->auditor_proc);
     103           0 :     ks->auditor_proc = NULL;
     104             :   }
     105           3 :   GNUNET_free (ks);
     106           3 : }
     107             : 
     108             : 
     109             : /**
     110             :  * Offer "auditor" 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           3 : auditor_traits (void *cls,
     120             :                 const void **ret,
     121             :                 const char *trait,
     122             :                 unsigned int index)
     123             : {
     124           3 :   struct AuditorState *ks = cls;
     125             :   struct TALER_TESTING_Trait traits[] = {
     126           3 :     TALER_TESTING_make_trait_process (0, &ks->auditor_proc),
     127           3 :     TALER_TESTING_trait_end ()
     128             :   };
     129             : 
     130           3 :   return TALER_TESTING_get_trait (traits,
     131             :                                   ret,
     132             :                                   trait,
     133             :                                   index);
     134             : }
     135             : 
     136             : 
     137             : /**
     138             :  * Make the "exec-auditor" CMD.
     139             :  *
     140             :  * @param label command label.
     141             :  * @param config_filename configuration filename.
     142             :  * @return the command.
     143             :  */
     144             : struct TALER_TESTING_Command
     145           3 : TALER_TESTING_cmd_exec_auditor (const char *label,
     146             :                                 const char *config_filename)
     147             : {
     148             :   struct AuditorState *ks;
     149             : 
     150           3 :   ks = GNUNET_new (struct AuditorState);
     151           3 :   ks->config_filename = config_filename;
     152             :   {
     153           3 :     struct TALER_TESTING_Command cmd = {
     154             :       .cls = ks,
     155             :       .label = label,
     156             :       .run = &auditor_run,
     157             :       .cleanup = &auditor_cleanup,
     158             :       .traits = &auditor_traits
     159             :     };
     160             : 
     161           3 :     return cmd;
     162             :   }
     163             : }
     164             : 
     165             : 
     166             : /* end of testing_auditor_api_cmd_exec_auditor.c */

Generated by: LCOV version 1.14