LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_depositcheck.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 74.1 % 27 20
Test Date: 2025-11-13 17:46:01 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2024 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_depositcheck.c
      21              :  * @brief run the taler-merchant-depositcheck command
      22              :  * @author Priscilla HUANG
      23              :  * @author Christian Grothoff
      24              :  */
      25              : #include "platform.h"
      26              : #include "taler/taler_json_lib.h"
      27              : #include <gnunet/gnunet_curl_lib.h>
      28              : #include "taler/taler_signatures.h"
      29              : #include "taler/taler_testing_lib.h"
      30              : #include "taler_merchant_testing_lib.h"
      31              : 
      32              : 
      33              : /**
      34              :  * State for a "depositcheck" CMD.
      35              :  */
      36              : struct DepositcheckState
      37              : {
      38              : 
      39              :   /**
      40              :    * Process for the depositcheck.
      41              :    */
      42              :   struct GNUNET_OS_Process *depositcheck_proc;
      43              : 
      44              :   /**
      45              :    * Configuration file used by the depositcheck.
      46              :    */
      47              :   const char *config_filename;
      48              : };
      49              : 
      50              : 
      51              : /**
      52              :  * Run the command; use the `taler-merchant-depositcheck' program.
      53              :  *
      54              :  * @param cls closure.
      55              :  * @param cmd command currently being executed.
      56              :  * @param is interpreter state.
      57              :  */
      58              : static void
      59            4 : depositcheck_run (void *cls,
      60              :                   const struct TALER_TESTING_Command *cmd,
      61              :                   struct TALER_TESTING_Interpreter *is)
      62              : {
      63            4 :   struct DepositcheckState *ws = cls;
      64              : 
      65              :   (void) cmd;
      66              :   ws->depositcheck_proc
      67            4 :     = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
      68              :                                NULL, NULL, NULL,
      69              :                                "taler-merchant-depositcheck",
      70              :                                "taler-merchant-depositcheck",
      71              :                                "-c", ws->config_filename,
      72              :                                "-t", /* exit when done */
      73              :                                "-T", "1200s",
      74              :                                "-L", "INFO",
      75              :                                NULL);
      76            4 :   if (NULL == ws->depositcheck_proc)
      77              :   {
      78            0 :     GNUNET_break (0);
      79            0 :     TALER_TESTING_interpreter_fail (is);
      80            0 :     return;
      81              :   }
      82            4 :   TALER_TESTING_wait_for_sigchld (is);
      83              : }
      84              : 
      85              : 
      86              : /**
      87              :  * Free the state of a "depositcheck" CMD, and possibly
      88              :  * kills its process if it did not terminate regularly.
      89              :  *
      90              :  * @param cls closure.
      91              :  * @param cmd the command being freed.
      92              :  */
      93              : static void
      94            4 : depositcheck_cleanup (void *cls,
      95              :                       const struct TALER_TESTING_Command *cmd)
      96              : {
      97            4 :   struct DepositcheckState *ws = cls;
      98              : 
      99              :   (void) cmd;
     100            4 :   if (NULL != ws->depositcheck_proc)
     101              :   {
     102            0 :     GNUNET_break (0 ==
     103              :                   GNUNET_OS_process_kill (ws->depositcheck_proc,
     104              :                                           SIGKILL));
     105            0 :     GNUNET_OS_process_wait (ws->depositcheck_proc);
     106            0 :     GNUNET_OS_process_destroy (ws->depositcheck_proc);
     107            0 :     ws->depositcheck_proc = NULL;
     108              :   }
     109            4 :   GNUNET_free (ws);
     110            4 : }
     111              : 
     112              : 
     113              : /**
     114              :  * Offer "depositcheck" CMD internal data to other commands.
     115              :  *
     116              :  * @param cls closure.
     117              :  * @param[out] ret result.
     118              :  * @param trait name of the trait.
     119              :  * @param index index number of the object to offer.
     120              :  * @return #GNUNET_OK on success.
     121              :  */
     122              : static enum GNUNET_GenericReturnValue
     123            8 : depositcheck_traits (void *cls,
     124              :                      const void **ret,
     125              :                      const char *trait,
     126              :                      unsigned int index)
     127              : {
     128            8 :   struct DepositcheckState *ws = cls;
     129              :   struct TALER_TESTING_Trait traits[] = {
     130            8 :     TALER_TESTING_make_trait_process (&ws->depositcheck_proc),
     131            8 :     TALER_TESTING_trait_end ()
     132              :   };
     133              : 
     134            8 :   return TALER_TESTING_get_trait (traits,
     135              :                                   ret,
     136              :                                   trait,
     137              :                                   index);
     138              : }
     139              : 
     140              : 
     141              : struct TALER_TESTING_Command
     142            4 : TALER_TESTING_cmd_depositcheck (const char *label,
     143              :                                 const char *config_filename)
     144              : {
     145              :   struct DepositcheckState *ws;
     146              : 
     147            4 :   ws = GNUNET_new (struct DepositcheckState);
     148            4 :   ws->config_filename = config_filename;
     149              : 
     150              :   {
     151            4 :     struct TALER_TESTING_Command cmd = {
     152              :       .cls = ws,
     153              :       .label = label,
     154              :       .run = &depositcheck_run,
     155              :       .cleanup = &depositcheck_cleanup,
     156              :       .traits = &depositcheck_traits
     157              :     };
     158              : 
     159            4 :     return cmd;
     160              :   }
     161              : }
     162              : 
     163              : 
     164              : /* end of testing_api_cmd_depositcheck.c */
        

Generated by: LCOV version 2.0-1