LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_wait.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 20 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             :   (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, or
       8             :   (at your 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, see
      17             :   <http://www.gnu.org/licenses/>
      18             : */
      19             : /**
      20             :  * @file testing/testing_api_cmd_wait.c
      21             :  * @brief command(s) to wait on some process
      22             :  * @author Christian Grothoff
      23             :  */
      24             : #include "platform.h"
      25             : #include "taler_json_lib.h"
      26             : #include <gnunet/gnunet_curl_lib.h>
      27             : #include "taler_testing_lib.h"
      28             : 
      29             : 
      30             : /**
      31             :  * Cleanup the state from a "wait service" CMD.
      32             :  *
      33             :  * @param cls closure.
      34             :  * @param cmd the command which is being cleaned up.
      35             :  */
      36             : static void
      37           0 : wait_service_cleanup (void *cls,
      38             :                       const struct TALER_TESTING_Command *cmd)
      39             : {
      40             :   (void) cls;
      41             :   (void) cmd;
      42             :   /* nothing to clean.  */
      43           0 :   return;
      44             : }
      45             : 
      46             : 
      47             : /**
      48             :  * No traits to offer, just provide a stub to be called when
      49             :  * some CMDs iterates through the list of all the commands.
      50             :  *
      51             :  * @param cls closure.
      52             :  * @param[out] ret result.
      53             :  * @param trait name of the trait.
      54             :  * @param index index number of the trait to return.
      55             :  * @return #GNUNET_OK on success.
      56             :  */
      57             : static int
      58           0 : wait_service_traits (void *cls,
      59             :                      const void **ret,
      60             :                      const char *trait,
      61             :                      unsigned int index)
      62             : {
      63             :   (void) cls;
      64             :   (void) ret;
      65             :   (void) trait;
      66             :   (void) index;
      67           0 :   return GNUNET_NO;
      68             : }
      69             : 
      70             : 
      71             : /**
      72             :  * Run a "wait service" CMD.
      73             :  *
      74             :  * @param cls closure.
      75             :  * @param cmd the command being run.
      76             :  * @param is the interpreter state.
      77             :  */
      78             : static void
      79           0 : wait_service_run (void *cls,
      80             :                   const struct TALER_TESTING_Command *cmd,
      81             :                   struct TALER_TESTING_Interpreter *is)
      82             : {
      83           0 :   unsigned int iter = 0;
      84           0 :   const char *url = cmd->cls;
      85             :   char *wget_cmd;
      86             : 
      87             :   (void) cls;
      88           0 :   GNUNET_asprintf (&wget_cmd,
      89             :                    "wget -q -t 1 -T 1 %s -o /dev/null -O /dev/null",
      90             :                    url);
      91             :   do
      92             :   {
      93           0 :     fprintf (stderr, ".");
      94             : 
      95           0 :     if (10 == iter++)
      96             :     {
      97           0 :       TALER_LOG_ERROR ("Could not reach the proxied service\n");
      98           0 :       TALER_TESTING_interpreter_fail (is);
      99           0 :       GNUNET_free (wget_cmd);
     100           0 :       return;
     101             :     }
     102             :   }
     103           0 :   while (0 != system (wget_cmd));
     104             : 
     105           0 :   GNUNET_free (wget_cmd);
     106           0 :   TALER_TESTING_interpreter_next (is);
     107             : }
     108             : 
     109             : 
     110             : /**
     111             :  * This CMD simply tries to connect via HTTP to the
     112             :  * service addressed by @a url.  It attempts 10 times
     113             :  * before giving up and make the test fail.
     114             :  *
     115             :  * @param label label for the command.
     116             :  * @param url complete URL to connect to.
     117             :  */
     118             : struct TALER_TESTING_Command
     119           0 : TALER_TESTING_cmd_wait_service (const char *label,
     120             :                                 const char *url)
     121             : {
     122           0 :   struct TALER_TESTING_Command cmd = {
     123             :     .label = label,
     124             :     .run = wait_service_run,
     125             :     .cleanup = wait_service_cleanup,
     126             :     .traits = wait_service_traits,
     127             :     .cls = (void *) url
     128             :   };
     129             : 
     130           0 :   return cmd;
     131             : }
     132             : 
     133             : 
     134             : /* end of testing_api_cmd_sleep.c  */

Generated by: LCOV version 1.14