[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-stable] [PATCH 49/79] tests: check-qom-proplist: add checks for cm
From: |
Michael Roth |
Subject: |
[Qemu-stable] [PATCH 49/79] tests: check-qom-proplist: add checks for cmdline-created objects |
Date: |
Mon, 28 Aug 2017 19:14:24 -0500 |
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 <address@hidden>
Cc: "Dr. David Alan Gilbert" <address@hidden>
Cc: Markus Armbruster <address@hidden>
Cc: Eric Blake <address@hidden>
Cc: Daniel Berrange <address@hidden>
Cc: address@hidden
Signed-off-by: Michael Roth <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
Message-Id: <address@hidden>
[Comment formatting tidied up]
Signed-off-by: Markus Armbruster <address@hidden>
(cherry picked from commit a1af255f065ccf3f47a7bfe88f1dbc9eeca36935)
Signed-off-by: Michael Roth <address@hidden>
---
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"
#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 },
+ { }
+ }
};
@@ -320,6 +327,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 +403,46 @@ 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 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 = NULL;
@@ -525,6 +580,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);
--
2.7.4
- [Qemu-stable] [PATCH 40/79] blkdebug: Add pass-through write_zero and discard support, (continued)
- [Qemu-stable] [PATCH 40/79] blkdebug: Add pass-through write_zero and discard support, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 31/79] stream: fix crash in stream_start() when block_job_create() fails, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 34/79] virtio-scsi: Unset hotplug handler when unrealize, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 46/79] mirror: Drop permissions on s->target on completion, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 37/79] virtio-net: fix wild pointer when remove virtio-net queues, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 44/79] block: Simplify BDRV_BLOCK_RAW recursion, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 50/79] monitor: fix object_del for command-line-created objects, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 38/79] blkdebug: Sanity check block layer guarantees, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 53/79] target/ppc: fix memory leak in kvmppc_is_mem_backend_page_size_ok(), Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 54/79] spapr: add pre_plug function for memory, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 49/79] tests: check-qom-proplist: add checks for cmdline-created objects,
Michael Roth <=
- [Qemu-stable] [PATCH 55/79] spapr: fix memory leak in spapr_memory_pre_plug(), Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 60/79] commit: Fix completion with extra reference, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 58/79] nbd: Fully initialize client in case of failed negotiation, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 62/79] blkverify: Catch bs->exact_filename overflow, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 41/79] blkdebug: Simplify override logic, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 42/79] blkdebug: Add ability to override unmap geometries, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 45/79] block: Guarantee that *file is set on bdrv_get_block_status(), Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 48/79] linuxboot_dma: compile for i486, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 47/79] virtio-serial-bus: Unset hotplug handler when unrealize, Michael Roth, 2017/08/28
- [Qemu-stable] [PATCH 04/79] qemu-img/convert: Use @opts for one thing only, Michael Roth, 2017/08/28