From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42525) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vu1mL-0000j3-3t for qemu-devel@nongnu.org; Fri, 20 Dec 2013 10:14:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vu1mH-0007A5-5g for qemu-devel@nongnu.org; Fri, 20 Dec 2013 10:14:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34249) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vu1mG-00079y-Tt for qemu-devel@nongnu.org; Fri, 20 Dec 2013 10:14:13 -0500 Date: Fri, 20 Dec 2013 16:14:06 +0100 From: Igor Mammedov Message-ID: <20131220161406.0c0d42cc@nial.usersys.redhat.com> In-Reply-To: <1387545971-22218-1-git-send-email-imammedo@redhat.com> References: <1387545971-22218-1-git-send-email-imammedo@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] test: QOM interface casting List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov Cc: pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, anthony@codemonkey.ws, afaerber@suse.de On Fri, 20 Dec 2013 14:26:11 +0100 Igor Mammedov wrote: Andreas, test shows that commit: "qom: Do not register interface "types" in the type table " https://github.com/afaerber/qemu-cpu/commit/7f00136ff5534ee651f4f10475170b8= db18e5c03 regresses QOM Interface in case where interface is implemented in not a leaf class, leading to abort. > Add basic regression testing for QOM Interface usage. >=20 > 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=E4rber > * 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 >=20 > 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(); > +}