LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_twister_exec_client.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 20 213 9.4 %
Date: 2022-08-25 06:15:09 Functions: 4 30 13.3 %
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             : /**
      21             :  * @file testing_api_cmd_twister_exec_client.c
      22             :  * @brief test commands aimed to call the CLI twister client
      23             :  *        to drive its behaviour.
      24             :  * @author Christian Grothoff <christian@grothoff.org>
      25             :  * @author Marcello Stanisci
      26             :  */
      27             : 
      28             : #include "platform.h"
      29             : #include "taler_testing_lib.h"
      30             : #include "taler_twister_testing_lib.h"
      31             : 
      32             : 
      33             : /**
      34             :  * State for a "modify object" CMD.
      35             :  */
      36             : struct ModifyObjectState
      37             : {
      38             :   /**
      39             :    * Process handle for the twister CLI client.
      40             :    */
      41             :   struct GNUNET_OS_Process *proc;
      42             : 
      43             :   /**
      44             :    * Object-like notation to the object to delete.
      45             :    */
      46             :   const char *path;
      47             : 
      48             : 
      49             :   /**
      50             :    * Value to substitute to the original one.
      51             :    */
      52             :   const char *value;
      53             : 
      54             :   /**
      55             :    * Config file name to pass to the CLI client.
      56             :    */
      57             :   const char *config_filename;
      58             : };
      59             : 
      60             : 
      61             : /**
      62             :  * State for a "flip object" CMD.
      63             :  */
      64             : struct FlipObjectState
      65             : {
      66             :   /**
      67             :    * Process handle for the twister CLI client.
      68             :    */
      69             :   struct GNUNET_OS_Process *proc;
      70             : 
      71             :   /**
      72             :    * Object-like notation to the string-object to flip.
      73             :    */
      74             :   const char *path;
      75             : 
      76             :   /**
      77             :    * Config file name to pass to the CLI client.
      78             :    */
      79             :   const char *config_filename;
      80             : };
      81             : 
      82             : 
      83             : /**
      84             :  * State for a "delete object" CMD.
      85             :  */
      86             : struct DeleteObjectState
      87             : {
      88             :   /**
      89             :    * Process handle for the twister CLI client.
      90             :    */
      91             :   struct GNUNET_OS_Process *proc;
      92             : 
      93             :   /**
      94             :    * Object-like notation to the object to delete.
      95             :    */
      96             :   const char *path;
      97             : 
      98             :   /**
      99             :    * Config file name to pass to the CLI client.
     100             :    */
     101             :   const char *config_filename;
     102             : };
     103             : 
     104             : 
     105             : /**
     106             :  * State for a "malform request" CMD.
     107             :  */
     108             : struct MalformRequestState
     109             : {
     110             :   /**
     111             :    * Process handle for the twister CLI client.
     112             :    */
     113             :   struct GNUNET_OS_Process *proc;
     114             : 
     115             :   /**
     116             :    * Config file name to pass to the CLI client.
     117             :    */
     118             :   const char *config_filename;
     119             : };
     120             : 
     121             : 
     122             : /**
     123             :  * State for a "malform response" CMD.
     124             :  */
     125             : struct MalformResponseState
     126             : {
     127             :   /**
     128             :    * Process handle for the twister CLI client.
     129             :    */
     130             :   struct GNUNET_OS_Process *proc;
     131             : 
     132             :   /**
     133             :    * Config file name to pass to the CLI client.
     134             :    */
     135             :   const char *config_filename;
     136             : };
     137             : 
     138             : 
     139             : /**
     140             :  * State for a "hack response code" CMD.
     141             :  */
     142             : struct HackResponseCodeState
     143             : {
     144             :   /**
     145             :    * Process handle for the twister CLI client.
     146             :    */
     147             :   struct GNUNET_OS_Process *proc;
     148             : 
     149             :   /**
     150             :    * HTTP status code to substitute to the original one.
     151             :    */
     152             :   unsigned int http_status;
     153             : 
     154             :   /**
     155             :    * Config file name to pass to the CLI client.
     156             :    */
     157             :   const char *config_filename;
     158             : };
     159             : 
     160             : 
     161             : /**
     162             :  * Free the state from a "hack response code" CMD, and
     163             :  * possibly kill its process if it did not terminate yet.
     164             :  *
     165             :  * @param cls closure.
     166             :  * @param cmd the command being cleaned up.
     167             :  */
     168             : static void
     169           0 : hack_response_code_cleanup
     170             :   (void *cls,
     171             :   const struct TALER_TESTING_Command *cmd)
     172             : {
     173           0 :   struct HackResponseCodeState *hrcs = cls;
     174             : 
     175           0 :   if (NULL != hrcs->proc)
     176             :   {
     177           0 :     GNUNET_break (0 == GNUNET_OS_process_kill (hrcs->proc,
     178             :                                                SIGKILL));
     179           0 :     GNUNET_OS_process_wait (hrcs->proc);
     180           0 :     GNUNET_OS_process_destroy (hrcs->proc);
     181           0 :     hrcs->proc = NULL;
     182             :   }
     183           0 :   GNUNET_free (hrcs);
     184           0 : }
     185             : 
     186             : 
     187             : /**
     188             :  * Offer data internal to a "hack response code" CMD,
     189             :  * to other commands.
     190             :  *
     191             :  * @param cls closure
     192             :  * @param[out] ret result (could be anything)
     193             :  * @param trait name of the trait
     194             :  * @param index index number of the object to offer.
     195             :  * @return #GNUNET_OK on success
     196             :  */
     197             : static enum GNUNET_GenericReturnValue
     198           0 : hack_response_code_traits (void *cls,
     199             :                            const void **ret,
     200             :                            const char *trait,
     201             :                            unsigned int index)
     202             : {
     203             : 
     204           0 :   struct HackResponseCodeState *hrcs = cls;
     205             :   struct TALER_TESTING_Trait traits[] = {
     206           0 :     TALER_TESTING_make_trait_process (&hrcs->proc),
     207           0 :     TALER_TESTING_trait_end ()
     208             :   };
     209             : 
     210           0 :   return TALER_TESTING_get_trait (traits,
     211             :                                   ret,
     212             :                                   trait,
     213             :                                   index);
     214             : }
     215             : 
     216             : 
     217             : /**
     218             :  * Run a "hack response code" CMD.
     219             :  *
     220             :  * @param cls closure.
     221             :  * @param cmd the command being run.
     222             :  * @param is the interpreter state.
     223             :  */
     224             : static void
     225           0 : hack_response_code_run (void *cls,
     226             :                         const struct TALER_TESTING_Command *cmd,
     227             :                         struct TALER_TESTING_Interpreter *is)
     228             : {
     229           0 :   struct HackResponseCodeState *hrcs = cls;
     230             :   char *http_status;
     231             : 
     232           0 :   GNUNET_asprintf (&http_status, "%u",
     233             :                    hrcs->http_status);
     234             : 
     235           0 :   hrcs->proc = GNUNET_OS_start_process (
     236             :     GNUNET_OS_INHERIT_STD_ALL,
     237             :     NULL, NULL, NULL,
     238             :     "taler-twister",
     239             :     "taler-twister",
     240             :     "-c", hrcs->config_filename,
     241             :     "--responsecode", http_status,
     242             :     NULL);
     243           0 :   if (NULL == hrcs->proc)
     244             :   {
     245           0 :     GNUNET_break (0);
     246           0 :     TALER_TESTING_interpreter_fail (is);
     247           0 :     return;
     248             :   }
     249           0 :   TALER_TESTING_wait_for_sigchld (is);
     250           0 :   GNUNET_free (http_status);
     251             : }
     252             : 
     253             : 
     254             : struct TALER_TESTING_Command
     255           0 : TALER_TESTING_cmd_hack_response_code (const char *label,
     256             :                                       const char *config_filename,
     257             :                                       unsigned int http_status)
     258             : {
     259             :   struct HackResponseCodeState *hrcs;
     260             : 
     261           0 :   hrcs = GNUNET_new (struct HackResponseCodeState);
     262           0 :   hrcs->http_status = http_status;
     263           0 :   hrcs->config_filename = config_filename;
     264             :   {
     265           0 :     struct TALER_TESTING_Command cmd = {
     266             :       .label = label,
     267             :       .run = &hack_response_code_run,
     268             :       .cleanup = &hack_response_code_cleanup,
     269             :       .traits = &hack_response_code_traits,
     270             :       .cls = hrcs
     271             :     };
     272             : 
     273           0 :     return cmd;
     274             :   }
     275             : }
     276             : 
     277             : 
     278             : /**
     279             :  * Free the state from a "delete object" CMD, and
     280             :  * possibly kill its process if it did not terminate yet.
     281             :  *
     282             :  * @param cls closure.
     283             :  * @param cmd the command being cleaned up.
     284             :  */
     285             : static void
     286           0 : delete_object_cleanup
     287             :   (void *cls,
     288             :   const struct TALER_TESTING_Command *cmd)
     289             : {
     290           0 :   struct DeleteObjectState *dos = cls;
     291             : 
     292           0 :   if (NULL != dos->proc)
     293             :   {
     294           0 :     GNUNET_break (0 == GNUNET_OS_process_kill (dos->proc,
     295             :                                                SIGKILL));
     296           0 :     GNUNET_OS_process_wait (dos->proc);
     297           0 :     GNUNET_OS_process_destroy (dos->proc);
     298           0 :     dos->proc = NULL;
     299             :   }
     300           0 :   GNUNET_free (dos);
     301           0 : }
     302             : 
     303             : 
     304             : /**
     305             :  * Offer data internal to a "delete object" CMD,
     306             :  * to other commands.
     307             :  *
     308             :  * @param cls closure
     309             :  * @param[out] ret result (could be anything)
     310             :  * @param trait name of the trait
     311             :  * @param index index number of the object to offer.
     312             :  * @return #GNUNET_OK on success
     313             :  */
     314             : static enum GNUNET_GenericReturnValue
     315           0 : delete_object_traits (void *cls,
     316             :                       const void **ret,
     317             :                       const char *trait,
     318             :                       unsigned int index)
     319             : {
     320             : 
     321           0 :   struct DeleteObjectState *dos = cls;
     322             :   struct TALER_TESTING_Trait traits[] = {
     323           0 :     TALER_TESTING_make_trait_process (&dos->proc),
     324           0 :     TALER_TESTING_trait_end ()
     325             :   };
     326             : 
     327           0 :   return TALER_TESTING_get_trait (traits,
     328             :                                   ret,
     329             :                                   trait,
     330             :                                   index);
     331             : }
     332             : 
     333             : 
     334             : /**
     335             :  * Run a "delete object" CMD.
     336             :  *
     337             :  * @param cls closure.
     338             :  * @param cmd the command being run.
     339             :  * @param is the interpreter state.
     340             :  */
     341             : static void
     342           0 : delete_object_run (void *cls,
     343             :                    const struct TALER_TESTING_Command *cmd,
     344             :                    struct TALER_TESTING_Interpreter *is)
     345             : {
     346           0 :   struct DeleteObjectState *dos = cls;
     347             : 
     348           0 :   dos->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     349             :                                        NULL, NULL, NULL,
     350             :                                        "taler-twister",
     351             :                                        "taler-twister",
     352             :                                        "-c", dos->config_filename,
     353             :                                        "--deleteobject", dos->path,
     354             :                                        NULL);
     355           0 :   if (NULL == dos->proc)
     356             :   {
     357           0 :     GNUNET_break (0);
     358           0 :     TALER_TESTING_interpreter_fail (is);
     359           0 :     return;
     360             :   }
     361           0 :   TALER_TESTING_wait_for_sigchld (is);
     362             : }
     363             : 
     364             : 
     365             : /**
     366             :  * Free the state from a "modify object" CMD, and
     367             :  * possibly kill its process if it did not terminate yet.
     368             :  *
     369             :  * @param cls closure.
     370             :  * @param cmd the command being cleaned up.
     371             :  */
     372             : static void
     373           0 : modify_object_cleanup (void *cls,
     374             :                        const struct TALER_TESTING_Command *cmd)
     375             : {
     376           0 :   struct ModifyObjectState *mos = cls;
     377             : 
     378           0 :   if (NULL != mos->proc)
     379             :   {
     380           0 :     GNUNET_break (0 == GNUNET_OS_process_kill (mos->proc,
     381             :                                                SIGKILL));
     382           0 :     GNUNET_OS_process_wait (mos->proc);
     383           0 :     GNUNET_OS_process_destroy (mos->proc);
     384           0 :     mos->proc = NULL;
     385             :   }
     386           0 :   GNUNET_free (mos);
     387           0 : }
     388             : 
     389             : 
     390             : /**
     391             :  * Offer data internal to a "modify object" CMD,
     392             :  * to other commands.
     393             :  *
     394             :  * @param cls closure
     395             :  * @param[out] ret result (could be anything)
     396             :  * @param trait name of the trait
     397             :  * @param index index number of the object to offer.
     398             :  * @return #GNUNET_OK on success
     399             :  */
     400             : static enum GNUNET_GenericReturnValue
     401           0 : modify_object_traits (void *cls,
     402             :                       const void **ret,
     403             :                       const char *trait,
     404             :                       unsigned int index)
     405             : {
     406             : 
     407           0 :   struct ModifyObjectState *mos = cls;
     408             :   struct TALER_TESTING_Trait traits[] = {
     409           0 :     TALER_TESTING_make_trait_process (&mos->proc),
     410           0 :     TALER_TESTING_trait_end ()
     411             :   };
     412             : 
     413           0 :   return TALER_TESTING_get_trait (traits,
     414             :                                   ret,
     415             :                                   trait,
     416             :                                   index);
     417             : }
     418             : 
     419             : 
     420             : /**
     421             :  * Run a "modify object" CMD.  The "download fashion" of it.
     422             :  *
     423             :  * @param cls closure.
     424             :  * @param cmd the command being run.
     425             :  * @param is the interpreter state.
     426             :  */
     427             : static void
     428           0 : modify_object_dl_run (void *cls,
     429             :                       const struct TALER_TESTING_Command *cmd,
     430             :                       struct TALER_TESTING_Interpreter *is)
     431             : {
     432           0 :   struct ModifyObjectState *mos = cls;
     433             : 
     434           0 :   mos->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     435             :                                        NULL, NULL, NULL,
     436             :                                        "taler-twister",
     437             :                                        "taler-twister",
     438             :                                        "-c", mos->config_filename,
     439             :                                        "-m", mos->path,
     440             :                                        "--value", mos->value,
     441             :                                        NULL);
     442           0 :   if (NULL == mos->proc)
     443             :   {
     444           0 :     GNUNET_break (0);
     445           0 :     TALER_TESTING_interpreter_fail (is);
     446           0 :     return;
     447             :   }
     448           0 :   TALER_TESTING_wait_for_sigchld (is);
     449             : }
     450             : 
     451             : 
     452             : /**
     453             :  * Run a "modify object" CMD, the "upload fashion" of it.
     454             :  *
     455             :  * @param cls closure.
     456             :  * @param cmd the command being run.
     457             :  * @param is the interpreter state.
     458             :  */
     459             : static void
     460           0 : modify_object_ul_run (void *cls,
     461             :                       const struct TALER_TESTING_Command *cmd,
     462             :                       struct TALER_TESTING_Interpreter *is)
     463             : {
     464           0 :   struct ModifyObjectState *mos = cls;
     465             : 
     466           0 :   mos->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     467             :                                        NULL, NULL, NULL,
     468             :                                        "taler-twister",
     469             :                                        "taler-twister",
     470             :                                        "-c", mos->config_filename,
     471             :                                        "-X", mos->path,
     472             :                                        "--value", mos->value,
     473             :                                        NULL);
     474           0 :   if (NULL == mos->proc)
     475             :   {
     476           0 :     GNUNET_break (0);
     477           0 :     TALER_TESTING_interpreter_fail (is);
     478           0 :     return;
     479             :   }
     480           0 :   TALER_TESTING_wait_for_sigchld (is);
     481             : }
     482             : 
     483             : 
     484             : /**
     485             :  * Run a "modify header" CMD
     486             :  *
     487             :  * @param cls closure.
     488             :  * @param cmd the command being run.
     489             :  * @param is the interpreter state.
     490             :  */
     491             : static void
     492           0 : modify_header_dl_run (void *cls,
     493             :                       const struct TALER_TESTING_Command *cmd,
     494             :                       struct TALER_TESTING_Interpreter *is)
     495             : {
     496           0 :   struct ModifyObjectState *mos = cls;
     497             : 
     498           0 :   mos->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     499             :                                        NULL, NULL, NULL,
     500             :                                        "taler-twister",
     501             :                                        "taler-twister",
     502             :                                        "-H", mos->path,
     503             :                                        "--value", mos->value,
     504             :                                        "-c", mos->config_filename,
     505             :                                        NULL);
     506           0 :   if (NULL == mos->proc)
     507             :   {
     508           0 :     GNUNET_break (0);
     509           0 :     TALER_TESTING_interpreter_fail (is);
     510           0 :     return;
     511             :   }
     512           0 :   TALER_TESTING_wait_for_sigchld (is);
     513             : }
     514             : 
     515             : 
     516             : struct TALER_TESTING_Command
     517           0 : TALER_TESTING_cmd_delete_object (const char *label,
     518             :                                  const char *config_filename,
     519             :                                  const char *path)
     520             : {
     521             :   struct DeleteObjectState *dos;
     522             : 
     523           0 :   dos = GNUNET_new (struct DeleteObjectState);
     524           0 :   dos->path = path;
     525           0 :   dos->config_filename = config_filename;
     526             : 
     527           0 :   struct TALER_TESTING_Command cmd = {
     528             :     .label = label,
     529             :     .run = &delete_object_run,
     530             :     .cleanup = &delete_object_cleanup,
     531             :     .traits = &delete_object_traits,
     532             :     .cls = dos
     533             :   };
     534             : 
     535           0 :   return cmd;
     536             : }
     537             : 
     538             : 
     539             : /**
     540             :  * Free the state from a "flip object" CMD, and
     541             :  * possibly kill its process if it did not terminate yet.
     542             :  *
     543             :  * @param cls closure.
     544             :  * @param cmd the command being cleaned up.
     545             :  */
     546             : static void
     547           0 : flip_object_cleanup
     548             :   (void *cls,
     549             :   const struct TALER_TESTING_Command *cmd)
     550             : {
     551           0 :   struct FlipObjectState *fos = cls;
     552             : 
     553           0 :   if (NULL != fos->proc)
     554             :   {
     555           0 :     GNUNET_break (0 == GNUNET_OS_process_kill (fos->proc,
     556             :                                                SIGKILL));
     557           0 :     GNUNET_OS_process_wait (fos->proc);
     558           0 :     GNUNET_OS_process_destroy (fos->proc);
     559           0 :     fos->proc = NULL;
     560             :   }
     561           0 :   GNUNET_free (fos);
     562           0 : }
     563             : 
     564             : 
     565             : /**
     566             :  * Offer data internal to a "flip object" CMD,
     567             :  * to other commands.
     568             :  *
     569             :  * @param cls closure
     570             :  * @param[out] ret result (could be anything)
     571             :  * @param trait name of the trait
     572             :  * @param index index number of the object to offer.
     573             :  * @return #GNUNET_OK on success
     574             :  */
     575             : static int
     576           0 : flip_object_traits (void *cls,
     577             :                     const void **ret,
     578             :                     const char *trait,
     579             :                     unsigned int index)
     580             : {
     581           0 :   struct FlipObjectState *fos = cls;
     582             :   struct TALER_TESTING_Trait traits[] = {
     583           0 :     TALER_TESTING_make_trait_process (&fos->proc),
     584           0 :     TALER_TESTING_trait_end ()
     585             :   };
     586             : 
     587           0 :   return TALER_TESTING_get_trait (traits,
     588             :                                   ret,
     589             :                                   trait,
     590             :                                   index);
     591             : }
     592             : 
     593             : 
     594             : /**
     595             :  * Run a "flip object" CMD, the upload fashion of it.
     596             :  *
     597             :  * @param cls closure.
     598             :  * @param cmd the command being run.
     599             :  * @param is the interpreter state.
     600             :  */
     601             : static void
     602           0 : flip_upload_run (void *cls,
     603             :                  const struct TALER_TESTING_Command *cmd,
     604             :                  struct TALER_TESTING_Interpreter *is)
     605             : {
     606           0 :   struct FlipObjectState *fos = cls;
     607             : 
     608           0 :   fos->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     609             :                                        NULL, NULL, NULL,
     610             :                                        "taler-twister",
     611             :                                        "taler-twister",
     612             :                                        "-c", fos->config_filename,
     613             :                                        "--flip-ul", fos->path,
     614             :                                        NULL);
     615           0 :   if (NULL == fos->proc)
     616             :   {
     617           0 :     GNUNET_break (0);
     618           0 :     TALER_TESTING_interpreter_fail (is);
     619           0 :     return;
     620             :   }
     621           0 :   TALER_TESTING_wait_for_sigchld (is);
     622             : }
     623             : 
     624             : 
     625             : /**
     626             :  * Run a "flip object" CMD, the download fashion of it.
     627             :  *
     628             :  * @param cls closure.
     629             :  * @param cmd the command being run.
     630             :  * @param is the interpreter state.
     631             :  */
     632             : static void
     633           0 : flip_download_run (void *cls,
     634             :                    const struct TALER_TESTING_Command *cmd,
     635             :                    struct TALER_TESTING_Interpreter *is)
     636             : {
     637           0 :   struct FlipObjectState *fos = cls;
     638             : 
     639           0 :   fos->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     640             :                                        NULL, NULL, NULL,
     641             :                                        "taler-twister",
     642             :                                        "taler-twister",
     643             :                                        "-c", fos->config_filename,
     644             :                                        "--flip-dl", fos->path,
     645             :                                        NULL);
     646           0 :   if (NULL == fos->proc)
     647             :   {
     648           0 :     GNUNET_break (0);
     649           0 :     TALER_TESTING_interpreter_fail (is);
     650           0 :     return;
     651             :   }
     652           0 :   TALER_TESTING_wait_for_sigchld (is);
     653             : }
     654             : 
     655             : 
     656             : struct TALER_TESTING_Command
     657           0 : TALER_TESTING_cmd_flip_upload (const char *label,
     658             :                                const char *config_filename,
     659             :                                const char *path)
     660             : {
     661             :   struct FlipObjectState *dos;
     662             : 
     663           0 :   dos = GNUNET_new (struct FlipObjectState);
     664           0 :   dos->path = path;
     665           0 :   dos->config_filename = config_filename;
     666             :   {
     667           0 :     struct TALER_TESTING_Command cmd = {
     668             :       .label = label,
     669             :       .run = &flip_upload_run,
     670             :       .cleanup = &flip_object_cleanup,
     671             :       .traits = &flip_object_traits,
     672             :       .cls = dos
     673             :     };
     674             : 
     675           0 :     return cmd;
     676             :   }
     677             : }
     678             : 
     679             : 
     680             : struct TALER_TESTING_Command
     681           0 : TALER_TESTING_cmd_flip_download (const char *label,
     682             :                                  const char *config_filename,
     683             :                                  const char *path)
     684             : {
     685             :   struct FlipObjectState *dos;
     686             : 
     687           0 :   dos = GNUNET_new (struct FlipObjectState);
     688           0 :   dos->path = path;
     689           0 :   dos->config_filename = config_filename;
     690             :   {
     691           0 :     struct TALER_TESTING_Command cmd = {
     692             :       .label = label,
     693             :       .run = &flip_download_run,
     694             :       .cleanup = &flip_object_cleanup,
     695             :       .traits = &flip_object_traits,
     696             :       .cls = dos
     697             :     };
     698             : 
     699           0 :     return cmd;
     700             :   }
     701             : }
     702             : 
     703             : 
     704             : /**
     705             :  * Free the state from a "malform request" CMD, and
     706             :  * possibly kill its process if it did not terminate yet.
     707             :  *
     708             :  * @param cls closure.
     709             :  * @param cmd the command being cleaned up.
     710             :  */
     711             : static void
     712           0 : malform_request_cleanup (void *cls,
     713             :                          const struct TALER_TESTING_Command *cmd)
     714             : {
     715           0 :   struct MalformRequestState *mrs = cls;
     716             : 
     717           0 :   if (NULL != mrs->proc)
     718             :   {
     719           0 :     GNUNET_break (0 == GNUNET_OS_process_kill (mrs->proc,
     720             :                                                SIGKILL));
     721           0 :     GNUNET_OS_process_wait (mrs->proc);
     722           0 :     GNUNET_OS_process_destroy (mrs->proc);
     723           0 :     mrs->proc = NULL;
     724             :   }
     725           0 :   GNUNET_free (mrs);
     726           0 : }
     727             : 
     728             : 
     729             : /**
     730             :  * Offer data internal to a "malform request" CMD,
     731             :  * to other commands.
     732             :  *
     733             :  * @param cls closure
     734             :  * @param[out] ret result (could be anything)
     735             :  * @param trait name of the trait
     736             :  * @param index index number of the object to offer.
     737             :  * @return #GNUNET_OK on success
     738             :  */
     739             : static enum GNUNET_GenericReturnValue
     740           0 : malform_request_traits (void *cls,
     741             :                         const void **ret,
     742             :                         const char *trait,
     743             :                         unsigned int index)
     744             : {
     745           0 :   struct MalformRequestState *mrs = cls;
     746             :   struct TALER_TESTING_Trait traits[] = {
     747           0 :     TALER_TESTING_make_trait_process (&mrs->proc),
     748           0 :     TALER_TESTING_trait_end ()
     749             :   };
     750             : 
     751           0 :   return TALER_TESTING_get_trait (traits,
     752             :                                   ret,
     753             :                                   trait,
     754             :                                   index);
     755             : }
     756             : 
     757             : 
     758             : /**
     759             :  * Run a "malform request" CMD.
     760             :  *
     761             :  * @param cls closure.
     762             :  * @param cmd the command being run.
     763             :  * @param is the interpreter state.
     764             :  */
     765             : static void
     766           0 : malform_request_run (void *cls,
     767             :                      const struct TALER_TESTING_Command *cmd,
     768             :                      struct TALER_TESTING_Interpreter *is)
     769             : {
     770           0 :   struct MalformRequestState *mrs = cls;
     771             : 
     772           0 :   mrs->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     773             :                                        NULL, NULL, NULL,
     774             :                                        "taler-twister",
     775             :                                        "taler-twister",
     776             :                                        "-c", mrs->config_filename,
     777             :                                        "--malformupload",
     778             :                                        NULL);
     779           0 :   if (NULL == mrs->proc)
     780             :   {
     781           0 :     GNUNET_break (0);
     782           0 :     TALER_TESTING_interpreter_fail (is);
     783           0 :     return;
     784             :   }
     785           0 :   TALER_TESTING_wait_for_sigchld (is);
     786             : }
     787             : 
     788             : 
     789             : /**
     790             :  * Free the state from a "malform response" CMD, and
     791             :  * possibly kill its process if it did not terminate yet.
     792             :  *
     793             :  * @param cls closure.
     794             :  * @param cmd the command being cleaned up.
     795             :  */
     796             : static void
     797           1 : malform_response_cleanup (void *cls,
     798             :                           const struct TALER_TESTING_Command *cmd)
     799             : {
     800           1 :   struct MalformResponseState *mrs = cls;
     801             : 
     802           1 :   if (NULL != mrs->proc)
     803             :   {
     804           0 :     GNUNET_break (0 == GNUNET_OS_process_kill (mrs->proc,
     805             :                                                SIGKILL));
     806           0 :     GNUNET_OS_process_wait (mrs->proc);
     807           0 :     GNUNET_OS_process_destroy (mrs->proc);
     808           0 :     mrs->proc = NULL;
     809             :   }
     810           1 :   GNUNET_free (mrs);
     811           1 : }
     812             : 
     813             : 
     814             : /**
     815             :  * Offer data internal to a "malform response" CMD,
     816             :  * to other commands.
     817             :  *
     818             :  * @param cls closure
     819             :  * @param[out] ret result (could be anything)
     820             :  * @param trait name of the trait
     821             :  * @param index index number of the object to offer.
     822             :  * @return #GNUNET_OK on success
     823             :  */
     824             : static enum GNUNET_GenericReturnValue
     825           1 : malform_response_traits (void *cls,
     826             :                          const void **ret,
     827             :                          const char *trait,
     828             :                          unsigned int index)
     829             : {
     830           1 :   struct MalformResponseState *mrs = cls;
     831             :   struct TALER_TESTING_Trait traits[] = {
     832           1 :     TALER_TESTING_make_trait_process (&mrs->proc),
     833           1 :     TALER_TESTING_trait_end ()
     834             :   };
     835             : 
     836           1 :   return TALER_TESTING_get_trait (traits,
     837             :                                   ret,
     838             :                                   trait,
     839             :                                   index);
     840             : }
     841             : 
     842             : 
     843             : /**
     844             :  * Run a "malform response" CMD.
     845             :  *
     846             :  * @param cls closure.
     847             :  * @param cmd the command being run.
     848             :  * @param is the interpreter state.
     849             :  */
     850             : static void
     851           1 : malform_response_run (void *cls,
     852             :                       const struct TALER_TESTING_Command *cmd,
     853             :                       struct TALER_TESTING_Interpreter *is)
     854             : {
     855           1 :   struct MalformResponseState *mrs = cls;
     856             : 
     857           1 :   mrs->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     858             :                                        NULL, NULL, NULL,
     859             :                                        "taler-twister",
     860             :                                        "taler-twister",
     861             :                                        "-c", mrs->config_filename,
     862             :                                        "--malform",
     863             :                                        NULL);
     864           1 :   if (NULL == mrs->proc)
     865             :   {
     866           0 :     GNUNET_break (0);
     867           0 :     TALER_TESTING_interpreter_fail (is);
     868           0 :     return;
     869             :   }
     870           1 :   TALER_TESTING_wait_for_sigchld (is);
     871             : }
     872             : 
     873             : 
     874             : struct TALER_TESTING_Command
     875           0 : TALER_TESTING_cmd_malform_request (const char *label,
     876             :                                    const char *config_filename)
     877             : {
     878             :   struct MalformRequestState *mrs;
     879             : 
     880           0 :   mrs = GNUNET_new (struct MalformRequestState);
     881           0 :   mrs->config_filename = config_filename;
     882             :   {
     883           0 :     struct TALER_TESTING_Command cmd = {
     884             :       .label = label,
     885             :       .run = &malform_request_run,
     886             :       .cleanup = &malform_request_cleanup,
     887             :       .traits = &malform_request_traits,
     888             :       .cls = mrs
     889             :     };
     890             : 
     891           0 :     return cmd;
     892             :   }
     893             : }
     894             : 
     895             : 
     896             : struct TALER_TESTING_Command
     897           1 : TALER_TESTING_cmd_malform_response (const char *label,
     898             :                                     const char *config_filename)
     899             : {
     900             :   struct MalformResponseState *mrs;
     901             : 
     902           1 :   mrs = GNUNET_new (struct MalformResponseState);
     903           1 :   mrs->config_filename = config_filename;
     904             : 
     905           1 :   struct TALER_TESTING_Command cmd = {
     906             :     .label = label,
     907             :     .run = &malform_response_run,
     908             :     .cleanup = &malform_response_cleanup,
     909             :     .traits = &malform_response_traits,
     910             :     .cls = mrs
     911             :   };
     912             : 
     913           1 :   return cmd;
     914             : 
     915             : }
     916             : 
     917             : 
     918             : struct TALER_TESTING_Command
     919           0 : TALER_TESTING_cmd_modify_object_dl (const char *label,
     920             :                                     const char *config_filename,
     921             :                                     const char *path,
     922             :                                     const char *value)
     923             : {
     924             :   struct ModifyObjectState *mos;
     925             : 
     926           0 :   mos = GNUNET_new (struct ModifyObjectState);
     927           0 :   mos->path = path;
     928           0 :   mos->value = value;
     929           0 :   mos->config_filename = config_filename;
     930             :   {
     931           0 :     struct TALER_TESTING_Command cmd = {
     932             :       .label = label,
     933             :       .run = &modify_object_dl_run,
     934             :       .cleanup = &modify_object_cleanup,
     935             :       .traits = &modify_object_traits,
     936             :       .cls = mos
     937             :     };
     938             : 
     939           0 :     return cmd;
     940             :   }
     941             : }
     942             : 
     943             : 
     944             : struct TALER_TESTING_Command
     945           0 : TALER_TESTING_cmd_modify_object_ul (const char *label,
     946             :                                     const char *config_filename,
     947             :                                     const char *path,
     948             :                                     const char *value)
     949             : {
     950             :   struct ModifyObjectState *mos;
     951             : 
     952           0 :   mos = GNUNET_new (struct ModifyObjectState);
     953           0 :   mos->path = path;
     954           0 :   mos->value = value;
     955           0 :   mos->config_filename = config_filename;
     956             :   {
     957           0 :     struct TALER_TESTING_Command cmd = {
     958             :       .label = label,
     959             :       .run = &modify_object_ul_run,
     960             :       .cleanup = &modify_object_cleanup,
     961             :       .traits = &modify_object_traits,
     962             :       .cls = mos
     963             :     };
     964             : 
     965           0 :     return cmd;
     966             :   }
     967             : }
     968             : 
     969             : 
     970             : struct TALER_TESTING_Command
     971           0 : TALER_TESTING_cmd_modify_header_dl (const char *label,
     972             :                                     const char *config_filename,
     973             :                                     const char *path,
     974             :                                     const char *value)
     975             : {
     976             :   struct ModifyObjectState *mos;
     977             : 
     978           0 :   mos = GNUNET_new (struct ModifyObjectState);
     979           0 :   mos->path = path;
     980           0 :   mos->value = value;
     981           0 :   mos->config_filename = config_filename;
     982             :   {
     983           0 :     struct TALER_TESTING_Command cmd = {
     984             :       .label = label,
     985             :       .run = &modify_header_dl_run,
     986             :       .cleanup = &modify_object_cleanup,
     987             :       .traits = &modify_object_traits,
     988             :       .cls = mos
     989             :     };
     990             : 
     991           0 :     return cmd;
     992             :   }
     993             : }
     994             : 
     995             : 
     996             : /* end of testing_api_cmd_exec_client.c */

Generated by: LCOV version 1.14