twister

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

commit 3bceec019b0bb732b6414c9e11fb60839f49b21b
parent 8fbd7583ac35df5e8f8af5088544e5360b59ed77
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Thu, 22 Mar 2018 17:11:46 +0100

add string-object flipper testing command.

Diffstat:
Msrc/include/taler_twister_testing_lib.h | 14++++++++++++++
Msrc/twister/taler-twister-service.c | 8++++----
Msrc/twister/testing_api_cmd_exec_client.c | 136+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 152 insertions(+), 6 deletions(-)

diff --git a/src/include/taler_twister_testing_lib.h b/src/include/taler_twister_testing_lib.h @@ -108,4 +108,18 @@ struct TALER_TESTING_Command TALER_TESTING_cmd_malform_request (const char *label, const char *config_filename); +/** + * This command deletes the JSON object pointed by @a path. + * + * @param label command label + * @param config_filename configuration filename. + * @param path object-like path notation to point the object + * to delete. + * + * @return the command + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_flip_object (const char *label, + const char *config_filename, + const char *path); #endif diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c @@ -1061,6 +1061,10 @@ flip_object (struct MHD_Connection *con, /* flip the LSB. */ current_value_flip[index] ^= 1; + + TALER_LOG_INFO ("Flipping %s to %s\n", + current_value, + current_value_flip); if (0 == json_string_set (child, (const char *) current_value_flip)) @@ -1068,10 +1072,6 @@ flip_object (struct MHD_Connection *con, if (-1 == ret_flip) TALER_LOG_WARNING ("Could not flip '%s'\n", target); - else - TALER_LOG_INFO ("Flipped to %s, from %s\n", - current_value_flip, - current_value); flip_path[0] = '\0'; GNUNET_free (target); diff --git a/src/twister/testing_api_cmd_exec_client.c b/src/twister/testing_api_cmd_exec_client.c @@ -51,6 +51,24 @@ struct ModifyObjectState }; +struct FlipObjectState +{ + /** + * Process handle for the twister CLI client. + */ + struct GNUNET_OS_Process *proc; + + /** + * Object-like notation to the object to delete. + */ + const char *path; + + /** + * Config file name to pass to the CLI client. + */ + const char *config_filename; +}; + struct DeleteObjectState { /** @@ -396,8 +414,6 @@ modify_object_run (void *cls, TALER_TESTING_wait_for_sigchld (is); } - - /** * This command deletes the JSON object pointed by @a path. * @@ -430,6 +446,122 @@ TALER_TESTING_cmd_delete_object (const char *label, } +////// + +/** + * Clean up after the command. Run during forced termination + * (CTRL-C) or test failure or test success. + * + * @param cls closure + */ +static void +flip_object_cleanup + (void *cls, + const struct TALER_TESTING_Command *cmd) +{ + struct FlipObjectState *fos = cls; + + if (NULL != fos->proc) + { + GNUNET_break (0 == GNUNET_OS_process_kill (fos->proc, + SIGKILL)); + GNUNET_OS_process_wait (fos->proc); + GNUNET_OS_process_destroy (fos->proc); + fos->proc = NULL; + } + GNUNET_free (fos); +} + +/** + * 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 +flip_object_traits (void *cls, + void **ret, + const char *trait, + unsigned int index) +{ + + struct FlipObjectState *fos = cls; + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_process (0, &fos->proc), + TALER_TESTING_trait_end () + }; + + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); +} + +/** + * FIXME: document. + */ +static void +flip_object_run (void *cls, + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) +{ + struct FlipObjectState *fos = cls; + + fos->proc = GNUNET_OS_start_process (GNUNET_NO, + GNUNET_OS_INHERIT_STD_ALL, + NULL, NULL, NULL, + "taler-twister", + "taler-twister", + "-c", fos->config_filename, + "--flip", fos->path, + NULL); + if (NULL == fos->proc) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + TALER_TESTING_wait_for_sigchld (is); +} + +/** + * This command deletes the JSON object pointed by @a path. + * + * @param label command label + * @param config_filename configuration filename. + * @param path object-like path notation to point the object + * to delete. + * + * @return the command + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_flip_object (const char *label, + const char *config_filename, + const char *path) +{ + struct FlipObjectState *dos; + struct TALER_TESTING_Command cmd; + + dos = GNUNET_new (struct FlipObjectState); + dos->path = path; + dos->config_filename = config_filename; + + cmd.label = label; + cmd.run = &flip_object_run; + cmd.cleanup = &flip_object_cleanup; + cmd.traits = &flip_object_traits; + cmd.cls = dos; + + return cmd; +} + + /** * TODO. */