qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Igor Mammedov" <imammedo@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [PULL 16/24] tests: Test QOM interface casting
Date: Tue, 24 Dec 2013 17:57:09 +0100	[thread overview]
Message-ID: <1387904237-6941-17-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1387904237-6941-1-git-send-email-afaerber@suse.de>

From: Igor Mammedov <imammedo@redhat.com>

Add basic regression testing for QOM Interface usage.
Test checks casting to interface type/class for following cases:
  - interface implementation in leaf class
  - interface implementation in intermediate (parent) class

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/Makefile              |   6 ++-
 tests/check-qom-interface.c | 105 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+), 1 deletion(-)
 create mode 100644 tests/check-qom-interface.c

diff --git a/tests/Makefile b/tests/Makefile
index 8d25878..0b85a34 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-qom-interface-y = qom/object.c
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -138,6 +140,7 @@ test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o
 
 $(test-obj-y): QEMU_INCLUDES += -Itests
 QEMU_CFLAGS += -I$(SRC_PATH)/tests
+qom-core-obj = qom/object.o qom/qom-qobject.o qom/container.o
 
 tests/test-x86-cpuid.o: QEMU_INCLUDES += -I$(SRC_PATH)/target-i386
 
@@ -147,6 +150,7 @@ tests/check-qdict$(EXESUF): tests/check-qdict.o libqemuutil.a
 tests/check-qlist$(EXESUF): tests/check-qlist.o libqemuutil.a
 tests/check-qfloat$(EXESUF): tests/check-qfloat.o libqemuutil.a
 tests/check-qjson$(EXESUF): tests/check-qjson.o libqemuutil.a libqemustub.a
+tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(qom-core-obj) libqemuutil.a
 tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(block-obj-y) libqemuutil.a libqemustub.a
 tests/test-aio$(EXESUF): tests/test-aio.o $(block-obj-y) libqemuutil.a libqemustub.a
 tests/test-throttle$(EXESUF): tests/test-throttle.o $(block-obj-y) libqemuutil.a libqemustub.a
@@ -160,7 +164,7 @@ tests/test-int128$(EXESUF): tests/test-int128.o
 tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \
 	hw/core/qdev.o hw/core/qdev-properties.o \
 	hw/core/irq.o \
-	qom/object.o qom/container.o qom/qom-qobject.o \
+	$(qom-core-obj) \
 	$(test-qapi-obj-y) \
 	libqemuutil.a libqemustub.a
 
diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c
new file mode 100644
index 0000000..f06380e
--- /dev/null
+++ b/tests/check-qom-interface.c
@@ -0,0 +1,105 @@
+/*
+ * QOM interface 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_obj;
+} TestIf;
+
+typedef struct TestIfClass {
+    InterfaceClass parent_class;
+
+    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 *ioc = TEST_IF_GET_CLASS(iobj);
+
+    g_assert(iobj);
+    g_assert(ioc->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("/qom/interface/direct_impl", interface_direct_test);
+    g_test_add_func("/qom/interface/intermediate_impl",
+                    interface_intermediate_test);
+
+    return g_test_run();
+}
-- 
1.8.4

  parent reply	other threads:[~2013-12-24 16:57 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-24 16:56 [Qemu-devel] [PULL 00/24] QOM devices patch queue 2013-12-24 Andreas Färber
2013-12-24 16:56 ` [Qemu-devel] [PULL 01/24] qdev: Replace no_user by cannot_instantiate_with_device_add_yet Andreas Färber
2013-12-24 16:56 ` [Qemu-devel] [PULL 02/24] sysbus: Set cannot_instantiate_with_device_add_yet Andreas Färber
2013-12-24 16:56 ` [Qemu-devel] [PULL 03/24] cpu: Document why cannot_instantiate_with_device_add_yet Andreas Färber
2013-12-24 16:56 ` [Qemu-devel] [PULL 04/24] apic: " Andreas Färber
2013-12-24 16:56 ` [Qemu-devel] [PULL 05/24] pci-host: Consistently set cannot_instantiate_with_device_add_yet Andreas Färber
2013-12-24 16:56 ` [Qemu-devel] [PULL 06/24] ich9: Document why cannot_instantiate_with_device_add_yet Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 07/24] piix3 piix4: Clean up use of cannot_instantiate_with_device_add_yet Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 08/24] vt82c686: " Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 09/24] isa: " Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 10/24] qdev: Do not let the user try to device_add when it cannot work Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 11/24] qdev-monitor: Avoid device_add crashing on non-device driver name Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 12/24] hw: cannot_instantiate_with_device_add_yet due to pointer props Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 13/24] qdev: Document that pointer properties kill device_add Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 14/24] qom: Split out object and class caches Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 15/24] qom: Do not register interface "types" in the type table and fix names Andreas Färber
2013-12-24 16:57 ` Andreas Färber [this message]
2013-12-24 16:57 ` [Qemu-devel] [PULL 17/24] qom: Detect bad reentrance during object_class_foreach() Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 18/24] qdev: Drop misleading qbus_free() function Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 19/24] apic: Cleanup for QOM'ification Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 20/24] apic: QOM'ify APIC Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 21/24] icc_bus: QOM'ify ICC Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 22/24] ioapic: Cleanup for QOM'ification Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 23/24] ioapic: QOM'ify ioapic Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 24/24] qdev-monitor: Improve error message for -device nonexistant Andreas Färber
2013-12-24 17:01 ` [Qemu-devel] [PULL 00/24] QOM devices patch queue 2013-12-24 Andreas Färber

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=1387904237-6941-17-git-send-email-afaerber@suse.de \
    --to=afaerber@suse.de \
    --cc=imammedo@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 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).