From nobody Tue Nov 4 15:46:43 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15039674331095.091938575084669; Mon, 28 Aug 2017 17:43:53 -0700 (PDT) Received: from localhost ([::1]:42034 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dmUdC-0000rJ-Jm for importer@patchew.org; Mon, 28 Aug 2017 20:43:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dmUCe-0001Tk-0P for qemu-devel@nongnu.org; Mon, 28 Aug 2017 20:16:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dmUCb-0005kE-8C for qemu-devel@nongnu.org; Mon, 28 Aug 2017 20:16:23 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:53635 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dmUCa-0005jW-Va for qemu-devel@nongnu.org; Mon, 28 Aug 2017 20:16:21 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7T0E9w6081539 for ; Mon, 28 Aug 2017 20:16:20 -0400 Received: from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cmurncru1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 28 Aug 2017 20:16:20 -0400 Received: from localhost by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 28 Aug 2017 18:16:19 -0600 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 28 Aug 2017 18:16:14 -0600 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7T0GEWb62718104; Mon, 28 Aug 2017 17:16:14 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 092F2BE038; Mon, 28 Aug 2017 18:16:14 -0600 (MDT) Received: from localhost (unknown [9.80.85.217]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id C9923BE039; Mon, 28 Aug 2017 18:16:13 -0600 (MDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 28 Aug 2017 19:14:24 -0500 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503965694-10794-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1503965694-10794-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17082900-0024-0000-0000-0000171CE4CB X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007630; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000226; SDB=6.00909028; UDB=6.00455849; IPR=6.00689279; BA=6.00005557; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016909; XFM=3.00000015; UTC=2017-08-29 00:16:17 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082900-0025-0000-0000-00004C7F054C Message-Id: <1503965694-10794-50-git-send-email-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-08-28_13:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1708290001 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 49/79] tests: check-qom-proplist: add checks for cmdline-created objects 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: Markus Armbruster , qemu-stable@nongnu.org, "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" check-qom-proplist originally added tests for verifying that object-creation helpers object_new_with_{props,propv} behaved in similar fashion to the "traditional" method involving setting each individual property separately after object creation rather than via a single call. Another similar "helper" for creating Objects exists in the form of objects specified via -object command-line parameters. By that rationale, we extend check-qom-proplist to include similar checks for command-line-created objects by employing the same qemu_opts_parse()-based parsing the vl.c employs. This parser has a side-effect of parsing the object's options into a QemuOpt structure and registering this in the global QemuOptsList using the Object's ID. This can conflict with future Object instances that attempt to use the same ID if we don't ensure this is cleaned up as part of Object finalization, so we include a FIXME stub to test for this case, which will then be resolved in a subsequent patch. Suggested-by: Daniel Berrange Cc: "Dr. David Alan Gilbert" Cc: Markus Armbruster Cc: Eric Blake Cc: Daniel Berrange Cc: qemu-stable@nongnu.org Signed-off-by: Michael Roth Reviewed-by: Markus Armbruster Message-Id: <1496531612-22166-2-git-send-email-mdroth@linux.vnet.ibm.com> [Comment formatting tidied up] Signed-off-by: Markus Armbruster (cherry picked from commit a1af255f065ccf3f47a7bfe88f1dbc9eeca36935) Signed-off-by: Michael Roth --- tests/check-qom-proplist.c | 56 ++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 56 insertions(+) diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c index a16cefc..e3b3ae4 100644 --- a/tests/check-qom-proplist.c +++ b/tests/check-qom-proplist.c @@ -23,6 +23,9 @@ #include "qapi/error.h" #include "qom/object.h" #include "qemu/module.h" +#include "qemu/option.h" +#include "qemu/config-file.h" +#include "qom/object_interfaces.h" =20 =20 #define TYPE_DUMMY "qemu-dummy" @@ -162,6 +165,10 @@ static const TypeInfo dummy_info =3D { .instance_finalize =3D dummy_finalize, .class_size =3D sizeof(DummyObjectClass), .class_init =3D dummy_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + } }; =20 =20 @@ -320,6 +327,14 @@ static const TypeInfo dummy_backend_info =3D { .class_size =3D sizeof(DummyBackendClass), }; =20 +static QemuOptsList qemu_object_opts =3D { + .name =3D "object", + .implied_opt_name =3D "qom-type", + .head =3D QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head), + .desc =3D { + { } + }, +}; =20 =20 static void test_dummy_createv(void) @@ -388,6 +403,46 @@ static void test_dummy_createlist(void) object_unparent(OBJECT(dobj)); } =20 +static void test_dummy_createcmdl(void) +{ + QemuOpts *opts; + DummyObject *dobj; + Error *err =3D NULL; + const char *params =3D TYPE_DUMMY \ + ",id=3Ddev0," \ + "bv=3Dyes,sv=3DHiss hiss hiss,av=3Dplatypus"; + + qemu_add_opts(&qemu_object_opts); + opts =3D qemu_opts_parse(&qemu_object_opts, params, true, &err); + g_assert(err =3D=3D NULL); + g_assert(opts); + + dobj =3D DUMMY_OBJECT(user_creatable_add_opts(opts, &err)); + g_assert(err =3D=3D NULL); + g_assert(dobj); + g_assert_cmpstr(dobj->sv, =3D=3D, "Hiss hiss hiss"); + g_assert(dobj->bv =3D=3D true); + g_assert(dobj->av =3D=3D DUMMY_PLATYPUS); + + user_creatable_del("dev0", &err); + g_assert(err =3D=3D NULL); + error_free(err); + + /* + * cmdline-parsing via qemu_opts_parse() results in a QemuOpts entry + * corresponding to the Object's ID to be added to the QemuOptsList + * for objects. To avoid having this entry conflict with future + * Objects using the same ID (which can happen in cases where + * qemu_opts_parse() is used to parse the object params, such as + * with hmp_object_add() at the time of this comment), we need to + * check for this in user_creatable_del() and remove the QemuOpts if + * it is present. + * + * FIXME: add an assert to verify that the QemuOpts is cleaned up + * once the corresponding cleanup code is added. + */ +} + static void test_dummy_badenum(void) { Error *err =3D NULL; @@ -525,6 +580,7 @@ int main(int argc, char **argv) =20 g_test_add_func("/qom/proplist/createlist", test_dummy_createlist); g_test_add_func("/qom/proplist/createv", test_dummy_createv); + g_test_add_func("/qom/proplist/createcmdline", test_dummy_createcmdl); g_test_add_func("/qom/proplist/badenum", test_dummy_badenum); g_test_add_func("/qom/proplist/getenum", test_dummy_getenum); g_test_add_func("/qom/proplist/iterator", test_dummy_iterator); --=20 2.7.4