From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44747) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vu08T-00029B-DW for qemu-devel@nongnu.org; Fri, 20 Dec 2013 08:29:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vu08P-0007ug-Ac for qemu-devel@nongnu.org; Fri, 20 Dec 2013 08:29:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26205) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vu08P-0007uZ-31 for qemu-devel@nongnu.org; Fri, 20 Dec 2013 08:28:57 -0500 From: Igor Mammedov Date: Fri, 20 Dec 2013 14:26:11 +0100 Message-Id: <1387545971-22218-1-git-send-email-imammedo@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH] test: QOM interface casting List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, afaerber@suse.de, anthony@codemonkey.ws, armbru@redhat.com Add basic regression testing for QOM Interface usage. Signed-off-by: Igor Mammedov --- v2: - Peter Crosthwaite * s/Parent/parent_obj/ * s/parent/parent_class/ - Peter Maydell * s/interfacei/interface/ * tests/Makefile split too long line - Andreas F=C3=A4rber * consolidate QOM core object files in dedicated variable * add SoB and commit message --- tests/Makefile | 6 ++- tests/check-qom-interface.c | 102 +++++++++++++++++++++++++++++++++++++= ++++++ 2 files changed, 107 insertions(+), 1 deletions(-) create mode 100644 tests/check-qom-interface.c diff --git a/tests/Makefile b/tests/Makefile index 379cdd9..89f8eff 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -52,6 +52,8 @@ check-unit-y +=3D tests/test-int128$(EXESUF) gcov-files-test-int128-y =3D check-unit-y +=3D tests/test-bitops$(EXESUF) check-unit-y +=3D tests/test-qdev-global-props$(EXESUF) +check-unit-y =3D tests/check-qom-interface$(EXESUF) +gcov-files-check-qdict-y =3D object/object.c =20 check-block-$(CONFIG_POSIX) +=3D tests/qemu-iotests-quick.sh =20 @@ -137,6 +139,7 @@ test-qapi-obj-y =3D tests/test-qapi-visit.o tests/tes= t-qapi-types.o =20 $(test-obj-y): QEMU_INCLUDES +=3D -Itests QEMU_CFLAGS +=3D -I$(SRC_PATH)/tests +qom-core-obj =3D qom/object.o qom/qom-qobject.o qom/container.o =20 tests/test-x86-cpuid.o: QEMU_INCLUDES +=3D -I$(SRC_PATH)/target-i386 =20 @@ -146,6 +149,7 @@ tests/check-qdict$(EXESUF): tests/check-qdict.o libqe= muutil.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 libqemustu= b.a +tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(qom-co= re-obj) libqemuutil.a tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(block-obj-y) lib= qemuutil.a libqemustub.a tests/test-aio$(EXESUF): tests/test-aio.o $(block-obj-y) libqemuutil.a l= ibqemustub.a tests/test-throttle$(EXESUF): tests/test-throttle.o $(block-obj-y) libqe= muutil.a libqemustub.a @@ -159,7 +163,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 =20 diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c new file mode 100644 index 0000000..8d7c1f8 --- /dev/null +++ b/tests/check-qom-interface.c @@ -0,0 +1,102 @@ +/* + * OQM interface test. + * + * Copyright (C) 2013 Red Hat Inc. + * + * Authors: + * Igor Mammedov + * + * 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 + +#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 =3D { + .name =3D TYPE_TEST_IF, + .parent =3D TYPE_INTERFACE, + .class_size =3D sizeof(TestIfClass), +}; + +#define PATTERN 0xFAFBFCFD +static void test_class_init(ObjectClass *oc, void *data) +{ + TestIfClass *tc =3D TEST_IF_CLASS(oc); + + g_assert(tc); + tc->test =3D PATTERN; +} + +#define TYPE_DIRECT_IMPL "direct-impl" +static const TypeInfo direct_impl_info =3D { + .name =3D TYPE_DIRECT_IMPL, + .parent =3D TYPE_OBJECT, + .class_init =3D test_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_TEST_IF }, + { } + } +}; + +#define TYPE_INTERMEDIATE_IMPL "intermediate-impl" +static const TypeInfo intermediate_impl_info =3D { + .name =3D TYPE_INTERMEDIATE_IMPL, + .parent =3D TYPE_DIRECT_IMPL, +}; + +static void test_interface_impl(const char *type) +{ + Object *obj =3D object_new(type); + TestIf *iobj =3D TEST_IF(obj); + TestIfClass *ico =3D TEST_IF_GET_CLASS(iobj); + + g_assert(iobj); + g_assert(ico->test =3D=3D 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(); +} --=20 1.7.1