Received: from eggs.gnu.org ([2001:4830:134:3::10]:52887) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vu0kk-00084R-8y for qemu-devel@nongnu.org; Fri, 20 Dec 2013 09:08:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vu0kf-0002xa-5q for qemu-devel@nongnu.org; Fri, 20 Dec 2013 09:08:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:10252) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vu0ke-0002wr-Ty for qemu-devel@nongnu.org; Fri, 20 Dec 2013 09:08:29 -0500 Date: Fri, 20 Dec 2013 15:08:22 +0100 From: Igor Mammedov Message-ID: <20131220150822.60ec3212@nial.usersys.redhat.com> In-Reply-To: <52B44CEF.6010800@suse.de> References: <1387545971-22218-1-git-send-email-imammedo@redhat.com> <52B44CEF.6010800@suse.de> 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: Andreas =?ISO-8859-1?B?RuRyYmVy?= Cc: Peter Maydell , Peter Crosthwaite , qemu-devel@nongnu.org, armbru@redhat.com, anthony@codemonkey.ws, pbonzini@redhat.com On Fri, 20 Dec 2013 14:58:07 +0100 Andreas F=E4rber wrote: > Am 20.12.2013 14:26, schrieb Igor Mammedov: > > 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) >=20 > Surely needs to be +=3D. fixed. >=20 > > +gcov-files-check-qdict-y =3D object/object.c >=20 > Copy&paste? ("qdict") > Also "qom/object.c". fixed >=20 > > =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/t= est-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 lib= qemuutil.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 libqemus= tub.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) l= ibqemuutil.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) lib= qemuutil.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, >=20 > TestIf is not assigned here - no bug but let's set a consistent example. What do you mean? >=20 > > + .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" >=20 > I'd insert a white line here and above. sure >=20 > > +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); >=20 > What's the o in ico for BTW? InterfaceClassObject ... >=20 > > + > > + 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", >=20 > Would it make sense to call it /qom/interface/... or /qom-interface/...? sure, I'll amend it. > Doesn't really matter though as long as it's unique, I guess. >=20 > > + interface_intermediate_test); > > + > > + return g_test_run(); > > +} >=20 > Regards, > Andreas >=20