[libvirt] [PATCH v2 07/11] tests: qemu: monitor: Add helpers to test full command syntax

Pavel Hrdina phrdina at redhat.com
Thu Jan 12 12:44:08 UTC 2017


On Wed, Jan 11, 2017 at 10:48:17AM +0100, Peter Krempa wrote:
> Add test monitor infrastructure that will test the commands verbatim
> rather than trying to do any smart handling.
> ---
>  tests/qemumonitortestutils.c | 89 ++++++++++++++++++++++++++++++++++++++++++++
>  tests/qemumonitortestutils.h |  5 +++
>  2 files changed, 94 insertions(+)
> 
> diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
> index fb4f51c54..50042f960 100644
> --- a/tests/qemumonitortestutils.c
> +++ b/tests/qemumonitortestutils.c
> @@ -508,6 +508,7 @@ struct _qemuMonitorTestCommandArgs {
> 
>  struct qemuMonitorTestHandlerData {
>      char *command_name;
> +    char *cmderr;
>      char *response;
>      size_t nargs;
>      qemuMonitorTestCommandArgsPtr args;
> @@ -529,6 +530,7 @@ qemuMonitorTestHandlerDataFree(void *opaque)
>      }
> 
>      VIR_FREE(data->command_name);
> +    VIR_FREE(data->cmderr);
>      VIR_FREE(data->response);
>      VIR_FREE(data->args);
>      VIR_FREE(data->expectArgs);
> @@ -606,6 +608,93 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
> 
> 
>  static int
> +qemuMonitorTestProcessCommandVerbatim(qemuMonitorTestPtr test,
> +                                      qemuMonitorTestItemPtr item,
> +                                      const char *cmdstr)
> +{
> +    struct qemuMonitorTestHandlerData *data = item->opaque;
> +    char *reformatted = NULL;
> +    char *errmsg = NULL;
> +    int ret = -1;
> +
> +    /* JSON strings will be reformatted to simplify checking */
> +    if (test->json || test->agent) {
> +        if (!(reformatted = virJSONStringReformat(cmdstr, false)))
> +            return -1;
> +
> +        cmdstr = reformatted;
> +    }
> +
> +    if (STREQ(data->command_name, cmdstr)) {
> +        ret = qemuMonitorTestAddResponse(test, data->response);
> +    } else {
> +        if (data->cmderr) {
> +            if (virAsprintf(&errmsg, "%s: %s", data->cmderr, cmdstr) < 0)
> +                goto cleanup;
> +
> +            ret = qemuMonitorTestAddErrorResponse(test, errmsg);
> +        } else {
> +            ret = qemuMonitorTestAddInvalidCommandResponse(test,
> +                                                           data->command_name,
> +                                                           cmdstr);
> +        }
> +    }
> +
> + cleanup:
> +    VIR_FREE(errmsg);
> +    VIR_FREE(reformatted);
> +    return ret;
> +}
> +
> +
> +/**
> + * qemuMonitorTestAddItemVerbatim:
> + * @test: monitor test object
> + * @command: full expected command syntax
> + * @cmderr: possible explanation of expected command (may be NULL)
> + * @response: full reply of @command
> + *
> + * Adds a test command for the simulated monitor. The full syntax is checked
> + * as specified in @command. For JSON monitor tests formatting/whitespace is
> + * ignored. If the command on the monitor is not as expected an error containing
> + * @cmderr is returned. Otherwise @response is put as-is on the monitor.
> + *
> + * Returns 0 when command was succesfully added, -1 on error.

s/succesfully/successfully/

ACK

Pavel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20170112/a9f859d3/attachment-0001.sig>


More information about the libvir-list mailing list