LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_exec_wirewatch.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 27 0.0 %
Date: 2022-08-25 06:15:09 Functions: 0 4 0.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
       6             :   it under the terms of the GNU General Public License as
       7             :   published by the Free Software Foundation; either version 3,
       8             :   or (at your option) any later version.
       9             : 
      10             :   TALER is distributed in the hope that it will be useful,
      11             :   but 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, see
      17             :   <http://www.gnu.org/licenses/>
      18             : */
      19             : /**
      20             :  * @file testing/testing_api_cmd_exec_wirewatch.c
      21             :  * @brief run the taler-exchange-wirewatch command
      22             :  * @author Christian Grothoff
      23             :  * @author Marcello Stanisci
      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 "wirewatch" CMD.
      34             :  */
      35             : struct WirewatchState
      36             : {
      37             : 
      38             :   /**
      39             :    * Process for the wirewatcher.
      40             :    */
      41             :   struct GNUNET_OS_Process *wirewatch_proc;
      42             : 
      43             :   /**
      44             :    * Configuration file used by the wirewatcher.
      45             :    */
      46             :   const char *config_filename;
      47             : };
      48             : 
      49             : 
      50             : /**
      51             :  * Run the command; use the `taler-exchange-wirewatch' program.
      52             :  *
      53             :  * @param cls closure.
      54             :  * @param cmd command currently being executed.
      55             :  * @param is interpreter state.
      56             :  */
      57             : static void
      58           0 : wirewatch_run (void *cls,
      59             :                const struct TALER_TESTING_Command *cmd,
      60             :                struct TALER_TESTING_Interpreter *is)
      61             : {
      62           0 :   struct WirewatchState *ws = cls;
      63             : 
      64             :   (void) cmd;
      65             :   ws->wirewatch_proc
      66           0 :     = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
      67             :                                NULL, NULL, NULL,
      68             :                                "taler-exchange-wirewatch",
      69             :                                "taler-exchange-wirewatch",
      70             :                                "-c", ws->config_filename,
      71             :                                "-S", "1",
      72             :                                "-w", "0",
      73             :                                "-t", /* exit when done */
      74             :                                NULL);
      75           0 :   if (NULL == ws->wirewatch_proc)
      76             :   {
      77           0 :     GNUNET_break (0);
      78           0 :     TALER_TESTING_interpreter_fail (is);
      79           0 :     return;
      80             :   }
      81           0 :   TALER_TESTING_wait_for_sigchld (is);
      82             : }
      83             : 
      84             : 
      85             : /**
      86             :  * Free the state of a "wirewatch" CMD, and possibly
      87             :  * kills its process if it did not terminate regularly.
      88             :  *
      89             :  * @param cls closure.
      90             :  * @param cmd the command being freed.
      91             :  */
      92             : static void
      93           0 : wirewatch_cleanup (void *cls,
      94             :                    const struct TALER_TESTING_Command *cmd)
      95             : {
      96           0 :   struct WirewatchState *ws = cls;
      97             : 
      98             :   (void) cmd;
      99           0 :   if (NULL != ws->wirewatch_proc)
     100             :   {
     101           0 :     GNUNET_break (0 ==
     102             :                   GNUNET_OS_process_kill (ws->wirewatch_proc,
     103             :                                           SIGKILL));
     104           0 :     GNUNET_OS_process_wait (ws->wirewatch_proc);
     105           0 :     GNUNET_OS_process_destroy (ws->wirewatch_proc);
     106           0 :     ws->wirewatch_proc = NULL;
     107             :   }
     108           0 :   GNUNET_free (ws);
     109           0 : }
     110             : 
     111             : 
     112             : /**
     113             :  * Offer "wirewatch" CMD internal data to other commands.
     114             :  *
     115             :  * @param cls closure.
     116             :  * @param[out] ret result.
     117             :  * @param trait name of the trait.
     118             :  * @param index index number of the object to offer.
     119             :  * @return #GNUNET_OK on success.
     120             :  */
     121             : static enum GNUNET_GenericReturnValue
     122           0 : wirewatch_traits (void *cls,
     123             :                   const void **ret,
     124             :                   const char *trait,
     125             :                   unsigned int index)
     126             : {
     127           0 :   struct WirewatchState *ws = cls;
     128             :   struct TALER_TESTING_Trait traits[] = {
     129           0 :     TALER_TESTING_make_trait_process (&ws->wirewatch_proc),
     130           0 :     TALER_TESTING_trait_end ()
     131             :   };
     132             : 
     133           0 :   return TALER_TESTING_get_trait (traits,
     134             :                                   ret,
     135             :                                   trait,
     136             :                                   index);
     137             : }
     138             : 
     139             : 
     140             : struct TALER_TESTING_Command
     141           0 : TALER_TESTING_cmd_exec_wirewatch (const char *label,
     142             :                                   const char *config_filename)
     143             : {
     144             :   struct WirewatchState *ws;
     145             : 
     146           0 :   ws = GNUNET_new (struct WirewatchState);
     147           0 :   ws->config_filename = config_filename;
     148             : 
     149             :   {
     150           0 :     struct TALER_TESTING_Command cmd = {
     151             :       .cls = ws,
     152             :       .label = label,
     153             :       .run = &wirewatch_run,
     154             :       .cleanup = &wirewatch_cleanup,
     155             :       .traits = &wirewatch_traits
     156             :     };
     157             : 
     158           0 :     return cmd;
     159             :   }
     160             : }
     161             : 
     162             : 
     163             : /* end of testing_api_cmd_exec_wirewatch.c */

Generated by: LCOV version 1.14