Patchwork [03/12] qtest: return string from QMP commands

login
register
mail settings
Submitter Anthony Liguori
Date June 19, 2013, 8:40 p.m.
Message ID <1371674435-14973-4-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/252654/
State New
Headers show

Comments

Anthony Liguori - June 19, 2013, 8:40 p.m.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 tests/libqtest.c | 16 +++++++++++++---
 tests/libqtest.h | 14 +++++++++++---
 2 files changed, 24 insertions(+), 6 deletions(-)
Andreas Färber - June 20, 2013, 3:24 p.m.
Am 19.06.2013 22:40, schrieb Anthony Liguori:
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
> ---
>  tests/libqtest.c | 16 +++++++++++++---
>  tests/libqtest.h | 14 +++++++++++---
>  2 files changed, 24 insertions(+), 6 deletions(-)
> 
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 81107cf..235ec62 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -287,10 +287,13 @@ redo:
>      return words;
>  }
>  
> -void qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
> +char *qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
>  {
>      bool has_reply = false;
>      int nesting = 0;
> +    GString *ret;
> +
> +    ret = g_string_new("");
>  
>      /* Send QMP request */
>      socket_sendf(s->qmp_fd, fmt, ap);
> @@ -319,16 +322,23 @@ void qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
>              nesting--;
>              break;
>          }
> +
> +        g_string_append_c(ret, c);
>      }
> +
> +    return g_string_free(ret, FALSE);
>  }
>  
> -void qtest_qmp(QTestState *s, const char *fmt, ...)
> +char *qtest_qmp(QTestState *s, const char *fmt, ...)
>  {
>      va_list ap;
> +    char *ret;
>  
>      va_start(ap, fmt);
> -    qtest_qmpv(s, fmt, ap);
> +    ret = qtest_qmpv(s, fmt, ap);
>      va_end(ap);
> +
> +    return ret;
>  }
>  
>  const char *qtest_get_arch(void)
> diff --git a/tests/libqtest.h b/tests/libqtest.h
> index 592f035..5cdcae7 100644
> --- a/tests/libqtest.h
> +++ b/tests/libqtest.h
> @@ -21,6 +21,7 @@
>  #include <stdbool.h>
>  #include <stdarg.h>
>  #include <sys/types.h>
> +#include <glib.h>
>  
>  typedef struct QTestState QTestState;
>  
> @@ -48,8 +49,10 @@ void qtest_quit(QTestState *s);
>   * @fmt...: QMP message to send to qemu
>   *
>   * Sends a QMP message to QEMU
> + *
> + * Returns: the result of the QMP command
>   */
> -void qtest_qmp(QTestState *s, const char *fmt, ...);
> +char *qtest_qmp(QTestState *s, const char *fmt, ...);
>  
>  /**
>   * qtest_qmpv:
> @@ -58,8 +61,10 @@ void qtest_qmp(QTestState *s, const char *fmt, ...);
>   * @ap: QMP message arguments
>   *
>   * Sends a QMP message to QEMU.
> + *
> + * Returns: the result of the QMP command
>   */
> -void qtest_qmpv(QTestState *s, const char *fmt, va_list ap);
> +char *qtest_qmpv(QTestState *s, const char *fmt, va_list ap);
>  
>  /**
>   * qtest_get_irq:
> @@ -340,10 +345,13 @@ static inline QTestState *qtest_start(const char *args)
>  static inline void qmp(const char *fmt, ...)
>  {
>      va_list ap;
> +    char *ret;
>  
>      va_start(ap, fmt);
> -    qtest_qmpv(global_qtest, fmt, ap);
> +    ret = qtest_qmpv(global_qtest, fmt, ap);
>      va_end(ap);
> +
> +    g_free(ret);
>  }
>  
>  /**

In http://patchwork.ozlabs.org/patch/207689/ you had suggested to return
QObject?

Regards,
Andreas
Anthony Liguori - June 20, 2013, 3:43 p.m.
Andreas Färber <afaerber@suse.de> writes:

> Am 19.06.2013 22:40, schrieb Anthony Liguori:
>> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
>> ---
>>  tests/libqtest.c | 16 +++++++++++++---
>>  tests/libqtest.h | 14 +++++++++++---
>>  2 files changed, 24 insertions(+), 6 deletions(-)
>> 
>> diff --git a/tests/libqtest.c b/tests/libqtest.c
>> index 81107cf..235ec62 100644
>> --- a/tests/libqtest.c
>> +++ b/tests/libqtest.c
>> @@ -287,10 +287,13 @@ redo:
>>      return words;
>>  }
>>  
>> -void qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
>> +char *qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
>>  {
>>      bool has_reply = false;
>>      int nesting = 0;
>> +    GString *ret;
>> +
>> +    ret = g_string_new("");
>>  
>>      /* Send QMP request */
>>      socket_sendf(s->qmp_fd, fmt, ap);
>> @@ -319,16 +322,23 @@ void qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
>>              nesting--;
>>              break;
>>          }
>> +
>> +        g_string_append_c(ret, c);
>>      }
>> +
>> +    return g_string_free(ret, FALSE);
>>  }
>>  
>> -void qtest_qmp(QTestState *s, const char *fmt, ...)
>> +char *qtest_qmp(QTestState *s, const char *fmt, ...)
>>  {
>>      va_list ap;
>> +    char *ret;
>>  
>>      va_start(ap, fmt);
>> -    qtest_qmpv(s, fmt, ap);
>> +    ret = qtest_qmpv(s, fmt, ap);
>>      va_end(ap);
>> +
>> +    return ret;
>>  }
>>  
>>  const char *qtest_get_arch(void)
>> diff --git a/tests/libqtest.h b/tests/libqtest.h
>> index 592f035..5cdcae7 100644
>> --- a/tests/libqtest.h
>> +++ b/tests/libqtest.h
>> @@ -21,6 +21,7 @@
>>  #include <stdbool.h>
>>  #include <stdarg.h>
>>  #include <sys/types.h>
>> +#include <glib.h>
>>  
>>  typedef struct QTestState QTestState;
>>  
>> @@ -48,8 +49,10 @@ void qtest_quit(QTestState *s);
>>   * @fmt...: QMP message to send to qemu
>>   *
>>   * Sends a QMP message to QEMU
>> + *
>> + * Returns: the result of the QMP command
>>   */
>> -void qtest_qmp(QTestState *s, const char *fmt, ...);
>> +char *qtest_qmp(QTestState *s, const char *fmt, ...);
>>  
>>  /**
>>   * qtest_qmpv:
>> @@ -58,8 +61,10 @@ void qtest_qmp(QTestState *s, const char *fmt, ...);
>>   * @ap: QMP message arguments
>>   *
>>   * Sends a QMP message to QEMU.
>> + *
>> + * Returns: the result of the QMP command
>>   */
>> -void qtest_qmpv(QTestState *s, const char *fmt, va_list ap);
>> +char *qtest_qmpv(QTestState *s, const char *fmt, va_list ap);
>>  
>>  /**
>>   * qtest_get_irq:
>> @@ -340,10 +345,13 @@ static inline QTestState *qtest_start(const char *args)
>>  static inline void qmp(const char *fmt, ...)
>>  {
>>      va_list ap;
>> +    char *ret;
>>  
>>      va_start(ap, fmt);
>> -    qtest_qmpv(global_qtest, fmt, ap);
>> +    ret = qtest_qmpv(global_qtest, fmt, ap);
>>      va_end(ap);
>> +
>> +    g_free(ret);
>>  }
>>  
>>  /**
>
> In http://patchwork.ozlabs.org/patch/207689/ you had suggested to return
> QObject?

It's the Right Thing to do but it's hard.   It's on my list todo and I
don't think gating this series on doing proper QMP integration is the
right thing to do.

Regards,

Anthony Liguori

>
> Regards,
> Andreas
>
> -- 
> SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
> GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

Patch

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 81107cf..235ec62 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -287,10 +287,13 @@  redo:
     return words;
 }
 
-void qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
+char *qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
 {
     bool has_reply = false;
     int nesting = 0;
+    GString *ret;
+
+    ret = g_string_new("");
 
     /* Send QMP request */
     socket_sendf(s->qmp_fd, fmt, ap);
@@ -319,16 +322,23 @@  void qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
             nesting--;
             break;
         }
+
+        g_string_append_c(ret, c);
     }
+
+    return g_string_free(ret, FALSE);
 }
 
-void qtest_qmp(QTestState *s, const char *fmt, ...)
+char *qtest_qmp(QTestState *s, const char *fmt, ...)
 {
     va_list ap;
+    char *ret;
 
     va_start(ap, fmt);
-    qtest_qmpv(s, fmt, ap);
+    ret = qtest_qmpv(s, fmt, ap);
     va_end(ap);
+
+    return ret;
 }
 
 const char *qtest_get_arch(void)
diff --git a/tests/libqtest.h b/tests/libqtest.h
index 592f035..5cdcae7 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -21,6 +21,7 @@ 
 #include <stdbool.h>
 #include <stdarg.h>
 #include <sys/types.h>
+#include <glib.h>
 
 typedef struct QTestState QTestState;
 
@@ -48,8 +49,10 @@  void qtest_quit(QTestState *s);
  * @fmt...: QMP message to send to qemu
  *
  * Sends a QMP message to QEMU
+ *
+ * Returns: the result of the QMP command
  */
-void qtest_qmp(QTestState *s, const char *fmt, ...);
+char *qtest_qmp(QTestState *s, const char *fmt, ...);
 
 /**
  * qtest_qmpv:
@@ -58,8 +61,10 @@  void qtest_qmp(QTestState *s, const char *fmt, ...);
  * @ap: QMP message arguments
  *
  * Sends a QMP message to QEMU.
+ *
+ * Returns: the result of the QMP command
  */
-void qtest_qmpv(QTestState *s, const char *fmt, va_list ap);
+char *qtest_qmpv(QTestState *s, const char *fmt, va_list ap);
 
 /**
  * qtest_get_irq:
@@ -340,10 +345,13 @@  static inline QTestState *qtest_start(const char *args)
 static inline void qmp(const char *fmt, ...)
 {
     va_list ap;
+    char *ret;
 
     va_start(ap, fmt);
-    qtest_qmpv(global_qtest, fmt, ap);
+    ret = qtest_qmpv(global_qtest, fmt, ap);
     va_end(ap);
+
+    g_free(ret);
 }
 
 /**