All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: Jason Baron <jbaron@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, andreas.faerber@web.de,
	blauwirbel@gmail.com, quintela@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 2/3] qtest: extend qtest_qmp() to fill in the reply
Date: Mon, 07 Jan 2013 14:04:02 -0600	[thread overview]
Message-ID: <87lic4u5e5.fsf@codemonkey.ws> (raw)
In-Reply-To: <99b3e20143db7c301424b2b8410fdf6b19aa59bf.1356022464.git.jbaron@redhat.com>

Jason Baron <jbaron@redhat.com> writes:

> From: Jason Baron <jbaron@redhat.com>
>
> Introduce:
>
> Add void qtest_qmp_resp(QTestState *s, QString *resp, const char *fmt,
> ...)

Any reason to not just return a QString?

Also, why not do the parsing in this function and just return a QObject
of the result?

Regards,

Anthony Liguori

>
> which allows a response string to be filled in.
>
> Signed-off-by: Jason Baron <jbaron@redhat.com>
> ---
>  tests/Makefile   |    2 +-
>  tests/libqtest.c |   17 ++++++++++-------
>  tests/libqtest.h |   15 +++++++++++++--
>  3 files changed, 24 insertions(+), 10 deletions(-)
>
> diff --git a/tests/Makefile b/tests/Makefile
> index b60f0fb..1756b47 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -85,7 +85,7 @@ TARGETS=$(patsubst %-softmmu,%, $(filter %-softmmu,$(TARGET_DIRS)))
>  QTEST_TARGETS=$(foreach TARGET,$(TARGETS), $(if $(check-qtest-$(TARGET)-y), $(TARGET),))
>  check-qtest-$(CONFIG_POSIX)=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)-y))
>  
> -qtest-obj-y = tests/libqtest.o $(oslib-obj-y) libqemustub.a
> +qtest-obj-y = tests/libqtest.o $(oslib-obj-y) libqemustub.a $(test-qapi-obj-y) $(qom-obj-y)
>  $(check-qtest-y): $(qtest-obj-y)
>  
>  .PHONY: check-help
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 57665c9..994cd2f 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -288,7 +288,7 @@ redo:
>      return words;
>  }
>  
> -void qtest_qmp(QTestState *s, const char *fmt, ...)
> +void qtest_qmp_resp(QTestState *s, QString *resp, const char *fmt, ...)
>  {
>      va_list ap;
>      bool has_reply = false;
> @@ -313,16 +313,19 @@ void qtest_qmp(QTestState *s, const char *fmt, ...)
>              fprintf(stderr, "Broken pipe\n");
>              exit(1);
>          }
> -
> -        switch (c) {
> -        case '{':
> +        if (c == '{') {
>              nesting++;
>              has_reply = true;
> -            break;
> -        case '}':
> +        }
> +        if (c == '}') {
>              nesting--;
> -            break;
>          }
> +        if (has_reply && resp) {
> +            qstring_append_chr(resp, c);
> +        }
> +    }
> +    if (has_reply && resp) {
> +        qstring_append_chr(resp, '\0');
>      }
>  }
>  
> diff --git a/tests/libqtest.h b/tests/libqtest.h
> index c8ade85..972ba5d 100644
> --- a/tests/libqtest.h
> +++ b/tests/libqtest.h
> @@ -18,6 +18,7 @@
>  #include <stdint.h>
>  #include <stdbool.h>
>  #include <sys/types.h>
> +#include "qstring.h"
>  
>  typedef struct QTestState QTestState;
>  
> @@ -38,13 +39,14 @@ QTestState *qtest_init(const char *extra_args);
>  void qtest_quit(QTestState *s);
>  
>  /**
> - * qtest_qmp:
> + * qtest_qmp_resp:
>   * @s: QTestState instance to operate on.
> + * @resp: Fills in response string if provided
>   * @fmt...: QMP message to send to qemu
>   *
>   * Sends a QMP message to QEMU
>   */
> -void qtest_qmp(QTestState *s, const char *fmt, ...);
> +void qtest_qmp_resp(QTestState *s, QString *resp, const char *fmt, ...);
>  
>  /**
>   * qtest_get_irq:
> @@ -349,4 +351,13 @@ void qtest_add_func(const char *str, void (*fn));
>   */
>  #define clock_set(val) qtest_clock_set(global_qtest, val)
>  
> +/**
> + * qtest_qmp:
> + * @s: QTestState instance to operate on.
> + * @fmt...: QMP message to send to qemu
> + *
> + * Sends a QMP message to QEMU
> + */
> +#define qtest_qmp(s, fmt, ...) qtest_qmp_resp(s, NULL, fmt, ## __VA_ARGS__)
> +
>  #endif
> -- 
> 1.7.1

      reply	other threads:[~2013-01-07 20:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-20 17:14 [Qemu-devel] [PATCH v2 0/3] qtest: add migration testing Jason Baron
2012-12-20 17:14 ` [Qemu-devel] [PATCH v2 1/3] qtest: Enable creation of multiple qemu instances Jason Baron
2012-12-20 20:07   ` Blue Swirl
2012-12-20 20:26     ` Jason Baron
2012-12-20 20:38       ` Blue Swirl
2012-12-21  7:47       ` Markus Armbruster
2012-12-20 17:14 ` [Qemu-devel] [PATCH v2 3/3] qtest: add migrate-test Jason Baron
2012-12-20 20:17   ` Blue Swirl
2012-12-20 17:14 ` [Qemu-devel] [PATCH v2 2/3] qtest: extend qtest_qmp() to fill in the reply Jason Baron
2013-01-07 20:04   ` Anthony Liguori [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lic4u5e5.fsf@codemonkey.ws \
    --to=aliguori@us.ibm.com \
    --cc=andreas.faerber@web.de \
    --cc=blauwirbel@gmail.com \
    --cc=jbaron@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.