LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_offline_sign_extensions.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) 2022 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             : /**
      21             :  * @file testing/testing_api_cmd_offline_sign_extensions.c
      22             :  * @brief run the taler-exchange-offline command to sign extensions (and therefore activate them)
      23             :  * @author Özgür Kesim
      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 "extensionssign" CMD.
      34             :  */
      35             : struct ExtensionsSignState
      36             : {
      37             : 
      38             :   /**
      39             :    * Process for the "extensionssign" command.
      40             :    */
      41             :   struct GNUNET_OS_Process *extensionssign_proc;
      42             : 
      43             :   /**
      44             :    * Configuration file used by the command.
      45             :    */
      46             :   const char *config_filename;
      47             : 
      48             : };
      49             : 
      50             : 
      51             : /**
      52             :  * Run the command; calls the `taler-exchange-offline' program.
      53             :  *
      54             :  * @param cls closure.
      55             :  * @param cmd the commaind being run.
      56             :  * @param is interpreter state.
      57             :  */
      58             : static void
      59           0 : extensionssign_run (void *cls,
      60             :                     const struct TALER_TESTING_Command *cmd,
      61             :                     struct TALER_TESTING_Interpreter *is)
      62             : {
      63           0 :   struct ExtensionsSignState *ks = cls;
      64             : 
      65             :   ks->extensionssign_proc
      66           0 :     = GNUNET_OS_start_process (
      67             :         GNUNET_OS_INHERIT_STD_ALL,
      68             :         NULL, NULL, NULL,
      69             :         "taler-exchange-offline",
      70             :         "taler-exchange-offline",
      71             :         "-c", ks->config_filename,
      72             :         "-L", "INFO",
      73             :         "extensions",
      74             :         "sign",
      75             :         "upload",
      76             :         NULL);
      77           0 :   if (NULL == ks->extensionssign_proc)
      78             :   {
      79           0 :     GNUNET_break (0);
      80           0 :     TALER_TESTING_interpreter_fail (is);
      81           0 :     return;
      82             :   }
      83           0 :   TALER_TESTING_wait_for_sigchld (is);
      84             : }
      85             : 
      86             : 
      87             : /**
      88             :  * Free the state of a "extensionssign" CMD, and possibly kills its
      89             :  * process if it did not terminate correctly.
      90             :  *
      91             :  * @param cls closure.
      92             :  * @param cmd the command being freed.
      93             :  */
      94             : static void
      95           0 : extensionssign_cleanup (void *cls,
      96             :                         const struct TALER_TESTING_Command *cmd)
      97             : {
      98           0 :   struct ExtensionsSignState *ks = cls;
      99             : 
     100             :   (void) cmd;
     101           0 :   if (NULL != ks->extensionssign_proc)
     102             :   {
     103           0 :     GNUNET_break (0 ==
     104             :                   GNUNET_OS_process_kill (ks->extensionssign_proc,
     105             :                                           SIGKILL));
     106           0 :     GNUNET_OS_process_wait (ks->extensionssign_proc);
     107           0 :     GNUNET_OS_process_destroy (ks->extensionssign_proc);
     108           0 :     ks->extensionssign_proc = NULL;
     109             :   }
     110           0 :   GNUNET_free (ks);
     111           0 : }
     112             : 
     113             : 
     114             : /**
     115             :  * Offer "extensionssign" CMD internal data to other commands.
     116             :  *
     117             :  * @param cls closure.
     118             :  * @param[out] ret result
     119             :  * @param trait name of the trait.
     120             :  * @param index index number of the object to offer.
     121             :  * @return #GNUNET_OK on success.
     122             :  */
     123             : static enum GNUNET_GenericReturnValue
     124           0 : extensionssign_traits (void *cls,
     125             :                        const void **ret,
     126             :                        const char *trait,
     127             :                        unsigned int index)
     128             : {
     129           0 :   struct ExtensionsSignState *ks = cls;
     130             :   struct TALER_TESTING_Trait traits[] = {
     131           0 :     TALER_TESTING_make_trait_process (&ks->extensionssign_proc),
     132           0 :     TALER_TESTING_trait_end ()
     133             :   };
     134             : 
     135           0 :   return TALER_TESTING_get_trait (traits,
     136             :                                   ret,
     137             :                                   trait,
     138             :                                   index);
     139             : }
     140             : 
     141             : 
     142             : struct TALER_TESTING_Command
     143           0 : TALER_TESTING_cmd_exec_offline_sign_extensions (const char *label,
     144             :                                                 const char *config_filename)
     145             : {
     146             :   struct ExtensionsSignState *ks;
     147             : 
     148           0 :   ks = GNUNET_new (struct ExtensionsSignState);
     149           0 :   ks->config_filename = config_filename;
     150             :   {
     151           0 :     struct TALER_TESTING_Command cmd = {
     152             :       .cls = ks,
     153             :       .label = label,
     154             :       .run = &extensionssign_run,
     155             :       .cleanup = &extensionssign_cleanup,
     156             :       .traits = &extensionssign_traits
     157             :     };
     158             : 
     159           0 :     return cmd;
     160             :   }
     161             : }
     162             : 
     163             : 
     164             : /* end of testing_api_cmd_exec_offline_sign_extensions.c */

Generated by: LCOV version 1.14