LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_auditor_exec_auditor_dbinit.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 30 0
Test Date: 2026-03-27 15:46:29 Functions: 0.0 % 4 0

            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_dbinit.c
      21              :  * @brief run the taler-auditor-dbinit "-R" command
      22              :  * @author Marcello Stanisci
      23              :  * @author Christian Grothoff
      24              :  */
      25              : #include "taler/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              : 
      31              : 
      32              : /**
      33              :  * State for a "auditor-dbinit" CMD.
      34              :  */
      35              : struct AuditorDbinitState
      36              : {
      37              : 
      38              :   /**
      39              :    * Process for the "auditor-dbinit" command.
      40              :    */
      41              :   struct GNUNET_Process *auditor_dbinit_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-dbinit` program.
      52              :  *
      53              :  * @param cls closure.
      54              :  * @param cmd the commaind being run.
      55              :  * @param is interpreter state.
      56              :  */
      57              : static void
      58            0 : auditor_dbinit_run (void *cls,
      59              :                     const struct TALER_TESTING_Command *cmd,
      60              :                     struct TALER_TESTING_Interpreter *is)
      61              : {
      62            0 :   struct AuditorDbinitState *ks = cls;
      63              : 
      64              :   (void) cmd;
      65              :   ks->auditor_dbinit_proc
      66            0 :     = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ERR);
      67            0 :   if (GNUNET_OK !=
      68            0 :       GNUNET_process_run_command_va (ks->auditor_dbinit_proc,
      69              :                                      "taler-auditor-dbinit",
      70              :                                      "taler-auditor-dbinit",
      71              :                                      "-c", ks->config_filename,
      72              :                                      "-R",
      73              :                                      NULL))
      74              :   {
      75            0 :     GNUNET_break (0);
      76            0 :     GNUNET_process_destroy (ks->auditor_dbinit_proc);
      77            0 :     ks->auditor_dbinit_proc = NULL;
      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 "auditor-dbinit" CMD, and possibly kills its
      87              :  * process if it did not terminate correctly.
      88              :  *
      89              :  * @param cls closure.
      90              :  * @param cmd the command being freed.
      91              :  */
      92              : static void
      93            0 : auditor_dbinit_cleanup (void *cls,
      94              :                         const struct TALER_TESTING_Command *cmd)
      95              : {
      96            0 :   struct AuditorDbinitState *ks = cls;
      97              : 
      98              :   (void) cmd;
      99            0 :   if (NULL != ks->auditor_dbinit_proc)
     100              :   {
     101            0 :     GNUNET_break (GNUNET_OK ==
     102              :                   GNUNET_process_kill (ks->auditor_dbinit_proc,
     103              :                                        SIGKILL));
     104            0 :     GNUNET_process_wait (ks->auditor_dbinit_proc,
     105              :                          true,
     106              :                          NULL,
     107              :                          NULL);
     108            0 :     GNUNET_process_destroy (ks->auditor_dbinit_proc);
     109            0 :     ks->auditor_dbinit_proc = NULL;
     110              :   }
     111            0 :   GNUNET_free (ks);
     112            0 : }
     113              : 
     114              : 
     115              : /**
     116              :  * Offer "auditor-dbinit" CMD internal data to other commands.
     117              :  *
     118              :  * @param cls closure.
     119              :  * @param[out] ret result
     120              :  * @param trait name of the trait.
     121              :  * @param index index number of the object to offer.
     122              :  * @return #GNUNET_OK on success.
     123              :  */
     124              : static int
     125            0 : auditor_dbinit_traits (void *cls,
     126              :                        const void **ret,
     127              :                        const char *trait,
     128              :                        unsigned int index)
     129              : {
     130            0 :   struct AuditorDbinitState *ks = cls;
     131              :   struct TALER_TESTING_Trait traits[] = {
     132            0 :     TALER_TESTING_make_trait_process (&ks->auditor_dbinit_proc),
     133            0 :     TALER_TESTING_trait_end ()
     134              :   };
     135              : 
     136            0 :   return TALER_TESTING_get_trait (traits,
     137              :                                   ret,
     138              :                                   trait,
     139              :                                   index);
     140              : }
     141              : 
     142              : 
     143              : struct TALER_TESTING_Command
     144            0 : TALER_TESTING_cmd_exec_auditor_dbinit (const char *label,
     145              :                                        const char *config_filename)
     146              : {
     147              :   struct AuditorDbinitState *ks;
     148              : 
     149            0 :   ks = GNUNET_new (struct AuditorDbinitState);
     150            0 :   ks->config_filename = config_filename;
     151              :   {
     152            0 :     struct TALER_TESTING_Command cmd = {
     153              :       .cls = ks,
     154              :       .label = label,
     155              :       .run = &auditor_dbinit_run,
     156              :       .cleanup = &auditor_dbinit_cleanup,
     157              :       .traits = &auditor_dbinit_traits
     158              :     };
     159              : 
     160            0 :     return cmd;
     161              :   }
     162              : }
     163              : 
     164              : 
     165              : /* end of testing_auditor_api_cmd_exec_auditor_dbinit.c */
        

Generated by: LCOV version 2.0-1