Received: from eggs.gnu.org ([2001:4830:134:3::10]:44394) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfSI5-0001LY-Ry for qemu-devel@nongnu.org; Fri, 25 Sep 2015 08:39:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZfSI2-000303-NO for qemu-devel@nongnu.org; Fri, 25 Sep 2015 08:39:53 -0400 Received: from mx2.suse.de ([195.135.220.15]:39870) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfSI2-0002zJ-Eq for qemu-devel@nongnu.org; Fri, 25 Sep 2015 08:39:50 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Fri, 25 Sep 2015 14:39:45 +0200 Message-Id: <1443184788-18859-5-git-send-email-afaerber@suse.de> In-Reply-To: <1443184788-18859-1-git-send-email-afaerber@suse.de> References: <1443184788-18859-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 4/7] tests: Add QOM property unit tests List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , Bruce Rogers , Lin Ma , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Add a test for parsing and setting a uint64 property. Signed-off-by: Andreas F=C3=A4rber --- MAINTAINERS | 1 + tests/Makefile | 3 ++ tests/check-qom-props.c | 120 ++++++++++++++++++++++++++++++++++++++++++= ++++++ 3 files changed, 124 insertions(+) create mode 100644 tests/check-qom-props.c diff --git a/MAINTAINERS b/MAINTAINERS index 71c652b..a941cfd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1032,6 +1032,7 @@ F: include/qom/ X: include/qom/cpu.h F: qom/ X: qom/cpu.c +F: tests/check-qom-props.c F: tests/qom-test.c =20 QMP diff --git a/tests/Makefile b/tests/Makefile index 4063639..93116a2 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -72,6 +72,8 @@ check-unit-y +=3D tests/check-qom-interface$(EXESUF) gcov-files-check-qom-interface-y =3D qom/object.c check-unit-y +=3D tests/check-qom-proplist$(EXESUF) gcov-files-check-qom-proplist-y =3D qom/object.c +check-unit-y +=3D tests/check-qom-props$(EXESUF) +gcov-files-check-qom-props-y =3D qom/object.c check-unit-y +=3D tests/test-qemu-opts$(EXESUF) gcov-files-test-qemu-opts-y =3D qom/test-qemu-opts.c check-unit-y +=3D tests/test-write-threshold$(EXESUF) @@ -303,6 +305,7 @@ tests/check-qfloat$(EXESUF): tests/check-qfloat.o $(t= est-util-obj-y) tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y) tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-q= om-obj-y) tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom= -obj-y) +tests/check-qom-props$(EXESUF): tests/check-qom-props.o $(test-qom-obj-y= ) tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(test-block-obj-y= ) tests/test-aio$(EXESUF): tests/test-aio.o $(test-block-obj-y) tests/test-rfifolock$(EXESUF): tests/test-rfifolock.o $(test-util-obj-y) diff --git a/tests/check-qom-props.c b/tests/check-qom-props.c new file mode 100644 index 0000000..53e5cc0 --- /dev/null +++ b/tests/check-qom-props.c @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * Copyright (c) 2015 SUSE Linux GmbH + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + * Author: Daniel P. Berrange + * Andreas F=C3=A4rber + */ + +#include + +#include "qapi/visitor.h" +#include "qom/object.h" +#include "qemu/module.h" + + +#define TYPE_DUMMY "qemu-dummy" + +typedef struct DummyObject DummyObject; +typedef struct DummyObjectClass DummyObjectClass; + +#define DUMMY_OBJECT(obj) \ + OBJECT_CHECK(DummyObject, (obj), TYPE_DUMMY) + +struct DummyObject { + Object parent_obj; + + uint64_t u64val; +}; + +struct DummyObjectClass { + ObjectClass parent_class; +}; + +static void dummy_set_uint64(Object *obj, Visitor *v, + void *opaque, const char *name, + Error **errp) +{ + uint64_t *ptr =3D (uint64_t *)opaque; + + visit_type_uint64(v, ptr, name, errp); +} + +static void dummy_get_uint64(Object *obj, Visitor *v, + void *opaque, const char *name, + Error **errp) +{ + uint64_t value =3D *(uint64_t *)opaque; + + visit_type_uint64(v, &value, name, errp); +} + +static void dummy_init(Object *obj) +{ + DummyObject *dobj =3D DUMMY_OBJECT(obj); + + object_property_add(obj, "u64val", "uint64", + dummy_get_uint64, + dummy_set_uint64, + NULL, &dobj->u64val, NULL); +} + + +static const TypeInfo dummy_info =3D { + .name =3D TYPE_DUMMY, + .parent =3D TYPE_OBJECT, + .instance_size =3D sizeof(DummyObject), + .instance_init =3D dummy_init, + .class_size =3D sizeof(DummyObjectClass), +}; + +static void test_dummy_uint64(void) +{ + Error *err =3D NULL; + char *str; + DummyObject *dobj =3D DUMMY_OBJECT(object_new(TYPE_DUMMY)); + + g_assert(dobj->u64val =3D=3D 0); + + str =3D g_strdup_printf("%" PRIu64, UINT64_MAX); + object_property_parse(OBJECT(dobj), str, "u64val", &err); + g_free(str); + g_assert(!err); + g_assert_cmpint(dobj->u64val, =3D=3D, UINT64_MAX); + + dobj->u64val =3D 0; + str =3D g_strdup_printf("0x%" PRIx64, UINT64_MAX); + object_property_parse(OBJECT(dobj), str, "u64val", &err); + g_free(str); + g_assert(!err); + g_assert_cmpint(dobj->u64val, =3D=3D, UINT64_MAX); + + object_unref(OBJECT(dobj)); +} + + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + module_call_init(MODULE_INIT_QOM); + type_register_static(&dummy_info); + + g_test_add_func("/qom/props/uint64", test_dummy_uint64); + + return g_test_run(); +} --=20 2.1.4