qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel]  [PATCH] tests: check empty qmp output visitor
@ 2014-05-20 15:07 Marcel Apfelbaum
  2014-05-21  0:19 ` Michael Roth
  0 siblings, 1 reply; 2+ messages in thread
From: Marcel Apfelbaum @ 2014-05-20 15:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, lcapitulino, akong, afaerber

Checks the output visitor behaviour for NULL values.

Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
---
 Notes:
 - I didn't add Michael's Sob because I tweaked the test a little.
 - To be added on top of  "qapi: output visitor crashes qemu if it encounters a NULL value",
   otherwise the test will fail.

 tests/test-qmp-output-visitor.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c
index 9c15458..de1bf83 100644
--- a/tests/test-qmp-output-visitor.c
+++ b/tests/test-qmp-output-visitor.c
@@ -507,6 +507,19 @@ static void test_visitor_out_union_anon(TestOutputVisitorData *data,
     qapi_free_UserDefAnonUnion(tmp);
 }
 
+static void test_visitor_out_empty(TestOutputVisitorData *data,
+                                   const void *unused)
+{
+    QObject *arg;
+    QDict *qdict;
+
+    arg = qmp_output_get_qobject(data->qov);
+    if (arg) {
+        qdict = qobject_to_qdict(arg);
+        QDECREF(qdict);
+    }
+}
+
 static void init_native_list(UserDefNativeListUnion *cvalue)
 {
     int i;
@@ -859,6 +872,8 @@ int main(int argc, char **argv)
                             &out_visitor_data, test_visitor_out_union_flat);
     output_visitor_test_add("/visitor/output/union-anon",
                             &out_visitor_data, test_visitor_out_union_anon);
+    output_visitor_test_add("/visitor/output/empty",
+                            &out_visitor_data, test_visitor_out_empty);
     output_visitor_test_add("/visitor/output/native_list/int",
                             &out_visitor_data, test_visitor_out_native_list_int);
     output_visitor_test_add("/visitor/output/native_list/int8",
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] tests: check empty qmp output visitor
  2014-05-20 15:07 [Qemu-devel] [PATCH] tests: check empty qmp output visitor Marcel Apfelbaum
@ 2014-05-21  0:19 ` Michael Roth
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Roth @ 2014-05-21  0:19 UTC (permalink / raw)
  To: Marcel Apfelbaum, qemu-devel; +Cc: akong, armbru, afaerber, lcapitulino

Quoting Marcel Apfelbaum (2014-05-20 10:07:59)
> Checks the output visitor behaviour for NULL values.
> 
> Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
> ---
>  Notes:
>  - I didn't add Michael's Sob because I tweaked the test a little.

Tweaked it so it didn't crash 100% of the time even after your fix? :)

Another approach, since the expected behavior now is for
qmp_output_get_qobject() to return NULL in this case, is to just
assert(arg == NULL) and drop the qdict/QDECREF completely.

>  - To be added on top of  "qapi: output visitor crashes qemu if it encounters a NULL value",
>    otherwise the test will fail.
> 
>  tests/test-qmp-output-visitor.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c
> index 9c15458..de1bf83 100644
> --- a/tests/test-qmp-output-visitor.c
> +++ b/tests/test-qmp-output-visitor.c
> @@ -507,6 +507,19 @@ static void test_visitor_out_union_anon(TestOutputVisitorData *data,
>      qapi_free_UserDefAnonUnion(tmp);
>  }
> 
> +static void test_visitor_out_empty(TestOutputVisitorData *data,
> +                                   const void *unused)
> +{
> +    QObject *arg;
> +    QDict *qdict;
> +
> +    arg = qmp_output_get_qobject(data->qov);
> +    if (arg) {
> +        qdict = qobject_to_qdict(arg);
> +        QDECREF(qdict);
> +    }
> +}
> +
>  static void init_native_list(UserDefNativeListUnion *cvalue)
>  {
>      int i;
> @@ -859,6 +872,8 @@ int main(int argc, char **argv)
>                              &out_visitor_data, test_visitor_out_union_flat);
>      output_visitor_test_add("/visitor/output/union-anon",
>                              &out_visitor_data, test_visitor_out_union_anon);
> +    output_visitor_test_add("/visitor/output/empty",
> +                            &out_visitor_data, test_visitor_out_empty);
>      output_visitor_test_add("/visitor/output/native_list/int",
>                              &out_visitor_data, test_visitor_out_native_list_int);
>      output_visitor_test_add("/visitor/output/native_list/int8",
> -- 
> 1.8.3.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-05-21  1:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-20 15:07 [Qemu-devel] [PATCH] tests: check empty qmp output visitor Marcel Apfelbaum
2014-05-21  0:19 ` Michael Roth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).