twister

HTTP fault injector for testing
Log | Files | Refs | README | LICENSE

commit 7bf67d2022d6acadbf5beda3d030ccfb4d2238be
parent 3952ac7133bca700817dfa18a24adbc1116d9aed
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Wed,  7 Mar 2018 14:35:14 +0100

test command to empty objects.

Diffstat:
Msrc/include/taler_twister_testing_lib.h | 16++++++++++++++++
Msrc/twister/testing_api_cmd_exec_client.c | 135+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 151 insertions(+), 0 deletions(-)

diff --git a/src/include/taler_twister_testing_lib.h b/src/include/taler_twister_testing_lib.h @@ -47,5 +47,21 @@ TALER_TESTING_cmd_hack_response_code (const char *label, unsigned int http_status); +/** + * This command replaces the JSON object contained in the + * response and pointed by @a path, with a empty one ("{}"). + * + * @param label command label + * @param config_filename configuration filename. + * @param path object-like path notation to point the object + * to be made empty. "f1.0.f2" will empty the object + * {"f1": [{"f2": {will be emptied. }}]}. + * + * @return the command + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_empty_object (const char *label, + const char *config_filename, + const char *path); #endif diff --git a/src/twister/testing_api_cmd_exec_client.c b/src/twister/testing_api_cmd_exec_client.c @@ -29,6 +29,25 @@ #include <taler/taler_testing_lib.h> #include "taler_twister_testing_lib.h" +struct EmptyObjectState +{ + /** + * Process handle for the twister CLI client. + */ + struct GNUNET_OS_Process *proc; + + /** + * Object-like notation to the object to make empty. + */ + const char *path; + + /** + * Config file name to pass to the CLI client. + */ + const char *config_filename; +}; + + struct HackResponseCodeState { /** @@ -164,3 +183,119 @@ TALER_TESTING_cmd_hack_response_code (const char *label, return cmd; } + +/** + * Clean up after the command. Run during forced termination + * (CTRL-C) or test failure or test success. + * + * @param cls closure + */ +static void +empty_object_cleanup + (void *cls, + const struct TALER_TESTING_Command *cmd) +{ + struct EmptyObjectState *eos = cls; + + if (NULL != eos->proc) + { + GNUNET_break (0 == GNUNET_OS_process_kill (eos->proc, + SIGKILL)); + GNUNET_OS_process_wait (eos->proc); + GNUNET_OS_process_destroy (eos->proc); + eos->proc = NULL; + } + GNUNET_free (eos); +} + +/** + * Extract information from a command that is useful for other + * commands. + * + * @param cls closure + * @param ret[out] result (could be anything) + * @param trait name of the trait + * @param selector more detailed information about which object + * to return in case there were multiple generated + * by the command + * @return #GNUNET_OK on success + */ +static int +empty_object_traits (void *cls, + void **ret, + const char *trait, + unsigned int index) +{ + + struct EmptyObjectState *eos = cls; + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_process (0, &eos->proc), + TALER_TESTING_trait_end () + }; + + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); +} + + +/** + * FIXME: document. + */ +static void +empty_object_run (void *cls, + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) +{ + struct EmptyObjectState *eos = cls; + + eos->proc = GNUNET_OS_start_process (GNUNET_NO, + GNUNET_OS_INHERIT_STD_ALL, + NULL, NULL, NULL, + "taler-twister", + "taler-twister", + "-c", eos->config_filename, + "--emptyobject", eos->path, + NULL); + if (NULL == eos->proc) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + TALER_TESTING_wait_for_sigchld (is); +} + + +/** + * This command replaces the JSON object contained in the + * response and pointed by @a path, with a empty one ("{}"). + * + * @param label command label + * @param config_filename configuration filename. + * @param path object-like path notation to point the object + * to be made empty. + * + * @return the command + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_empty_object (const char *label, + const char *config_filename, + const char *path) +{ + struct EmptyObjectState *eos; + struct TALER_TESTING_Command cmd; + + eos = GNUNET_new (struct EmptyObjectState); + eos->path = path; + eos->config_filename = config_filename; + + cmd.label = label; + cmd.run = &empty_object_run; + cmd.cleanup = &empty_object_cleanup; + cmd.traits = &empty_object_traits; + cmd.cls = eos; + + return cmd; +}