From patchwork Tue Dec 6 20:15:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 703330 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 3tYCZZ1SRmz9snm for ; Wed, 7 Dec 2016 07:16:38 +1100 (AEDT) Received: from localhost ([::1]:34591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEMAG-0006Ro-6I for incoming@patchwork.ozlabs.org; Tue, 06 Dec 2016 15:16:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51203) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEM91-0005ZZ-7R for qemu-devel@nongnu.org; Tue, 06 Dec 2016 15:15:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cEM8x-00010j-Ud for qemu-devel@nongnu.org; Tue, 06 Dec 2016 15:15:19 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:42405) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cEM8x-0000zx-Hw for qemu-devel@nongnu.org; Tue, 06 Dec 2016 15:15:15 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uB6KEkg0144112 for ; Tue, 6 Dec 2016 15:15:14 -0500 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 2762h4ee6w-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 06 Dec 2016 15:15:14 -0500 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 6 Dec 2016 13:15:13 -0700 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 6 Dec 2016 13:15:10 -0700 Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 382EF19D801C; Tue, 6 Dec 2016 13:14:30 -0700 (MST) Received: from b01ledav03.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uB6KF9sk40173606; Tue, 6 Dec 2016 20:15:09 GMT Received: from b01ledav03.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 90C97B2050; Tue, 6 Dec 2016 15:15:09 -0500 (EST) Received: from localhost (unknown [9.41.92.221]) by b01ledav03.gho.pok.ibm.com (Postfix) with ESMTP id 74B7CB2054; Tue, 6 Dec 2016 15:15:09 -0500 (EST) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 6 Dec 2016 14:15:00 -0600 X-Mailer: git-send-email 1.9.1 In-Reply-To: <1481055300-14239-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1481055300-14239-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16120620-0012-0000-0000-000011529D7D X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006205; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000194; SDB=6.00790193; UDB=6.00382645; IPR=6.00567932; BA=6.00004946; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013560; XFM=3.00000011; UTC=2016-12-06 20:15:13 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16120620-0013-0000-0000-000047C980E8 Message-Id: <1481055300-14239-3-git-send-email-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-12-06_11:, , 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-1609300000 definitions=main-1612060303 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH for-2.8 2/2] 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: armbru@redhat.com, dgilbert@redhat.com, bharata.rao@gmail.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 in 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 add specific checks for this scenario in addition to the normal sanity checks. Suggested-by: Daniel Berrange Cc: "Dr. David Alan Gilbert" Cc: Markus Armbruster Cc: Eric Blake Cc: Daniel Berrange Signed-off-by: Michael Roth Reviewed-by: Daniel P. Berrange --- tests/check-qom-proplist.c | 54 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c index a16cefc..087ce21 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" #define TYPE_DUMMY "qemu-dummy" @@ -162,6 +165,10 @@ static const TypeInfo dummy_info = { .instance_finalize = dummy_finalize, .class_size = sizeof(DummyObjectClass), .class_init = dummy_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + } }; @@ -291,7 +298,6 @@ static void dummy_backend_init(Object *obj) { } - static const TypeInfo dummy_dev_info = { .name = TYPE_DUMMY_DEV, .parent = TYPE_OBJECT, @@ -320,6 +326,14 @@ static const TypeInfo dummy_backend_info = { .class_size = sizeof(DummyBackendClass), }; +static QemuOptsList qemu_object_opts = { + .name = "object", + .implied_opt_name = "qom-type", + .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head), + .desc = { + { } + }, +}; static void test_dummy_createv(void) @@ -388,6 +402,43 @@ static void test_dummy_createlist(void) object_unparent(OBJECT(dobj)); } +static void test_dummy_createcmdl(void) +{ + QemuOpts *opts; + DummyObject *dobj; + Error *err = NULL; + const char *params = TYPE_DUMMY \ + ",id=dev0," \ + "bv=yes,sv=Hiss hiss hiss,av=platypus"; + + qemu_add_opts(&qemu_object_opts); + opts = qemu_opts_parse(&qemu_object_opts, params, true, &err); + g_assert(err == NULL); + g_assert(opts); + + dobj = DUMMY_OBJECT(user_creatable_add_opts(opts, &err)); + g_assert(err == NULL); + g_assert(dobj); + g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss"); + g_assert(dobj->bv == true); + g_assert(dobj->av == DUMMY_PLATYPUS); + + user_creatable_del("dev0", &err); + g_assert(err == 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 check + * for this in user_creatable_del() and remove the QemuOpts if it + * is present. The below check ensures this works as expected. + */ + g_assert(qemu_opts_find(&qemu_object_opts, "dev0") == NULL); +} + static void test_dummy_badenum(void) { Error *err = NULL; @@ -525,6 +576,7 @@ int main(int argc, char **argv) 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);