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: 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
       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             :  * Run the command; use the `taler-exchange-wirewatch' program.
      51             :  *
      52             :  * @param cls closure.
      53             :  * @param cmd command currently being executed.
      54             :  * @param is interpreter state.
      55             :  */
      56             : static void
      57          27 : wirewatch_run (void *cls,
      58             :                const struct TALER_TESTING_Command *cmd,
      59             :                struct TALER_TESTING_Interpreter *is)
      60             : {
      61          27 :   struct WirewatchState *ws = cls;
      62             : 
      63             :   ws->wirewatch_proc
      64          27 :     = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
      65             :                                NULL, NULL, NULL,
      66             :                                "taler-exchange-wirewatch",
      67             :                                "taler-exchange-wirewatch",
      68             :                                "-c", ws->config_filename,
      69             :                                "-S", "1",
      70             :                                "-w", "0",
      71             :                                "-t", /* exit when done */
      72             :                                NULL);
      73          27 :   if (NULL == ws->wirewatch_proc)
      74             :   {
      75           0 :     GNUNET_break (0);
      76           0 :     TALER_TESTING_interpreter_fail (is);
      77           0 :     return;
      78             :   }
      79          27 :   TALER_TESTING_wait_for_sigchld (is);
      80             : }
      81             : 
      82             : 
      83             : /**
      84             :  * Free the state of a "wirewatch" CMD, and possibly
      85             :  * kills its process if it did not terminate regularly.
      86             :  *
      87             :  * @param cls closure.
      88             :  * @param cmd the command being freed.
      89             :  */
      90             : static void
      91          27 : wirewatch_cleanup (void *cls,
      92             :                    const struct TALER_TESTING_Command *cmd)
      93             : {
      94          27 :   struct WirewatchState *ws = cls;
      95             : 
      96          27 :   if (NULL != ws->wirewatch_proc)
      97             :   {
      98           0 :     GNUNET_break (0 ==
      99             :                   GNUNET_OS_process_kill (ws->wirewatch_proc,
     100             :                                           SIGKILL));
     101           0 :     GNUNET_OS_process_wait (ws->wirewatch_proc);
     102           0 :     GNUNET_OS_process_destroy (ws->wirewatch_proc);
     103           0 :     ws->wirewatch_proc = NULL;
     104             :   }
     105          27 :   GNUNET_free (ws);
     106          27 : }
     107             : 
     108             : 
     109             : /**
     110             :  * Offer "wirewatch" 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          87 : wirewatch_traits (void *cls,
     120             :                   const void **ret,
     121             :                   const char *trait,
     122             :                   unsigned int index)
     123             : {
     124          87 :   struct WirewatchState *ws = cls;
     125             :   struct TALER_TESTING_Trait traits[] = {
     126          87 :     TALER_TESTING_make_trait_process (0,
     127             :                                       &ws->wirewatch_proc),
     128          87 :     TALER_TESTING_trait_end ()
     129             :   };
     130             : 
     131          87 :   return TALER_TESTING_get_trait (traits,
     132             :                                   ret,
     133             :                                   trait,
     134             :                                   index);
     135             : }
     136             : 
     137             : 
     138             : /**
     139             :  * Make a "wirewatch" CMD.
     140             :  *
     141             :  * @param label command label.
     142             :  * @param config_filename configuration filename.
     143             :  * @return the command.
     144             :  */
     145             : struct TALER_TESTING_Command
     146          27 : TALER_TESTING_cmd_exec_wirewatch (const char *label,
     147             :                                   const char *config_filename)
     148             : {
     149             :   struct WirewatchState *ws;
     150             : 
     151          27 :   ws = GNUNET_new (struct WirewatchState);
     152          27 :   ws->config_filename = config_filename;
     153             : 
     154             :   {
     155          27 :     struct TALER_TESTING_Command cmd = {
     156             :       .cls = ws,
     157             :       .label = label,
     158             :       .run = &wirewatch_run,
     159             :       .cleanup = &wirewatch_cleanup,
     160             :       .traits = &wirewatch_traits
     161             :     };
     162             : 
     163          27 :     return cmd;
     164             :   }
     165             : }
     166             : 
     167             : 
     168             : /* end of testing_api_cmd_exec_wirewatch.c */

Generated by: LCOV version 1.14