qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC] test: QOM interface casting
@ 2013-12-20 11:08 Igor Mammedov
  2013-12-20 11:24 ` Peter Crosthwaite
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Igor Mammedov @ 2013-12-20 11:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, afaerber, anthony, armbru

---
 tests/Makefile              |    3 +
 tests/check-qom-interface.c |  102 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 0 deletions(-)
 create mode 100644 tests/check-qom-interface.c

diff --git a/tests/Makefile b/tests/Makefile
index 379cdd9..dfb6cce 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -52,6 +52,8 @@ check-unit-y += tests/test-int128$(EXESUF)
 gcov-files-test-int128-y =
 check-unit-y += tests/test-bitops$(EXESUF)
 check-unit-y += tests/test-qdev-global-props$(EXESUF)
+check-unit-y = tests/check-qom-interface$(EXESUF)
+gcov-files-check-qdict-y = object/object.c
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -205,6 +207,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
 tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
 tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
 tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
+tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o qom/object.o qom/qom-qobject.o libqemuutil.a libqemustub.a
 
 # QTest rules
 
diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c
new file mode 100644
index 0000000..6d59606
--- /dev/null
+++ b/tests/check-qom-interface.c
@@ -0,0 +1,102 @@
+/*
+ * OQM interfacei test.
+ *
+ * Copyright (C) 2013 Red Hat Inc.
+ *
+ * Authors:
+ *  Igor Mammedov <imammedo@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+#include <glib.h>
+
+#include "qom/object.h"
+#include "qemu/module.h"
+
+
+#define TYPE_TEST_IF "test-interface"
+#define TEST_IF_CLASS(klass) \
+     OBJECT_CLASS_CHECK(TestIfClass, (klass), TYPE_TEST_IF)
+#define TEST_IF_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(TestIfClass, (obj), TYPE_TEST_IF)
+#define TEST_IF(obj) \
+     INTERFACE_CHECK(TestIf, (obj), TYPE_TEST_IF)
+
+typedef struct TestIf {
+    Object Parent;
+} TestIf;
+
+typedef struct TestIfClass {
+    InterfaceClass parent;
+
+    uint32_t test;
+} TestIfClass;
+
+static const TypeInfo test_if_info = {
+    .name          = TYPE_TEST_IF,
+    .parent        = TYPE_INTERFACE,
+    .class_size = sizeof(TestIfClass),
+};
+
+#define PATTERN 0xFAFBFCFD
+static void test_class_init(ObjectClass *oc, void *data)
+{
+    TestIfClass *tc = TEST_IF_CLASS(oc);
+
+    g_assert(tc);
+    tc->test = PATTERN;
+}
+
+#define TYPE_DIRECT_IMPL "direct-impl"
+static const TypeInfo direct_impl_info = {
+    .name = TYPE_DIRECT_IMPL,
+    .parent = TYPE_OBJECT,
+    .class_init = test_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_TEST_IF },
+        { }
+    }
+};
+
+#define TYPE_INTERMEDIATE_IMPL "intermediate-impl"
+static const TypeInfo intermediate_impl_info = {
+    .name = TYPE_INTERMEDIATE_IMPL,
+    .parent = TYPE_DIRECT_IMPL,
+};
+
+static void test_interface_impl(const char *type)
+{
+    Object *obj = object_new(type);
+    TestIf *iobj = TEST_IF(obj);
+    TestIfClass *ico = TEST_IF_GET_CLASS(iobj);
+
+    g_assert(iobj);
+    g_assert(ico->test == PATTERN);
+}
+
+static void interface_direct_test(void)
+{
+    test_interface_impl(TYPE_DIRECT_IMPL);
+}
+
+static void interface_intermediate_test(void)
+{
+    test_interface_impl(TYPE_INTERMEDIATE_IMPL);
+}
+
+int main(int argc, char **argv)
+{
+    g_test_init(&argc, &argv, NULL);
+
+    module_call_init(MODULE_INIT_QOM);
+    type_register_static(&test_if_info);
+    type_register_static(&direct_impl_info);
+    type_register_static(&intermediate_impl_info);
+
+    g_test_add_func("/interface/direct_impl", interface_direct_test);
+    g_test_add_func("/interface/intermediate_impl",
+                    interface_intermediate_test);
+
+    return g_test_run();
+}
-- 
1.7.1

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

* Re: [Qemu-devel] [RFC] test: QOM interface casting
  2013-12-20 11:08 [Qemu-devel] [RFC] test: QOM interface casting Igor Mammedov
@ 2013-12-20 11:24 ` Peter Crosthwaite
  2013-12-20 12:01 ` Peter Maydell
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Peter Crosthwaite @ 2013-12-20 11:24 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: Paolo Bonzini, Markus Armbruster,
	qemu-devel@nongnu.org Developers, Anthony Liguori,
	Andreas Färber

On Fri, Dec 20, 2013 at 9:08 PM, Igor Mammedov <imammedo@redhat.com> wrote:
> ---
>  tests/Makefile              |    3 +
>  tests/check-qom-interface.c |  102 +++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 105 insertions(+), 0 deletions(-)
>  create mode 100644 tests/check-qom-interface.c
>
> diff --git a/tests/Makefile b/tests/Makefile
> index 379cdd9..dfb6cce 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -52,6 +52,8 @@ check-unit-y += tests/test-int128$(EXESUF)
>  gcov-files-test-int128-y =
>  check-unit-y += tests/test-bitops$(EXESUF)
>  check-unit-y += tests/test-qdev-global-props$(EXESUF)
> +check-unit-y = tests/check-qom-interface$(EXESUF)
> +gcov-files-check-qdict-y = object/object.c
>
>  check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
>
> @@ -205,6 +207,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
>  tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
>  tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
>  tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
> +tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o qom/object.o qom/qom-qobject.o libqemuutil.a libqemustub.a
>
>  # QTest rules
>
> diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c
> new file mode 100644
> index 0000000..6d59606
> --- /dev/null
> +++ b/tests/check-qom-interface.c
> @@ -0,0 +1,102 @@
> +/*
> + * OQM interfacei test.
> + *
> + * Copyright (C) 2013 Red Hat Inc.
> + *
> + * Authors:
> + *  Igor Mammedov <imammedo@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
> + * See the COPYING.LIB file in the top-level directory.
> + */
> +#include <glib.h>
> +
> +#include "qom/object.h"
> +#include "qemu/module.h"
> +
> +
> +#define TYPE_TEST_IF "test-interface"
> +#define TEST_IF_CLASS(klass) \
> +     OBJECT_CLASS_CHECK(TestIfClass, (klass), TYPE_TEST_IF)
> +#define TEST_IF_GET_CLASS(obj) \
> +     OBJECT_GET_CLASS(TestIfClass, (obj), TYPE_TEST_IF)
> +#define TEST_IF(obj) \
> +     INTERFACE_CHECK(TestIf, (obj), TYPE_TEST_IF)
> +
> +typedef struct TestIf {
> +    Object Parent;

parent_obj

> +} TestIf;
> +
> +typedef struct TestIfClass {
> +    InterfaceClass parent;

parent_class?

Regards,
Peter

> +
> +    uint32_t test;
> +} TestIfClass;
> +
> +static const TypeInfo test_if_info = {
> +    .name          = TYPE_TEST_IF,
> +    .parent        = TYPE_INTERFACE,
> +    .class_size = sizeof(TestIfClass),
> +};
> +
> +#define PATTERN 0xFAFBFCFD
> +static void test_class_init(ObjectClass *oc, void *data)
> +{
> +    TestIfClass *tc = TEST_IF_CLASS(oc);
> +
> +    g_assert(tc);
> +    tc->test = PATTERN;
> +}
> +
> +#define TYPE_DIRECT_IMPL "direct-impl"
> +static const TypeInfo direct_impl_info = {
> +    .name = TYPE_DIRECT_IMPL,
> +    .parent = TYPE_OBJECT,
> +    .class_init = test_class_init,
> +    .interfaces = (InterfaceInfo[]) {
> +        { TYPE_TEST_IF },
> +        { }
> +    }
> +};
> +
> +#define TYPE_INTERMEDIATE_IMPL "intermediate-impl"
> +static const TypeInfo intermediate_impl_info = {
> +    .name = TYPE_INTERMEDIATE_IMPL,
> +    .parent = TYPE_DIRECT_IMPL,
> +};
> +
> +static void test_interface_impl(const char *type)
> +{
> +    Object *obj = object_new(type);
> +    TestIf *iobj = TEST_IF(obj);
> +    TestIfClass *ico = TEST_IF_GET_CLASS(iobj);
> +
> +    g_assert(iobj);
> +    g_assert(ico->test == PATTERN);
> +}
> +
> +static void interface_direct_test(void)
> +{
> +    test_interface_impl(TYPE_DIRECT_IMPL);
> +}
> +
> +static void interface_intermediate_test(void)
> +{
> +    test_interface_impl(TYPE_INTERMEDIATE_IMPL);
> +}
> +
> +int main(int argc, char **argv)
> +{
> +    g_test_init(&argc, &argv, NULL);
> +
> +    module_call_init(MODULE_INIT_QOM);
> +    type_register_static(&test_if_info);
> +    type_register_static(&direct_impl_info);
> +    type_register_static(&intermediate_impl_info);
> +
> +    g_test_add_func("/interface/direct_impl", interface_direct_test);
> +    g_test_add_func("/interface/intermediate_impl",
> +                    interface_intermediate_test);
> +
> +    return g_test_run();
> +}
> --
> 1.7.1
>
>

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

* Re: [Qemu-devel] [RFC] test: QOM interface casting
  2013-12-20 11:08 [Qemu-devel] [RFC] test: QOM interface casting Igor Mammedov
  2013-12-20 11:24 ` Peter Crosthwaite
@ 2013-12-20 12:01 ` Peter Maydell
  2013-12-20 12:47 ` Andreas Färber
  2013-12-21 10:48 ` Markus Armbruster
  3 siblings, 0 replies; 7+ messages in thread
From: Peter Maydell @ 2013-12-20 12:01 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: Paolo Bonzini, Markus Armbruster, QEMU Developers,
	Anthony Liguori, Andreas Färber

On 20 December 2013 11:08, Igor Mammedov <imammedo@redhat.com> wrote:
> ---
>  tests/Makefile              |    3 +
>  tests/check-qom-interface.c |  102 +++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 105 insertions(+), 0 deletions(-)
>  create mode 100644 tests/check-qom-interface.c
>
> diff --git a/tests/Makefile b/tests/Makefile
> index 379cdd9..dfb6cce 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -52,6 +52,8 @@ check-unit-y += tests/test-int128$(EXESUF)
>  gcov-files-test-int128-y =
>  check-unit-y += tests/test-bitops$(EXESUF)
>  check-unit-y += tests/test-qdev-global-props$(EXESUF)
> +check-unit-y = tests/check-qom-interface$(EXESUF)
> +gcov-files-check-qdict-y = object/object.c
>
>  check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
>
> @@ -205,6 +207,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
>  tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
>  tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
>  tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
> +tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o qom/object.o qom/qom-qobject.o libqemuutil.a libqemustub.a

This line's getting a bit long and could use folding I guess.

>
>  # QTest rules
>
> diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c
> new file mode 100644
> index 0000000..6d59606
> --- /dev/null
> +++ b/tests/check-qom-interface.c
> @@ -0,0 +1,102 @@
> +/*
> + * OQM interfacei test.

"QOM", "interface" :-)

thanks
-- PMM

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

* Re: [Qemu-devel] [RFC] test: QOM interface casting
  2013-12-20 11:08 [Qemu-devel] [RFC] test: QOM interface casting Igor Mammedov
  2013-12-20 11:24 ` Peter Crosthwaite
  2013-12-20 12:01 ` Peter Maydell
@ 2013-12-20 12:47 ` Andreas Färber
  2013-12-20 13:22   ` Igor Mammedov
  2013-12-21 10:48 ` Markus Armbruster
  3 siblings, 1 reply; 7+ messages in thread
From: Andreas Färber @ 2013-12-20 12:47 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel
  Cc: Peter Maydell, Peter Crosthwaite, Eduardo Habkost, armbru,
	anthony, pbonzini

Hi,

Am 20.12.2013 12:08, schrieb Igor Mammedov:
> ---
>  tests/Makefile              |    3 +
>  tests/check-qom-interface.c |  102 +++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 105 insertions(+), 0 deletions(-)
>  create mode 100644 tests/check-qom-interface.c

Apart from the style issues and typos that the two Peter's have pointed
out, I'd like to point out that this is missing Signed-off-by and commit
message. In particular, is this a test that should be committed
alongside the interface cast fixes or anything else that I have queued?
Or just to improve overall test coverage? Either way I'm in favor of
having them.

Concerning PMM's comment, don't we already have a qdev properties unit
test from Eduardo where we might share QOM dependencies via some
Makefile variable? Grouping the check-* tests also makes sense to me
than just adding at the bottom.

Anything in particular that you'd like comments on, this being an RFC?

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

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

* Re: [Qemu-devel] [RFC] test: QOM interface casting
  2013-12-20 12:47 ` Andreas Färber
@ 2013-12-20 13:22   ` Igor Mammedov
  0 siblings, 0 replies; 7+ messages in thread
From: Igor Mammedov @ 2013-12-20 13:22 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Peter Maydell, Peter Crosthwaite, Eduardo Habkost, qemu-devel,
	armbru, anthony, pbonzini

On Fri, 20 Dec 2013 13:47:32 +0100
Andreas Färber <afaerber@suse.de> wrote:

> Hi,
> 
> Am 20.12.2013 12:08, schrieb Igor Mammedov:
> > ---
> >  tests/Makefile              |    3 +
> >  tests/check-qom-interface.c |  102 +++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 105 insertions(+), 0 deletions(-)
> >  create mode 100644 tests/check-qom-interface.c
> 
> Apart from the style issues and typos that the two Peter's have pointed
> out, I'd like to point out that this is missing Signed-off-by and commit
> message. In particular, is this a test that should be committed
> alongside the interface cast fixes or anything else that I have queued?
> Or just to improve overall test coverage? Either way I'm in favor of
> having them.
Since interfaces are not widely used it's easy to break them, this adds
regression testing. It could go along with fixes you've queued.

> 
> Concerning PMM's comment, don't we already have a qdev properties unit
> test from Eduardo where we might share QOM dependencies via some
> Makefile variable? Grouping the check-* tests also makes sense to me
> than just adding at the bottom.
> 
> Anything in particular that you'd like comments on, this being an RFC?
Peters's and your comments are applied, I'll respin it as patch,
thanks for reviewing.

> Regards,
> Andreas
> 

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

* Re: [Qemu-devel] [RFC] test: QOM interface casting
  2013-12-20 11:08 [Qemu-devel] [RFC] test: QOM interface casting Igor Mammedov
                   ` (2 preceding siblings ...)
  2013-12-20 12:47 ` Andreas Färber
@ 2013-12-21 10:48 ` Markus Armbruster
  2013-12-21 14:56   ` Igor Mammedov
  3 siblings, 1 reply; 7+ messages in thread
From: Markus Armbruster @ 2013-12-21 10:48 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: pbonzini, qemu-devel, anthony, afaerber

Igor Mammedov <imammedo@redhat.com> writes:

> ---
>  tests/Makefile              |    3 +
>  tests/check-qom-interface.c |  102 +++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 105 insertions(+), 0 deletions(-)
>  create mode 100644 tests/check-qom-interface.c
>
> diff --git a/tests/Makefile b/tests/Makefile
> index 379cdd9..dfb6cce 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -52,6 +52,8 @@ check-unit-y += tests/test-int128$(EXESUF)
>  gcov-files-test-int128-y =
>  check-unit-y += tests/test-bitops$(EXESUF)
>  check-unit-y += tests/test-qdev-global-props$(EXESUF)
> +check-unit-y = tests/check-qom-interface$(EXESUF)
> +gcov-files-check-qdict-y = object/object.c
>  
>  check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
>  
> @@ -205,6 +207,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
>  tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
>  tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
>  tests/qemu-iotests/socket_scm_helper$(EXESUF):
> tests/qemu-iotests/socket_scm_helper.o
> +tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o
> qom/object.o qom/qom-qobject.o libqemuutil.a libqemustub.a
>  
>  # QTest rules
>  
> diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c
> new file mode 100644
> index 0000000..6d59606
> --- /dev/null
> +++ b/tests/check-qom-interface.c
> @@ -0,0 +1,102 @@
> +/*
> + * OQM interfacei test.

Machine-gun typist, eh?  ;-)

[...]

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

* Re: [Qemu-devel] [RFC] test: QOM interface casting
  2013-12-21 10:48 ` Markus Armbruster
@ 2013-12-21 14:56   ` Igor Mammedov
  0 siblings, 0 replies; 7+ messages in thread
From: Igor Mammedov @ 2013-12-21 14:56 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: pbonzini, qemu-devel, anthony, afaerber

On Sat, 21 Dec 2013 11:48:29 +0100
Markus Armbruster <armbru@redhat.com> wrote:

> Igor Mammedov <imammedo@redhat.com> writes:
> 
> > ---
> >  tests/Makefile              |    3 +
> >  tests/check-qom-interface.c |  102 +++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 105 insertions(+), 0 deletions(-)
> >  create mode 100644 tests/check-qom-interface.c
> >
> > diff --git a/tests/Makefile b/tests/Makefile
> > index 379cdd9..dfb6cce 100644
> > --- a/tests/Makefile
> > +++ b/tests/Makefile
> > @@ -52,6 +52,8 @@ check-unit-y += tests/test-int128$(EXESUF)
> >  gcov-files-test-int128-y =
> >  check-unit-y += tests/test-bitops$(EXESUF)
> >  check-unit-y += tests/test-qdev-global-props$(EXESUF)
> > +check-unit-y = tests/check-qom-interface$(EXESUF)
> > +gcov-files-check-qdict-y = object/object.c
> >  
> >  check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
> >  
> > @@ -205,6 +207,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
> >  tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
> >  tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
> >  tests/qemu-iotests/socket_scm_helper$(EXESUF):
> > tests/qemu-iotests/socket_scm_helper.o
> > +tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o
> > qom/object.o qom/qom-qobject.o libqemuutil.a libqemustub.a
> >  
> >  # QTest rules
> >  
> > diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c
> > new file mode 100644
> > index 0000000..6d59606
> > --- /dev/null
> > +++ b/tests/check-qom-interface.c
> > @@ -0,0 +1,102 @@
> > +/*
> > + * OQM interfacei test.
> 
> Machine-gun typist, eh?  ;-)
sort of :)
fixed in v2

> 
> [...]


-- 
Regards,
  Igor

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

end of thread, other threads:[~2013-12-21 14:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-20 11:08 [Qemu-devel] [RFC] test: QOM interface casting Igor Mammedov
2013-12-20 11:24 ` Peter Crosthwaite
2013-12-20 12:01 ` Peter Maydell
2013-12-20 12:47 ` Andreas Färber
2013-12-20 13:22   ` Igor Mammedov
2013-12-21 10:48 ` Markus Armbruster
2013-12-21 14:56   ` Igor Mammedov

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).