From patchwork Wed Sep 12 12:55:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 10597517 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B37414BD for ; Wed, 12 Sep 2018 13:05:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58E3229A99 for ; Wed, 12 Sep 2018 13:05:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D09C29F76; Wed, 12 Sep 2018 13:05:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A185229A99 for ; Wed, 12 Sep 2018 13:05:19 +0000 (UTC) Received: from localhost ([::1]:36195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g04pb-0005R6-1q for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Sep 2018 09:05:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33203) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g04h9-0007pd-LM for qemu-devel@nongnu.org; Wed, 12 Sep 2018 08:56:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g04h6-00004r-ER for qemu-devel@nongnu.org; Wed, 12 Sep 2018 08:56:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54516 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g04h5-0008W2-Vl for qemu-devel@nongnu.org; Wed, 12 Sep 2018 08:56:32 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3B7C640241C0; Wed, 12 Sep 2018 12:56:31 +0000 (UTC) Received: from localhost (ovpn-112-57.ams2.redhat.com [10.36.112.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 643E2101042B; Wed, 12 Sep 2018 12:56:25 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Wed, 12 Sep 2018 16:55:29 +0400 Message-Id: <20180912125531.32131-8-marcandre.lureau@redhat.com> In-Reply-To: <20180912125531.32131-1-marcandre.lureau@redhat.com> References: <20180912125531.32131-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 12 Sep 2018 12:56:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 12 Sep 2018 12:56:31 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 7/9] tests: add user-creatable test to test-qdev-global-props X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S. Tsirkin" , Mark Cave-Ayland , dgilbert@redhat.com, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Igor Mammedov , Paolo Bonzini , =?utf-8?q?Andreas_F=C3=A4rber?= , Artyom Tarasenko , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add a TYPE_USER_CREATABLE object global property check. Rename the test, since it is no longer QDev-specific. Signed-off-by: Marc-André Lureau --- ...dev-global-props.c => test-global-props.c} | 128 ++++++++++++++++-- tests/Makefile.include | 4 +- 2 files changed, 117 insertions(+), 15 deletions(-) rename tests/{test-qdev-global-props.c => test-global-props.c} (74%) diff --git a/tests/test-qdev-global-props.c b/tests/test-global-props.c similarity index 74% rename from tests/test-qdev-global-props.c rename to tests/test-global-props.c index 9dffdf336d..1c725245bc 100644 --- a/tests/test-qdev-global-props.c +++ b/tests/test-global-props.c @@ -27,7 +27,100 @@ #include "hw/qdev.h" #include "qom/object.h" #include "qapi/visitor.h" +#include "qom/object_interfaces.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; + + char *sv; +}; + +struct DummyObjectClass { + ObjectClass parent_class; +}; + +static void dummy_set_sv(Object *obj, + const char *value, + Error **errp) +{ + DummyObject *dobj = DUMMY_OBJECT(obj); + + g_free(dobj->sv); + dobj->sv = g_strdup(value); +} + +static char *dummy_get_sv(Object *obj, + Error **errp) +{ + DummyObject *dobj = DUMMY_OBJECT(obj); + + return g_strdup(dobj->sv); +} + + + +static void dummy_class_init(ObjectClass *cls, void *data) +{ + object_class_property_add_str(cls, "sv", + dummy_get_sv, + dummy_set_sv, + NULL); +} + + +static void dummy_finalize(Object *obj) +{ + DummyObject *dobj = DUMMY_OBJECT(obj); + + g_free(dobj->sv); +} + + +static const TypeInfo dummy_info = { + .name = TYPE_DUMMY, + .parent = TYPE_OBJECT, + .instance_size = sizeof(DummyObject), + .instance_finalize = dummy_finalize, + .class_size = sizeof(DummyObjectClass), + .class_init = dummy_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + } +}; + +static void test_global_props_uc_subprocess(void) +{ + DummyObject *d; + static GlobalProperty gp = { + TYPE_DUMMY, "sv", "foobar", + }; + + d = DUMMY_OBJECT(object_new(TYPE_DUMMY)); + g_assert_null(d->sv); + object_unref(OBJECT(d)); + + object_property_register_global(&gp); + d = DUMMY_OBJECT(object_new(TYPE_DUMMY)); + g_assert_cmpstr(d->sv, ==, "foobar"); + object_unref(OBJECT(d)); +} + +static void test_global_props_uc(void) +{ + g_test_trap_subprocess("/global-props/usercreatable/subprocess", 0, 0); + g_test_trap_assert_passed(); + g_test_trap_assert_stderr(""); + g_test_trap_assert_stdout(""); +} #define TYPE_STATIC_PROPS "static_prop_type" #define STATIC_TYPE(obj) \ @@ -83,7 +176,8 @@ static void test_static_prop_subprocess(void) static void test_static_prop(void) { - g_test_trap_subprocess("/qdev/properties/static/default/subprocess", 0, 0); + g_test_trap_subprocess("/global-props/qdev/static/default/subprocess", + 0, 0); g_test_trap_assert_passed(); g_test_trap_assert_stderr(""); g_test_trap_assert_stdout(""); @@ -119,7 +213,7 @@ static void test_static_globalprop_subprocess(void) static void test_static_globalprop(void) { - g_test_trap_subprocess("/qdev/properties/static/global/subprocess", 0, 0); + g_test_trap_subprocess("/global-props/qdev/static/global/subprocess", 0, 0); g_test_trap_assert_passed(); g_test_trap_assert_stderr(""); g_test_trap_assert_stdout(""); @@ -245,7 +339,8 @@ static void test_dynamic_globalprop_subprocess(void) static void test_dynamic_globalprop(void) { - g_test_trap_subprocess("/qdev/properties/dynamic/global/subprocess", 0, 0); + g_test_trap_subprocess("/global-props/qdev/dynamic/global/subprocess", + 0, 0); g_test_trap_assert_passed(); g_test_trap_assert_stderr_unmatched("*prop1*"); g_test_trap_assert_stderr_unmatched("*prop2*"); @@ -290,7 +385,8 @@ static void test_dynamic_globalprop_nouser_subprocess(void) static void test_dynamic_globalprop_nouser(void) { - g_test_trap_subprocess("/qdev/properties/dynamic/global/nouser/subprocess", 0, 0); + g_test_trap_subprocess("/global-props/qdev" + "/dynamic/global/nouser/subprocess", 0, 0); g_test_trap_assert_passed(); g_test_trap_assert_stderr(""); g_test_trap_assert_stdout(""); @@ -323,6 +419,7 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); module_call_init(MODULE_INIT_QOM); + type_register_static(&dummy_info); type_register_static(&static_prop_type); type_register_static(&subclass_type); type_register_static(&dynamic_prop_type); @@ -330,27 +427,32 @@ int main(int argc, char **argv) type_register_static(&nohotplug_type); type_register_static(&nondevice_type); - g_test_add_func("/qdev/properties/static/default/subprocess", + g_test_add_func("/global-props/usercreatable/subprocess", + test_global_props_uc_subprocess); + g_test_add_func("/global-props/usercreatable", + test_global_props_uc); + + g_test_add_func("/global-props/qdev/static/default/subprocess", test_static_prop_subprocess); - g_test_add_func("/qdev/properties/static/default", + g_test_add_func("/global-props/qdev/static/default", test_static_prop); - g_test_add_func("/qdev/properties/static/global/subprocess", + g_test_add_func("/global-props/qdev/static/global/subprocess", test_static_globalprop_subprocess); - g_test_add_func("/qdev/properties/static/global", + g_test_add_func("/global-props/qdev/static/global", test_static_globalprop); - g_test_add_func("/qdev/properties/dynamic/global/subprocess", + g_test_add_func("/global-props/qdev/dynamic/global/subprocess", test_dynamic_globalprop_subprocess); - g_test_add_func("/qdev/properties/dynamic/global", + g_test_add_func("/global-props/qdev/dynamic/global", test_dynamic_globalprop); - g_test_add_func("/qdev/properties/dynamic/global/nouser/subprocess", + g_test_add_func("/global-props/qdev/dynamic/global/nouser/subprocess", test_dynamic_globalprop_nouser_subprocess); - g_test_add_func("/qdev/properties/dynamic/global/nouser", + g_test_add_func("/global-props/qdev/dynamic/global/nouser", test_dynamic_globalprop_nouser); - g_test_add_func("/qdev/properties/global/subclass", + g_test_add_func("/global-props/qdev/global/subclass", test_subclass_global_props); g_test_run(); diff --git a/tests/Makefile.include b/tests/Makefile.include index 87c81d1dcc..080b218fd3 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -128,7 +128,7 @@ check-unit-y += tests/test-qht-par$(EXESUF) gcov-files-test-qht-par-y = util/qht.c check-unit-y += tests/test-bitops$(EXESUF) check-unit-y += tests/test-bitcnt$(EXESUF) -check-unit-y += tests/test-qdev-global-props$(EXESUF) +check-unit-y += tests/test-global-props$(EXESUF) check-unit-y += tests/check-qom-interface$(EXESUF) gcov-files-check-qom-interface-y = qom/object.c check-unit-y += tests/check-qom-proplist$(EXESUF) @@ -657,7 +657,7 @@ tests/qht-bench$(EXESUF): tests/qht-bench.o $(test-util-obj-y) tests/test-bufferiszero$(EXESUF): tests/test-bufferiszero.o $(test-util-obj-y) tests/atomic_add-bench$(EXESUF): tests/atomic_add-bench.o $(test-util-obj-y) -tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ +tests/test-global-props$(EXESUF): tests/test-global-props.o \ hw/core/qdev.o hw/core/qdev-properties.o hw/core/hotplug.o\ hw/core/bus.o \ hw/core/irq.o \